以[年/月/日 时:分:秒]的格式显示当前日时
时间从cmos ram的读取,987420分别对应年月日时分秒,
保存在cmos ram是BCD码的格式。
如2的BCD是0010,6的BCD是0110,所以26的BCD是00100110。
而26的BCD码右移四位可以得到0010,即2;and 00001111B可以得到0110,即6。
数字+30H即可得到对应的字符串,如’0’=30H,‘1’=31H。
程序最终显示20/ 02/ 16 22: 00: 11 ,因为这里数据以push的形式保存,
3个标题符号都是1个字节,所以多保存了高位的两个0,读取时0H等于空格。
注意必须先高位乘以2再低位,否则0000,1000+0000,1000=0010,0000
assume cs:code
code segment
d1:db 0,2,4,7,8,9
start:
mov ax,code
mov ds,ax
mov si,offset d1
mov cx,6
mov ax,24h
push ax
s1:
mov al,[si]
out 70h,al
in al,71h
mov ah,0
call fun
inc si
push ax
cmp cx,4
jz addSpace
jc addXiexian
jmp short addMaohao
back:
loop s1
mov ax,ss
mov ds,ax
mov dx,sp
mov ah,9
int 21h
mov ax,4c00h
int 21h
addSpace: ;// +空格
mov ax,20h
push ax
jmp short back
addMaohao: ;// +冒号
mov ax,3ah
push ax
jmp short back
addXiexian: ;// +斜线
cmp cx,1 ;// 年前面不加斜线
jz next
mov ax,2fh
next:
push ax
jmp short back
fun:
push cx
mov ah,al
mov cl,4
shr al,cl
and ah,00001111b
add ah,30h
add al,30h
pop cx
ret
code ends
end start
有个更简单的思路https://blog.csdn.net/weixin_41944412/article/details/80588423
data segment
db '00/00/00 00:00:00','$'
db 9,8,7,4,2,0
data ends