gpt4 book ai didi

assembly - 如何使用NASM访问系统时间?

转载 作者:行者123 更新时间:2023-12-04 13:45:22 36 4
gpt4 key购买 nike

我正在尝试使用当前系统时间为我的随机数生成器播种。如何使用NASM访问系统时间? (我正在使用linux)

最佳答案

%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

它使用NASM,来自 here

关于assembly - 如何使用NASM访问系统时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1465927/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com