; 以年/月/日 时: 分: 秒的 形式显示当前的日期和时间
assume cs:code, ds:data, ss:stack
data segment
db 128 dup(0)
data ends
stack segment stack
db 128 dup(0)
stack ends
code segment
TIME_STYLE db 'YY/MM/DD HH:MM:SS', 0 ; y = year m = month d = day
; h = hour m = minute s = second
TIME_CMOS db 9, 8, 7, 4, 2, 0
start: mov ax, stack
mov ss, ax
mov sp, 128
call init_reg
call show_clock
mov ax, 4C00H
int 21H
;====================================================
show_clock: call show_time_style
showTime: mov si, OFFSET TIME_CMOS
mov di, 160 * 10 + 30 * 2
mov cx, 6
showDate: mov al, ds:[si]
out 70H, al
in al, 71H
mov ah, al ; 0011 0000
shr ah, 1
shr ah, 1
shr ah, 1
shr ah, 1
and al, 00001111B
add ah, 30H
add al, 30H
mov es:[di], ah
mov es:[di + 2], al
inc si
add di, 6
loop showDate
jmp showTime ; 键盘中断
ret
;=====================================================
init_reg: mov bx, 0B800H
mov es, bx
mov bx, cs
mov ds, bx
ret
;==========================================================
show_string: push dx
push ds
push es
push si
push di
showString: mov dl, ds:[si]
cmp dl, 0
je showStringRet
mov es:[di], dl
add di, 2
inc si
jmp showString
showStringRet: pop di
pop si
pop es
pop ds
pop dx
ret
;==========================================
show_time_style:
mov si, OFFSET TIME_STYLE
mov di, 160 * 10 + 30 * 2
call show_string
ret
code ends
end start