王爽《組合語言》第十四章讀取CMOS時鐘練習解答

2021-04-26 14:06:53 字數 1960 閱讀 7861

; 讀取cmos裡的年月日時分秒,以格式 年/月/日  時:分:秒 顯示在螢幕上,

; '/' 的ascii碼是 2f, ':' 的ascii碼是 3a

assume cs:code,

code segment

start:

; 讀取年,cmos4單元

mov al, 9

call  readconvert

mov bx, 0b800h

mov es, bx

mov byte ptr es:[160*12 + 40*12], al ; 個位數

mov byte ptr es:[160*12 + 40*12 + 2], ah; 十位數

mov byte ptr es:[160*12 + 40*12 + 4], 2fh ; '/'

; 讀取月,coms 8單元的資料

mov  al, 8

call readconvert

mov byte ptr es:[160*12 + 40*12 + 6], al ;個位數

mov byte ptr es:[160*12 + 40*12 + 8], ah ; 十位數

mov byte ptr es:[160*12 + 40*12 + 0ah], 2fh ; '/'

; 讀取日,coms 7單元的資料

mov  al, 7

call readconvert

mov byte ptr es:[160*12 + 40*12 + 0ch], al ; 個位數

mov byte ptr es:[160*12 + 40*12 + 0eh], ah ; 十位數

mov byte ptr es:[160*12 + 40*12 + 10h], ' ' ; 空格

; 讀取時

mov  al, 4

call readconvert

mov byte ptr es:[160*12 + 40*12 + 12h], al ; 個位數

mov byte ptr es:[160*12 + 40*12 + 14h], ah ; 十位數

mov byte ptr es:[160*12 + 40*12 + 16h], ':'

; 讀取分

mov  al, 2

call readconvert

mov byte ptr es:[160*12 + 40*12 + 18h], al ; 個位數

mov byte ptr es:[160*12 + 40*12 + 1ah], ah ;十位數

mov byte ptr es:[160*12 + 40*12 + 1ch], ':'

; 讀取秒

mov  al, 0

call readconvert

mov byte ptr es:[160*12 + 40*12 + 1eh], al ; 個位數

mov byte ptr es:[160*12 + 40*12 + 20h], ah ; 十位數

loop start

mov ax, 4c00h

int 21h

; 子程式,把2進製劃分為bcd碼,然後轉換為10進製的ascii碼,放在ah和al中

readconvert:

out 70h, al

in al, 71h

; 把讀取到的位元組用bcd碼表示出來

mov ah, al

mov cl, 4

shr al, cl

and ah, 00001111b

; 10進製顯示出來

add ah, 30h

add al, 30h

retcode ends

end start

本章學習到埠方面的知識,並用in和out指令來讀寫埠。

埠是在晶元裡的,晶元裡的資訊通過埠和cpu互動。

還有就是使用shr和shl來進行移位運算,從而把8位的二進位制轉化為兩個4位的bcd碼。。。

王爽《組合語言》學習筆記(第十三章 第十四章)

組合語言 學習筆記 第一章 第二章 組合語言 學習筆記 第三章 第四章 組合語言 學習筆記 第五章 第六章 組合語言 學習筆記 第七章 第八章 組合語言 學習筆記 第九章 第十章 組合語言 學習筆記 第十一章 第十二章 組合語言 學習筆記 第十三章 第十四章 組合語言 學習筆記 第十五章 第十六章 ...

組合語言(王爽) 實驗十四(20130909)

assume cs code,ds data,es info num data segment db 11 11 11 11 11 11 預設字串 data ends info num segment db 9,8,7,4,2,0 埠時間位址列表 info num ends code segment...

組合語言 王爽

cpu有三條匯流排 位址 資料 控制線 位址匯流排確定儲存單元 控制匯流排傳送指令 資料匯流排 傳輸資料 cpu n個位址線 位址匯流排寬度為n 可以尋找2 n個記憶體單元 儲存單元 0開始編號,乙個儲存單元可以儲存乙個byte 8086cpu有16根位址線 1bit就是一根位址線 注意 儲存器以b...