; 在屏幕的左上角动态显示时间,期间,按下Home键后,能显示“Home”,按下End键后,退出程序。
assume cs:code, ss:stack, ds:data
stack segment stack
db 128 dup (0)
stack ends
data segment
dw 0,0
home db 'Home',0dh,0ah,'$'
data ends
code segment
start:
mov ax,stack
mov ss,ax
mov sp,128
mov ax,data
mov ds,ax
; 改中断例程入口地址
mov ax,0
mov es,ax
push es:[9*4]
pop ds:[0]
push es:[9*4+2]
pop ds:[2]
mov word ptr es:[9*4],offset int9
mov es:[9*4+2],cs
; 显示时间
show: mov al,2 ;分
out 70h,al
in al,71h
mov ah,al
mov cl,4
shr ah,cl
and al,00001111b
add ah,30h
add al,30h
mov bx,0b800h
mov es,bx
mov byte ptr es:[0],ah
mov byte ptr es:[1],01001111b
mov byte ptr es:[2],al
mov byte ptr es:[3],01001111b
mov byte ptr es:[4],':'
mov byte ptr es:[5],01001111b
mov al,0 ;秒
out 70h,al
in al,71h
mov ah,al
mov cl,4
shr ah,cl
and al,00001111b
add ah,30h
add al,30h
mov bx,0b800h
mov es,bx
mov byte ptr es:[6],ah
mov byte ptr es:[7],01001111b
mov byte ptr es:[8],al
mov byte ptr es:[9],01001111b
jmp show
; 定义中断例程
int9: push ax
push bx
push dx
push es
in al,60h
pushf
pushf
pop bx
and bh,11111100b
push bx
popf
call dword ptr ds:[0]
mov bl, al ;保存al
cmp al,47h ; 47h是HOME键的扫描码
jne ifend
;处理HOME
lea dx, home
mov ah,9
int 21h
jmp int9ret
ifend:
cmp bl, 4Fh ;4Fh是end键的扫描码
jne int9ret
;处理END,使程序结束,注意在此要恢复中断向量
mov ax,0
mov es,ax
push ds:[0]
pop es:[9*4]
push ds:[2]
pop es:[9*4+2]
mov ax,4c00h
int 21h
int9ret:
pop es
pop dx
pop bx
pop ax
iret
code ends
end start