程序功能:以“年/月/日 时:分:秒” 的格式,显示当前的日期,时间
代码如下:
assume cs:code
code segment
s: db 9,'/',8,'/',7,' ',4,':',2,':',0,'$' ;将日期和时间在CMOS中储存的位置以及要显示的符号列出
start:
mov ax,cs
mov ds,ax
mov si,offset s
mov di,160*12+40*2 ;设置日期和时间出现的位置
read:
cmp byte ptr ds:[si],'$'
je exit
cmp byte ptr ds:[si],'/'
je do
cmp byte ptr ds:[si],' '
je do
cmp byte ptr ds:[si],':'
je do ;条件判断以及相关跳转
mov al,ds:[si]
out 70h,al
in al,71h
change:
mov ah,al
mov cl,4
shr ah,cl
and al,00001111b
add ah,30h
add al,30h
call show_date
add di,4
inc si
jmp short read
do:
call show_symbol
add di,2
inc si
jmp short read
exit: mov ax,4c00h
int 21h
show_date: ;显示日期和时间的子程序
push bx
push es
push di
mov bx,0b800h
mov es,bx
mov byte ptr es:[di],ah
mov byte ptr es:[di+1],00000010b
mov byte ptr es:[di+2],al
mov byte ptr es:[di+3],00000010b
pop di
pop es
pop bx
ret
show_symbol: ;显示符号的子程序
push ax
push es
mov ax,0b800h
mov es,ax
mov al,ds:[si]
mov ah,00000010b
mov byte ptr es:[di],al
mov byte ptr es:[di+1],ah
pop es
pop ax
ret
code ends
end start