第七篇 使用8253計數器

來源:互聯網
上載者:User

本篇博文主要介紹如何利用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

 

二、

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.