I got the user to enter a 16 bit number. I want to display the number entered by the user.
This is what I've come up with so far.
As you can see, I have subtracted 30H from the input to convert it to decimal. Where should I add 30H back to get it back to its original ASCII value?
MOV AH,1H ;user input for first number part 1
INT 21H
SUB AL,30H
MOV NUM1,AL
MOV AH,1H ;1st number part 2
INT 21H
SUB AL,30H
MOV NUM2,AL
MOV AH,1H ;1st number part 3
INT 21H
SUB AL,30H
MOV NUM3,AL
MOV AH,1H ;1st number part 4
INT 21H
SUB AL,30H
MOV NUM4,AL
XOR AH,AH
MOV AL,NUM1
MOV DX,1000D
MUL DX ;1*1000
ADD AH,30H
ADD AL,30H
MOV BX,AX
XOR AH,AH
MOV AL,NUM2
MOV DX,100D
MUL DX ;2*100
ADD BX,AX
XOR AH,AH
MOV AL,NUM3
MOV DX,0010D
MUL DX ;3*10
ADD AH,30H
ADD AL,30H
ADD BX,AX
XOR CH,CH
MOV CL,NUM4
ADD CH,30H
ADD CL,30H
ADD BX,CX ;BX now has the 16 bit number
MOV FNUM1,BX ;final 1st 16 bit number
PRINTN
LEA DX,MSG8 ;msg for output
MOV AH,9H
INT 21H
PRINT FNUM1
For eg: when I enter the number as 1234, I get output as F. Can you guys let me know what I'm doing wrong and help me out? Any help would be appreciated at this point.
ADD AX,3030H
after a 16-bit multiply makes zero sense. You have a binary integer, not two BCD digits. See NASM Assembly convert input to integer? for simple / working string->int functions that take an ASCII decimal string and produce a binary integer in a register. – Peter Cordes