I am doing an assembly lab for my school and its on printing signed and unsigned numbers. It keeps printing an infinite amount of "-/" but it should be printing a number. Is the offset for number to ascii value 30h?
Display .EQU 04E9h
NumAddr .EQU 0050h
Main:
mov BX, NumAddr
mov DX, Display
mainLoop:
MOV AH,[BX]
cmp AH, 0h ; is number 0?
JE EndPrt ; if yes we are done
CMP AH,0h
JG posNum ; should jump to posNum if AH is positive
negNum:
mov AL, 2Dh
out DX,AL ; print a negative sign
NEG AH ; turn AH into a positive number
printPos:
MOV AL,[BX]
ADD AL, 30h ; should add required offset to convert to ASCII
out DX,AL
MOV AL, 0Dh
out DX,AL
MOV AL, 0Ah
out DX,AL
inc BX
jmp mainLoop
EndPrt:
HLT
.END Main
30h
is offset of single digit. Ie. (4 + 30h) is 34h
, and in ASCII encoding that is '4'
. But for (17 + 30h) you will get 41h
, which is character 'A'
.
If you want two characters for value 17, like 31h '1' and 37h '7', you must split the number into separate base 10 (decimal) digits (dividing it by 10 and collecting remainders).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.