彙編語言 實驗14

;*********************************************************
;實驗14:訪問CMOS RAM
;以“年/月/日 時:分:秒”的格式,顯示當前時間和日期
;*********************************************************

assume cs:code

code segment
start:
mov ax, 0b800h
mov es, ax
mov di, 160*12+30*2 ;顯示在12行,30列
mov al, 0ah ;將al設爲10,因爲在CMOS RAM中,年月日時分秒的存放單元爲9,8,7,4,2,0
push di

rdata:
dec al
cmp al, 7
jb rtime ;當al小於7時,說明年月日讀取完畢,已經讀到時分秒
call show ;將日期顯示
add di, 6 ;XX/XX/XX X(2字節)X(2字節)/(2字節),一共要向後跳6字節
jmp short rdata ;回跳繼續顯示日期

rtime:
sub al, 2
cmp al, 0feh ;0000h - 2 = 0feh
je sign ;若al == 0feh 則跳到顯示”/”, “:”
call show
add di, 6 ;XX:XX:XX X(2字節)X(2字節):(2字節),一共要向後跳6字節
jmp short rtime

sign: ;XX/XX/XX XX:XX:XX
pop di
add di, 4 ;XX/ X(2字節)X(字節),一共要向後跳4個字節
mov byte ptr es:[di], ‘/’

add di, 6          
mov byte ptr es:[di], '/'

add di, 12
mov byte ptr es:[di], ':'

add di, 6
mov byte ptr es:[di], ':'

mov ax, 4c00h
int 21h

show:
push ax
push cx

out 70h, al                 ;70h 爲地址端口存放要訪問的 CMOS RAM 單元的地址
in al, 71h                                  ;71h  爲數據端口,存放從選定的 CMOS RAM 單元中讀取的數據,或要寫入到其中的數據

mov cx, 4
mov ah, al
shr ah, cl                  ;將ah置爲0000XXXXh
and al, 0fh                 ;將al置爲0000XXXXh

add ah, 30h                 ;轉爲對應的ascii碼
add al, 30h                                 ;轉爲對應的ascii碼

mov es:[di], ah             ;存入顯存
mov es:[di+2], al

pop cx
pop ax
ret

code ends
end start

發佈了23 篇原創文章 · 獲贊 22 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章