NASM Forum > Programming with NASM

How do you retrieve the Zero Flag in assembly?

(1/1)

ben321:
If I do a comparison operation like "TEST EAX,EAX", the result of that operation is unfortunately not stored in any normal accessible register like ECX or whatever. Instead it's stored in the Zero Flag bit of the CPU status register. This works great when using a conditional jump instruction (like JNE), which internally looks at such flag bits. However what if I want to just extract ZF bit for further usage that DOESN'T involve a conditional jump, how do I do that? For example, how do I store the ZF bit in the lowest bit of the EAX register? I don't know if there's any kind of GetZeroFlagBit instruction in x86 assembly.

Frank Kotler:

--- Code: ---pushf
pop eax ; or other reg

--- End code ---

Best,
Frank

Frank Kotler:
Hi again Ben,

I should have said... You probably don't want to do this. Probably better to save the "mystery value" and test it for zero when you're ready to use the result than to test it now and save the result. But if you want to, "pushf"...

Best,
Frank

fredericopissarra:

--- Code: ---setz al  ; al = 0 if ZF=0, 1 if ZF=1
--- End code ---

Frank Kotler:
We live and learn! Thank you, Fred!

Best,
Frank

Navigation

[0] Message Index

Go to full version