Page 1 of 1
EFLAGS:
Posted: Sat Feb 17, 2007 12:28 am
by uglyoldbob
How am i supposed to read the value of the EFLAGS register?
The only commands I know of set the entire EFLAGS (pushf/popf) or set individual flags (sti, cli, ,,,). What about the other flags like trap, v8086 mode, etc? I checked the NASM docs and the forum, but apparently everybody except me knows how to do this.
Posted: Sat Feb 17, 2007 2:09 am
by xsix
PUSHF and then POP AX or PUSHFD and POP EAX or any other register, and then test it with OR AND XOR CMP or whatever you want. Or you can use conditional jumps, like JZ - jump if Zero Flag is set, JNZ - if not, JO - jump if overflown is set, and so on! If you want to test that there is CPUID capability just PUSHFD POP EAX and test eax, CPUID_BIT, JNZ CPUID_PRESENT
Posted: Sat Feb 17, 2007 7:05 am
by Mikae
For the first eight flags it is possible to use LAHF/SAHF instructions.
Posted: Sat Feb 17, 2007 9:21 am
by uglyoldbob
B.4.265 `PUSHFx': Push Flags Register
PUSHF ; 9C [8086]
PUSHFD ; o32 9C [386]
PUSHFW ; o16 9C [8086]
(*) `PUSHFW' pops a word from the stack and stores it in the bottom
16 bits of the flags register (or the whole flags register, on
processors below a 386).
(*) `PUSHFD' pops a doubleword and stores it in the entire flags
register.
`PUSHF' is an alias mnemonic for either `PUSHFW' or `PUSHFD',
depending on the current `BITS' setting.
See also `POPF' (section B.4.246).
..................................................................................................
B.4.246 `POPFx': Pop Flags Register
POPF ; 9D [8086]
POPFW ; o16 9D [8086]
POPFD ; o32 9D [386]
(*) `POPFW' pops a word from the stack and stores it in the bottom
16 bits of the flags register (or the whole flags register, on
processors below a 386).
(*) `POPFD' pops a doubleword and stores it in the entire flags
register.
`POPF' is an alias mnemonic for either `POPFW' or `POPFD', depending
on the current `BITS' setting.
See also `PUSHF' (section B.4.265).
..................................................................................................
So can I take it that the NASM instructions are not right? Because that is what was confusing me.
Posted: Sat Feb 17, 2007 9:25 am
by os64dev
the following code will do.
Code: Select all
pushfl; //- push flags on stack(same as pushfd)
pop %eax; //- %eax now contains flags