MOV AX, 200
ADD AX, 300
MOV RESULT, AX
Will result be equal to 500?
Yes.
I tried adding 3 and 2 and using this to show output:
MOV DX, RESULT
ADD RESULT, '0'
MOV AH, 02H
INT 21H
But the output is a candy cane character! Where is it wrong?
You're adding '0'
to RESULT
after moving RESULT
to DX
. You should probably add '0'
to DL
instead of to RESULT
.
Now division.
MOV AX, 30
MOV BX, 12
DIV BX
MOV RESULT, AX
What holds the quotient? If what I read was correct, that would be AX, and DX holds the remainder...?
DIV BX
divides the 32-bit value DX:AX
by BX
, so you should clear DX
before the division. The quotient will end up in AX
and the remainder in DX
.
Someone suggested that I should declare my variables as
RESULT dw ?
If you're going to move 16-bit values to/from the variable (e.g. MOV RESULT,AX
) then you should make the variable (at least) 16 bits.