彙編語言----能動態顯示時間的程序(時:分:秒)

我從前最怕旁人火眼金睛,如今,倒是盼着有人能夠洞幽燭遠。如此,就能贈我一點歡喜。

在屏幕的左上角能動態顯示時間,程序如下:

assume cs:code
stack segment
     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

後運行附動態圖

時間顯示位置可以根據需要隨意挪動。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章