📄 读取并显示计算机实时时钟.txt
字号:
assume cs:code,ds:data
;*************************************************************************************************
data segment
db 'yy/mm/dd hh:mm:ss'
db 9,8,7,4,2,0 ;CMOS中时间信息的单元号
data ends
;*************************************************************************************************
stack segment
dw 8 dup(0)
stack ends
;*************************************************************************************************
code segment
start:
mov bx,data
mov ds,bx
mov bx,stack
mov ss,bx
mov sp,16d
mov si,0 ;si指向'yy/mm/dd hh:mm:ss'的首地址
mov di,17d ;di指向9,8,7,4,2,0的首地址
mov cx,6 ;循环次数
s: push cx
mov al,ds:[di] ;从CMOS中读出年份的BCD码
out 70h,al
in al,71h
mov ah,al ;al中位读出的数据
mov cl,4
shr ah,cl ;ah中为年份的十位数
and al,00001111b ;al中为年份的个位数
add ah,30h ;把数值转换为对应的ASCII码
add al,30h ;同上
mov byte ptr ds:[si],ah ;把读出的时间写入ds段
mov byte ptr ds:[si+1],al
add si,3
inc di
pop cx
loop s
;把读出的内容按yy/mm/dd hh:mm:ss的格式写显存
mov bx,0b800h
mov es,bx
mov ch,ds:[0]
mov byte ptr es:[160*16+26*2],ch
mov cl,ds:[1]
mov byte ptr es:[160*16+26*2+2],cl
mov cl,ds:[2]
mov byte ptr es:[160*16+26*2+4],cl
mov ch,ds:[3]
mov byte ptr es:[160*16+26*2+6],ch
mov cl,ds:[4]
mov byte ptr es:[160*16+26*2+8],cl
mov cl,ds:[5]
mov byte ptr es:[160*16+26*2+10],cl
mov ch,ds:[6]
mov byte ptr es:[160*16+26*2+12],ch
mov cl,ds:[7]
mov byte ptr es:[160*16+26*2+14],cl
mov cl,ds:[8]
mov byte ptr es:[160*16+26*2+16],cl
mov ch,ds:[9]
mov byte ptr es:[160*16+26*2+18],ch
mov cl,ds:[10]
mov byte ptr es:[160*16+26*2+20],cl
mov cl,ds:[11]
mov byte ptr es:[160*16+26*2+22],cl
mov ch,ds:[12]
mov byte ptr es:[160*16+26*2+24],ch
mov cl,ds:[13]
mov byte ptr es:[160*16+26*2+26],cl
mov cl,ds:[14]
mov byte ptr es:[160*16+26*2+28],cl
mov ch,ds:[15]
mov byte ptr es:[160*16+26*2+30],ch
mov cl,ds:[16]
mov byte ptr es:[160*16+26*2+32],cl
;调用int 16h的1号功能,从键盘缓冲区读字符
mov ah,1
int 16h
cmp al,'q' ;若按q键则退出程序
je exit
jmp start ;使程序反复读CMOS,从而实现动态显示时间
exit: mov ax,4c00h
int 21h
code ends
;*************************************************************************************************
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -