User:Johnburger/Demo/x86/EFlags
< User:Johnburger | Demo
Jump to navigation
Jump to search
Personally, I prefer Borland's TASM and Microsoft's MASM syntax for bitfields: you can define a RECORD
for a bitfield, and then each individual bit or range of bits are accessible through the use of keywords like SHIFT
, MASK
and WIDTH
to reference the fields.
You want to isolate x86.EFlags.IOPL?
x86.EFlags RECORD
.NT : 1 ; Nested Task Flag
.IOPL : 2 ; I/O Privilege Level
.OF : 1 ; Parity Flag
.DF : 1 ; Direction Flag
.IF : 1 ; Interrupt Flag
.TF : 1 ; Trace Flag
.SF : 1 ; Sign Flag
.ZF : 1 ; Zero Flag
: 1 ; Reserved
.AF : 1 ; Arithmetic Flag
.0 : 1 ; Always 0
.PF : 1 ; Parity Flag
.1 : 1 ; Always 1
.CF : 1 ; Carry Flag
x86.EFlags ENDS
PUSHFD
POP EAX
AND EAX,MASK x86.EFlags.IOPL
SHR EAX,SHIFT x86.EFlags.IOPL
MOV CL,WIDTH x86.EFlags.IOPL
(Of course, I've muddied the example by using NASM's sophisticated local-label syntax that TASM doesn't support, and I've used a non-supported "missing bit" syntax extension...)
I've seen posts asking why the whole RECORD
, MASK
, SHIFT
, and WIDTH
infrastructure exists: THIS is why! NASM doesn't support the keywords: I miss them...
Demo/x86/EFlags.inc
;
; x86/EFlags.inc
;
; The following are the bitfields in the EFlags register
x86.EFlags.ID EQU 0000_0000_0010_0000_0000_0000_0000_0000b
x86.EFlags.VIP EQU 0000_0000_0001_0000_0000_0000_0000_0000b
x86.EFlags.VIF EQU 0000_0000_0000_1000_0000_0000_0000_0000b
x86.EFlags.AC EQU 0000_0000_0000_0100_0000_0000_0000_0000b
x86.EFlags.VM EQU 0000_0000_0000_0010_0000_0000_0000_0000b
x86.EFlags.RF EQU 0000_0000_0000_0001_0000_0000_0000_0000b
x86.EFlags.NT EQU 0000_0000_0000_0000_0100_0000_0000_0000b
x86.EFlags.IOPL EQU 0000_0000_0000_0000_0011_0000_0000_0000b
x86.EFlags.OF EQU 0000_0000_0000_0000_0000_1000_0000_0000b
x86.EFlags.DF EQU 0000_0000_0000_0000_0000_0100_0000_0000b
x86.EFlags.IF EQU 0000_0000_0000_0000_0000_0010_0000_0000b
x86.EFlags.TF EQU 0000_0000_0000_0000_0000_0001_0000_0000b
x86.EFlags.SF EQU 0000_0000_0000_0000_0000_0000_1000_0000b
x86.EFlags.ZF EQU 0000_0000_0000_0000_0000_0000_0100_0000b
x86.EFlags.AF EQU 0000_0000_0000_0000_0000_0000_0001_0000b
x86.EFlags.PF EQU 0000_0000_0000_0000_0000_0000_0000_0100b
x86.EFlags.1 EQU 0000_0000_0000_0000_0000_0000_0000_0010b
x86.EFlags.CF EQU 0000_0000_0000_0000_0000_0000_0000_0001b