Reputation: 73
I'm having trouble trying to set a zero flag. I have done some research online but it has come to confuse me even more. Correct me if I'm wrong but it's my understanding that you can use MOV, ADD, SUB, INC, and DEC and set and clear flags? So would something like this work..?
.data
Num1 = 18
Num2 = 18
.code
main PROC
sub num2, num1
main ENDP
END main
and that would set a ZF for example? If that's the case then how would I clear it?
Upvotes: 2
Views: 1100
Reputation: 9899
Correct me if I'm wrong but it's my understanding that you can use MOV, ADD, SUB, INC, and DEC and set and clear flags?
It's true that add
, sub
, inc
and dec
will set/clear several flags including the ZF.
mov
on the other hand will never changes any flags!
sub num2, num1
This is a very impossible instruction.
It's not allowed for the mandatory 2 operands of the sub
instruction to be both immediates (just numbers) or both variables (memory locations).
In your example you could verify the flags from the result of:
mov ax, Num2
sub ax, Num1
Since both values are the same, hereafter the ZF will be set.
Upvotes: 1
Reputation: 29022
This code won't set the ZERO flag, because of a spelling case check:
Num1
!= num1
and Num2
!= num2
.
Apart from that, you're not defining any .data
values, because Num1 = 18
andNum2 = 18
, respectively, are constant assignments and do not define a data value.
So you're essentially trying to compare a constant to a constant by the OpCode(CMP
), which is invalid and wouldn't pass any assemblers syntax check.
Upvotes: 1