Assembly 汇编程序输出错误

Assembly 汇编程序输出错误,assembly,x86-16,Assembly,X86 16,这段代码应该以年:月:日的形式显示日期,但年显示为20f4,日显示为58,我不知道为什么 ; return: CX = year (1980-2099). DH = month. DL = day. AL = day of week (00h=Sunday) displaydate: mov ah,2Ah int 21h ; get date mov dl,' ' mov ah,02h int 21h mov dl,' ' mov ah,02h int 21h mov dl,'2'

这段代码应该以年:月:日的形式显示日期,但年显示为20f4,日显示为58,我不知道为什么

; return: CX = year (1980-2099). DH = month. DL = day. AL = day of week (00h=Sunday)  
displaydate:
mov ah,2Ah
int 21h   ; get date

mov dl,' '
mov ah,02h
int 21h
mov dl,' '
mov ah,02h
int 21h  
mov dl,'2'
mov ah,02h
int 21h 
mov dl,'0'
mov ah,02h
int 21h 


mov al,cl ; year
mov  ah,0 
mov bl,10
div bl 

 mov years1,al ; number
mov years2,ah ;remainder  
add years1,30h
add years2,30h;asci code 

mov dl,years1
mov ah,02h
int 21h   
 mov dl,years2
mov ah,02h
int 21h 
mov dl,':'
mov ah,02h
int 21h
;--------------------------------------------- 

mov al,dh ;months
mov  ah,0  
mov bl,10
div bl  

mov month1,al ; number
mov month2,ah ;remainder  
add month1,30h
add month2,30h;asci code 

mov dl,month1
mov ah,02h
int 21h   
 mov dl,month2
mov ah,02h
int 21h 
mov dl,':'

mov ah,02h
int 21h  
;-------------------------------------------------
 mov al,DL  ;days
mov  ah,0  
mov bl,10
div bl  

mov days1,al ; number
mov days2,ah ;remainder  
add days1,30h
add days2,30h;asci code 

mov dl,days1
mov ah,02h
int 21h   
 mov dl,days2
mov ah,02h
int 21h
为什么您只在这里使用
CL
注册?
如果您通过函数2Ah从DOS获得日期,则您已在整个
CX
寄存器中收到该年的数字。这将在1980-2099年的范围内。在处理世纪(0-99)内的年份之前,您的程序需要从该值中减去2000:


一天显示为58,我不知道为什么

当天的数字保留在
DL
寄存器中,但当您的程序准备好处理它时,
DL
中的数字已被所有中间代码更改为通过DOS显示字符!也就是说你在里面放了很多其他的值。使用
push
/
pop
不释放日值:

mov ah,2Ah
int 21h   ; get date
PUSH DX   <<< This preserves the day value in DL

;do all the other stuff

POP DX    <<< This restores the day value in DL
;-------------------------------------------------
mov al,DL  ;days
mov  ah,0  
mov bl,10
div bl  
mov days1,al ; number
mov days2,ah ;remainder  
add days1,30h
add days2,30h;asci code 
mov-ah,2Ah
int 21h;约会

推送DX您尚未列出任何已遵循的故障排除或调试步骤。第一个问题应该是,“使用调试器逐步完成它,并查看在哪一点开始出现您不理解的行为。”通常,这将允许您解决问题。
mov ax, cx  ;Year
sub ax, 2000
mov bl, 10
div bl
mov ah,2Ah
int 21h   ; get date
PUSH DX   <<< This preserves the day value in DL

;do all the other stuff

POP DX    <<< This restores the day value in DL
;-------------------------------------------------
mov al,DL  ;days
mov  ah,0  
mov bl,10
div bl  
mov days1,al ; number
mov days2,ah ;remainder  
add days1,30h
add days2,30h;asci code