本篇博文主要介紹如何利用8253計數器計時。
8253計數器每秒大概計數18次。每計數一次就會向CPU發出插斷要求。也即每55ms就會
發一次插斷要求。CPU響應中斷,調用的是int 1ch。
以下代碼的作用時利用int 1ch中斷計時60秒,在螢幕上顯示00至59,然後程式自動結束。
一、代碼
initint equ 1chdata segmentaddr dw ?,?time dw ?count db ?divide db 10data endssseg segment stackdw 512 dup (?)sseg endscode segmentassume cs:code,ds:data,ss:ssegstart:mov ax,datamov ds,axmov ax,ssegmov ss,axmov ax,0mov es,ax;儲存1ch中斷的原始地址mov ax,es:[initint*4]mov addr,axmov ax,es:[initint*4+2]mov addr[2],ax;加入新中斷服務程式地址clilea ax,isrmov es:[initint*4],axmov ax,seg isrmov es:[initint*4+2],axstimov time,0mov count,0again:cmp time,60jae exitjmp again;恢複原中斷地址exit:climov ax,addrmov es:[initint*4],axmov ax,addr[2]mov es:[initint*4+2],axstimov ah,4chint 21hisr proc farpush axpush cxpush dx;告訴中斷服務子程式變數在哪mov ax,datamov ds,axstiinc countcmp count,18 ;近似把18次中斷記作一秒jae goback:pushfcall dword ptr addrclipop dxpop cxpop axiretgo:mov count,0;獲得秒的十位和個位mov ax,timediv dividemov cl,almov ch,ah;顯示十位mov ah,2add cl,30hmov dl,clint 21h;顯示個位add ch,30hmov dl,chmov ah,2int 21h;斷行符號mov dl,0dhmov ah,2int 21hinc timejmp backisr endpcode endsend start
二、