Page 1 of 1

Real-Time Clock

Posted: Thu Jan 30, 2003 2:00 am
by rtocpro
Hello All, I have been recently working with the real time clock in asm and I understand how it works to read in the hours, minutes and seconds, here is what i have so far:

Code: Select all

movb $0x02, %ah
int $0x1a

mov %ch, %al
okay now if i'm right, that should save the value of ch into al. Which is the hours? Now my question is, if i'm right, how would i output the value without converting from BCD? Or even to BCD.
And one more question is that, if i go to the minutes seconds, would it be like this:

mov %cl, %al
mov %dh, %al

if i do those, each after writing to the screen the value, would that work properly as a simple clock?

btw, i'm compiling with 'as' in linux.

Thanks so much for any help!

Re:Real-Time Clock

Posted: Thu Jan 30, 2003 5:57 am
by Pype.Clicker
a tip from codeslasher (in a former topic) : to display BCD correctly, just display it as %x and it will show nicely.

BCD is some old stuff from punched cards age, which consist in using a nybble (4bits) to represent each digit (0..9) of a number. So if you encode 4096 in BCD and look at the memory, it will look like 0x96 0x40 on an intel.

From this,

Code: Select all

#define bin2bcd(x) 16*(x/10)+(x%10)
#define bcd2bin(x) (x&0x0f)+10*(x>>4)

Re:Real-Time Clock

Posted: Thu Jan 30, 2003 11:22 pm
by gtsphere
how would that be done in asm?

Re:Real-Time Clock

Posted: Fri Jan 31, 2003 3:12 am
by Pype.Clicker
Maybe there are some specific opcodes for BCD conversion (i know there are some BCD-computation ones like AAD or something alike, but i cannot remember for conversion).
Otherwise, just try a play conversion (+ --> ADD, * -->MUL ...) ... or write it in C and ask the compiler to translate it for you :-)