; display system time. press f1 to change the color displayed, press esc to exit program.
assume cs:codesg
stacksg segment
dw 128 dup(0)
stacksg ends
; 秒: 0 分:2 时: 4 日 : 7 月:8 年:9
codesg segment
str1 db '20yy/mm/dd hh:mm:ss',0
row db 9,8,7,4,2,0
line db 1
csip dw 0,0
exitflag db 0
color db 2
start:
mov ax, stacksg
mov ss, ax
mov sp, 128
mov ax, cs
mov ds, ax
mov ax, 0
mov es, ax
push es:[9*4]
pop csip[0]
push es:[9*4 + 2]
pop csip[2]
cli
mov word ptr es:[9*4], offset int9
mov es:[9*4 + 2], cs
sti
s_second:
mov al, exitflag
cmp al, 1
je exit
mov di, 2
mov si, 0
mov cx, 6
s: mov al, row[si]
out 70h, al
in al, 71h
call do_addstr
add di, 3
inc si
loop s
; 调用函数
mov ax, 0b800h
mov es, ax
mov si, 0
mov di, 0
mov bh, 160
mov al, line[0]
mul bh
add di, ax
add di, 2*8
s_print:
mov bl, ds:[si]
cmp bl,0
je s_print_out
mov bh, color
; 无论哪行,从第8列开始显示
mov es:[di], bx
inc si
add di, 2
jmp s_print
s_print_out:
call delay
jmp s_second
exit:
; 恢复向量表
mov ax, 0
mov es, ax
push csip[0]
pop es:[9*4]
push csip[2]
pop es:[9*4 + 2]
mov ax, 4c00h
int 21h
delay:
push ax
push dx
mov dx, 0BFFh
mov ax, 0
s_delay:
sub ax, 1
sbb dx, 0
cmp ax, 0
jne s_delay
cmp dx, 0
jne s_delay
pop dx
pop ax
ret
; 参数al, 将al中bcd放到ds:di指定处
do_addstr:
push di
push ax
push cx
mov ah, al
mov cl, 4
shr ah, cl
add ah, 30h
and al, 00001111b
add al, 30h
mov [di], ah
mov [di + 1], al
pop cx
pop ax
pop di
ret
int9:
push ax
push bx
in al, 60h
pushf
call dword ptr csip
; check if equal esc:01, f1:3b, f1 change color. esc exit function
cmp al, 01h ;esc
je sesc
cmp al, 3bh
je f1
jmp int9ret
f1: inc color
jmp int9ret
sesc:
mov exitflag, 1
int9ret:
pop bx
pop ax
iret
codesg ends
end start
转载于:https://www.cnblogs.com/boota/p/3734659.html