EFLAGS:

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
uglyoldbob
Member
Member
Posts: 62
Joined: Tue Feb 13, 2007 10:46 am

EFLAGS:

Post 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.
I have an 80386SX 20MHz 2MB RAM.
It is my testbed platform. Only has the 3.5" and 5.25" floppy drives.
xsix
Member
Member
Posts: 59
Joined: Tue Oct 24, 2006 10:52 am

Post 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
Mikae
Member
Member
Posts: 94
Joined: Sun Jul 30, 2006 1:08 pm

Post by Mikae »

For the first eight flags it is possible to use LAHF/SAHF instructions.
uglyoldbob
Member
Member
Posts: 62
Joined: Tue Feb 13, 2007 10:46 am

Post 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.
I have an 80386SX 20MHz 2MB RAM.
It is my testbed platform. Only has the 3.5" and 5.25" floppy drives.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

the following code will do.

Code: Select all

pushfl;      //- push flags on stack(same as pushfd)
pop    %eax; //- %eax now contains flags
Author of COBOS
Post Reply