Click to See Complete Forum and Search --> : [RESOLVED] Date and Time functions print wrong results?


David2010
October 1st, 2010, 05:09 PM
This is a strange one.

The functions print "something" without error however the results are wrong. Generally speaking, with me the whole function don't work. xD

These two functions get the time and date from the BIOS and print it to the screen.

Date:



date:

%define RTCaddress 0x70
%define RTCdata 0x71

loop3: mov al,10 ;Get RTC register A
out RTCaddress,al
in al,RTCdata
test al,0x80 ;Is update in progress?
jne loop3 ; yes, wait

mov al,0x07 ;Get day
out RTCaddress,al
in al,RTCdata
mov [RTCtimeDay],al

mov al,0x08 ;Get month
out RTCaddress,al
in al,RTCdata
mov [RTCtimeMonth],al

mov al,0x09 ;Get year
out RTCaddress,al
in al,RTCdata
mov [RTCtimeYear],al

mov si, msg3
call print

mov si, [RTCtimeMonth]
call printints

mov si, msg1
call print

mov si, [RTCtimeDay]
call printints

mov si, msg1
call print

mov si, [RTCtimeYear]
call printints

mov si, msg2
call print

ret

msg1 db ' ', 0
msg2 db ' ', 0x0D, 0x0A, 0
msg3 db 'Month Day Year', 0x0D, 0x0A, 0
RTCtimeDay db 0, 0
RTCtimeMonth db 0, 0
RTCtimeYear db 0, 0



Time:



time:

%define RTCaddress 0x70
%define RTCdata 0x71

loop1: mov al,10 ;Get RTC register A
out RTCaddress,al
in al,RTCdata
test al,0x80 ;Is update in progress?
jne loop1 ; yes, wait

mov al,0x04 ;Get hours
out RTCaddress,al
in al,RTCdata
mov [RTCtimeHour],al

mov al,0x02 ;Get minutes
out RTCaddress,al
in al,RTCdata
mov [RTCtimeMinute],al

mov si, [RTCtimeHour]
call printints

mov si, msg_hours
call print

mov si, [RTCtimeMinute]
call printints

mov si, msg_minutes
call print

ret

msg_minutes db ' Minutes', 0x0D, 0x0A, 0
msg_hours db ' Hours ', 0
RTCtimeHour db 0, 0
RTCtimeMinute db 0, 0



The problem is, the data printed by these two functions are wrong.

I already checked the BIOS and made sure the date and time values were correct there.

--------------------------------------------

Register values after each function:

---------------------------------------------

Time function:



ax = 31704
cx = 64
dx = 1
bx = 40
si = 40
di = 0



Date function:



ax = 31704
cx = 64
dx = 1
bx = 44
si = 44
di = 0

Eri523
October 1st, 2010, 06:26 PM
These two functions get the time and date from the BIOS [...].

Well, they don't get the date/time from the BIOS, but rather directly from the RTC hardware. (However, there are BIOS functions to access the RTC: INT 0x1A, function 0x02 and up.)

Your problem most likely arises from the fact that the RTC usually is configured to deliver (and receive) the date/time values in BCD rather than binary (bit 2 of status register B is 0), but you interpret them as being binary (assuming that you use the integer output routine from our other thread).

BTW, the BIOS functions for accessing the RTC I mentioned above use the BCD format as well.

HTH

David2010
October 1st, 2010, 08:46 PM
Well, they don't get the date/time from the BIOS, but rather directly from the RTC hardware. (However, there are BIOS functions to access the RTC: INT 0x1A, function 0x02 and up.)

Your problem most likely arises from the fact that the RTC usually is configured to deliver (and receive) the date/time values in BCD rather than binary (bit 2 of status register B is 0), but you interpret them as being binary (assuming that you use the integer output routine from our other thread).

BTW, the BIOS functions for accessing the RTC I mentioned above use the BCD format as well.

HTH

This small function converts from BCD to binary.

Thank you again for your help!



bcd2int:
mov ah,al
shr ah,4
and al,0x0F
aad
or al,ah
ret