Reputation: 411
I want to take two inputs and multiply them and print the result in emu8086. But the problem is multiply is only possible with AL or AX as one fixed operand. suppose i can't multiply BX and DX. So now how can i take input of AL and BL and multiply them.
my code:
mov ah,1
int 21h
mov bl,al
int 21h
mul bl
mov ah,2
mov dl,al
int 21h
Upvotes: 1
Views: 1905
Reputation: 9899
The input that you get from using DOS function 01h is a character. You need to convert this into the digit that it stands for. e.g."2" is converted to the value 2. We simply subtract 48 to do this.
The multiplication mul bl
is correct (AL
* BL
). The product will be in AX
but both inputs are limited to 9 and so the product will never be larger than 81.
Before printing you need to convert the value of the product back to a character by adding 48. This can only work if the product was not above 9 because otherwise it would require more than 1 character.
mov ah,1
int 21h
SUB AL, 48
mov bl,al
MOV AH, 01h
int 21h
SUB AL, 48
mul bl
mov ah,2
mov dl,al
ADD DL,48
int 21h
If you input "2" and "3" you'll get an output of "6".
Upvotes: 3