开发者

Assembly 386: Unexpected output when using Interrupt 21h with function 02h

I'm beginning today with Assembly (i386) and I'm trying to output the caracters of a 2-digits number. The way I found after some resarch is to divide my number by 10d to get the remainder and the quotient and then to use interruption 21h with function 02h to output separately the 2 digits.

开发者_如何转开发My problem is that with the code below I'm expecting 53 as an output but I have 55. It looks like the value stored in AL register is modified (I made a try using variables to store the quotient and the remainder and the output is correct in that case). I want to understand why I don't have the expected output with my code below.

Am I doing something wrong? Can anybody explain me in details please? Moreover, regarding performances, can you confirm me that it is better to use the registers rather than storing the quotient and the remainder in variables.

.386
code segment use16
assume cs:code, ds:code, ss:code
org 100h ;offset décalés de 100h=256

label1:

;Division to get quotient and remainder
MOV AX, 35d
DIV divisor

;If the divider is a byte then 
;the quotient will be stored on the AL register 
;and the residue on AH

ADD AH, 30h
ADD AL, 30h

;Displays first caracter (from the right of the string)
MOV DL, AH
MOV AH, 02h
INT 21h

;Displays second character (from the right of the string)
MOV DL, AL
MOV AH, 02h
INT 21h


RET

divisor db 10d

code ends

end label1


Yes, if I recall correctly, INT 21h, and any interrupt is allowed and indeed is likely to overwrite any of the registers AX, CX, and DX.

Your simplest work-around is probably

PUSH AX

;Displays first caracter (from the right of the string)
MOV DL, AH
MOV AH, 02h
INT 21h

POP AX

;Displays second character (from the right of the string)
MOV DL, AL
MOV AH, 02h
INT 21h
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜