Assembly
Code & debug the following program in VS, then answer these questions at the end of the code using comments:
a) To which label the program jumped?
b) Why did the program jump to this label?
c) Why the program didn’t jump to the other label, since ‘80h > 7Fh’ is correct?
mov al,+127 ;hex value is 7Fh (+127)
cmp al,-128 ;hex value is 80h (-128)
ja IsAbove
jg IsGreater
IsAbove:
exit
IsGreater:
exit
To answer this question lets, first understand the JA and JF flags.
JA Flag : Algorithm: if (CF = 0) and (ZF = 0) then jump
JG Flag : if (ZF = 0) and (SF = OF) then jump
Now, let us understand the CMP label:
Compare. Algorithm: operand1 - operand2
The immediate result is not stored anywhere, flags are set (OF, SF, ZF, AF, PF, CF) according to result.
Now in the question we are using CMP on +127 and -128, when subtracting it will result in -1.
For jump condtion to stasify we need to set ZF = 0.
But ZF = 0 only if After any arithmetical or logical
operation if the result is 0 or 00H, the zero flag becomes set i.e.
1, otherwise it becomes reset i.e. 0.
We can see that carry flag is also 0.
So JA Flag would be used.
a) isAbove label
b) I have explained it above.
c) Because the result is not stored in immediate result, but using flags, as explained above.
Get Answers For Free
Most questions answered within 1 hours.