CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2009
    Posts
    100

    [RESOLVED] Date and Time functions print wrong results?

    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:

    Code:
    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:

    Code:
    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:

    Code:
    ax = 31704
    cx = 64
    dx = 1
    bx = 40
    si = 40
    di = 0
    Date function:

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

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Date and Time functions print wrong results?

    Quote Originally Posted by David2010 View Post
    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
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Jun 2009
    Posts
    100

    Re: Date and Time functions print wrong results?

    Quote Originally Posted by Eri523 View Post
    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!

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured