Real-Time Clock

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
rtocpro

Real-Time Clock

Post 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!
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Real-Time Clock

Post 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)
gtsphere

Re:Real-Time Clock

Post by gtsphere »

how would that be done in asm?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Real-Time Clock

Post 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 :-)
Post Reply