I am trying to seed my random number generator with current system time. How can I access the system time using NASM? (I am using linux)
+2
A:
%define RTCaddress 0x70
%define RTCdata 0x71
;Get time and date from RTC
.l1: mov al,10 ;Get RTC register A
out RTCaddress,al
in al,RTCdata
test al,0x80 ;Is update in progress?
jne .l1 ; yes, wait
mov al,0 ;Get seconds (00 to 59)
out RTCaddress,al
in al,RTCdata
mov [RTCtimeSecond],al
mov al,0x02 ;Get minutes (00 to 59)
out RTCaddress,al
in al,RTCdata
mov [RTCtimeMinute],al
mov al,0x04 ;Get hours (see notes)
out RTCaddress,al
in al,RTCdata
mov [RTCtimeHour],al
mov al,0x07 ;Get day of month (01 to 31)
out RTCaddress,al
in al,RTCdata
mov [RTCtimeDay],al
mov al,0x08 ;Get month (01 to 12)
out RTCaddress,al
in al,RTCdata
mov [RTCtimeMonth],al
mov al,0x09 ;Get year (00 to 99)
out RTCaddress,al
in al,RTCdata
mov [RTCtimeYear],al
ret
This uses NASM, and is from here.
Kyle Rozendo
2009-09-23 13:17:34
I'm a little confused. Is this working on the assumption that the poster is using windows?
BigBeagle
2009-09-23 13:23:56
Should work for any OS on x86 that maintains its system date/time.
Kyle Rozendo
2009-09-23 13:27:35
Just tried -- Unfortunately, "out RTCaddress,al" fails on Vista64 because of privilege level.
PhiS
2009-09-23 21:09:05
Ah, I don't really know then. As I said, I this should work on x86, not x64, let alone with Vista's glorious security, hehe.
Kyle Rozendo
2009-09-24 17:01:37
A:
You could make a call to interrupt 1Ah to get the clock ticks since midnight.
here are some people talking about formating the time from ticks
Sorskoot
2009-09-23 13:19:38
I only have experience with these interrupts on DOS on a x86. They're old, but I'm not sure if they'll work on other platforms. Have a look at this, maybe it helps: http://linux.ucla.edu/LDP/LDP/khg/HyperNews/get/khg/117/1/1/1.html
Sorskoot
2009-09-23 19:10:52
A:
I'd say, depending on what platform you're on, you'll have to use an OS function.
On windows, try GetSystemTime. On linux, try gettimeofday - see related question here.
PhiS
2009-09-23 21:18:14