Reputation: 35
I'm doing a little practice in assembly, using 8086 TASM, and i've encountered a problem I'm trying to solve for some time now. The main program, a basic calculator to add, and substract big numbers. I reached the point to store the user input, and tried to substract 48 from it, to be a real decimal number. The problem is it's writing out smileys and poker symbols instead of actual numbers. Here's the code of the reading and printing:
READNUM PROC
PUSH SI
MOV CX, 0
READ:
MOV AH, 1h
INT 21h
CMP CX, 9
JE ENDREAD
CMP AL, 0dh
JE ENDREAD
SUB AL, 48d
MOV [SI], AL
INC CX
INC SI
JMP READ
ENDREAD:
MOV byte ptr [SI], 0
MOV AX, 0e0ah
INT 10h
POP SI
CALL PRINTER
RET
READNUM ENDP
PRINTER PROC
CYCLE:
LODSB
CMP AL, 0
JE OVER
MOV AH, 14
INT 10H
JMP CYCLE
VER:
RET
PRINTER ENDP
Upvotes: 0
Views: 197
Reputation: 58467
You convert the digits from characters to values when you subtract 48 (e.g. '0'
-> 0
). When you want to print the digits to the screen you need to convert them back to characters by adding 48 again.
Upvotes: 2
Reputation: 35
In the mean time I've found what was missing. I forgot to add 30h to al. just like this before sub:
...
ADD AL, 30h
SUB AL, 48d
...
Upvotes: 0