I just need some help. I don't fully understand and I am fairly new to masm32 so if you could explain, that would be great!
MOV AX, 200
ADD AX, 300
MOV RESULT, AX
Will result be equal to 500? 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?
Now I assume subtraction will work the same as addition, so on to Multiplication we go. This is what I did for multiplication
MOV AX, 30
MOV BX, 8
MUL BX
MOV RESULT, AX
Is RESULT's value equal to 240?.... I tried AX as 3 and BX as 2. The output is a spade. Can you point me to the right direction?
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...?
I have already done 8 bit arithmetic (using AL, BL, DL...) and I tried to apply it here, sadly, when the RESULT becomes greater than 128, it just outputs garbage. Someone suggested that I should declare my variables as 'RESULT dw ?' instead of 'RESULT db ?' and instead of AL BL registers I should use AX BX.... Now I'm stuck.
Any help would be appreciated! Sorry if these questions seem too trivial. Anyway, thanks in advance! :DD
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.