Set means flag value = 1
and Unset means flag value = 0
Now I understand there are several ways to set and unset flags in MASM, as follows:
test al,0 ; set Zero flag
and al,0 ; set Zero flag
or al,1 ; clear Zero flag
Same goes for Sign flag
:
or al,80h ; set Sign flag
and al,7Fh ; clear Sign flag
To set the Carry flag
, we use the STC instruction; to clear the Carry flag, we use CLC:
stc ; set Carry flag
clc ; clear Carry flag
To set the Overflow flag
, we add two positive values that produce a negative sum. To clear the Overflow flag
, we OR an operand with 0:
mov al,7Fh ; AL = +127
inc al ; AL = 80h (-128), OF=1
or eax,0 ; clear Overflow flag
The Overflow
and Carry
flags operations are self-understood and easy to grasp, but I find it hard to understand the mathematics behind setting the Zero/Sign
flags. Any help is appreciated!
Thanks!