装配程序输出错误

时间:2016-11-13 21:27:55

标签: 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'
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

1 个答案:

答案 0 :(得分:2)

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

为什么你只在这里使用CL注册?
如果你通过功能2Ah从DOS获得了日期,那么你已经在整个CX注册中收到了一年中的数字。这将在1980年至2099年的范围内。在处理世纪内的年份(0-99)之前,您的程序需要从此值中减去2000:

mov ax, cx  ;Year
sub ax, 2000
mov bl, 10
div bl
  

日显示为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