I'm preparing for an exam where I have to find the results of x86 Assembly programs without a computer, in particular I have a problem with an example our teacher gave us:
MOV AX,6326
OR EAX,0000FFF1h
AND EAX,0000000Fh
MOV BL,-1
SUB BL,250
MUL BL
What is AX?
If I try to do it by myself, the process seems to be:
OR
and the AND
, EAX is 00000007h, so 7 in decimalSUB BL, 250
= -1 - 250 = -251MUL BL
= -251 x 7 = -1757, so without the sign AX is equal to 1757But if I try to run it on VS, the result is 35.
I think that the difference is caused by the two's complement, but I don't understand why or where this change happens.
MOV AX,6326 18B6h AX
OR EAX,0000FFF1h 0000FFF7h EAX
AND EAX,0000000Fh 00000007h EAX
MOV BL,-1 FFh BL
SUB BL,250 05h BL
MUL BL 0023h AX
You were right about EAX.
For MOV BL,-1
you should note that the CPU does not modify any flags while loading a register via MOV
. This instruction could just as well have read MOV BL,255
, since that is the actual bitpattern that gets stored in this register (-1 and 255 share the same bitpattern). If you look at it that way, the subtraction becomes a very normal 255 - 250 producing 5. The unsigned MUL
that follows calculates the equally simple 7 * 5 producing 35.