I can't execute programs like shl
, shr
, mul
, div
shl
, shr
, mul
, div
are instructions. Please don't refer to them as programs.
... I covert it through subtracting 30h ...
See in the code below that the conversion requires you to add 30h instead of subtracting 30h.
Mov Al 2
Mov Bx 2
mul bx
mov dx,bx
mov ah,2
int 21h
You can correct this program that multiplies 2 single digit numbers.
Error 1 : Choose the correct size multiplication. Using mul bx
, you've calculated DX:AX = AX * BX
which is overkill in this case. Moreover since you forgot to zero AH
, you got random results!
mov al, 2
mov bl, 2
mul bl ; -> AX = AL * BL
Error 2 : Convert the result which is the number 4 ( 2 * 2 ) into the character "4".
Also notice that the result of the mul
instruction is not to be found in the BX
register, like your code is thinking (mov dx, bx
).
mul bl
leaves its result in AX
, and since the value is so small, we need only use AL
(the low half of AX
)
add al, "0" ;"0" = 30h
mov dl, al
mov ah, 02h
int 21h
It's important to see that this very simple way of displaying the result can only work for results varying from 0 to 9.
To display numbers that are outside this [0,9] range take a look at Displaying numbers with DOS. The text explains in great detail how you can convert any number into its textual representation and output that to the screen.