Assembly: Flags

Contributor Icon Contributed by William_Wilson  
Tag Icon Tagged: Computer programming  

The EFlags register, what they, what they do and when they are set.


The flags are located in a single 32-bit register (EFlags), each a single bit, thus holding a value of 1 true, or 0 false.

I will list the flags by name, location in the register and use:
*location will be a bit from 0-31
00: CF Carry Flag – becomes one if an addition, multiplication, AND, OR, etc results in a value larger than the register meant for the result
02: PF Parity Flag – becomes 1 if the lower 8-bits of an operation contains an even number of 1 bits
04: AF Auxiliary Flag – Set on a carry or borrow to the value of the loer order 4 bits
06: ZF Zero Flag – becomes 1 if an operation results in a 0 writeback, or 0 register
07: SF Sign Flag – is 1 if the value saved is negative, 0 for positive
08: TF Trap Flag – allows for the stopping of code within a segment (allows for single stepping/debugging in programming)
09: IF Interrupt Flag – when this flag is set, the processor begins ‘listening’ for external interupts
10: DF Direction Flag – determines the direction to move through the code (specific to repeat instructions)
11: OF Overflow Flag – becomes 1 if the operation is larger than available space to write (eg: addition which results in a number >32-bits)
12-13: IOPL I/O Privilage Level – Read, Write, or a combination of the 2 (2-bit register)
14: NT Nested Task – becomes 1 when calls within a program are made
16: RF Resume Flag – stays 1 upon a break, and stays that way until a given ‘release’ or resume opertaion/command occurs
17: VM Virtual Machine 8086 – becomes a 1 if the processor is to simulate the 8086 processor (16-bit)
18: AC Alignment Check – checks that a file or command is not breaking it’s privilage level
19: VIF Virtual Interupt Flag – almost always set in protected mode, listening for internal and assmbling interupts
20: VIP Virtual Interupt Pending – 1 if a virtual interupt is yet to occur
21: ID ID Flag – is set if a CPU identification check is pending (used in some cases to ensure valid hardware)

*Missing bits are not mistakes, some flags temporarily use 2+ bits, and use neighbors to hold temporary values, also there are 17 necessary flags so 32-bits is the smallest register to hold them. (2^5)

NOTE: a single operation may change or set multiple flags, even those which seem independant may be nullified by specific operations.

The flags are used in many operations to save clock cycles and determine results without actually have to do read operations.
examples: jmp command (can be modified to a conditional jump, based on a flags value)

Questions/Comments: william_a_wilson@hotmail.com
-William. § (marvin_gohan)

 

1 Comment -


  1. Khaostrik said on February 14, 2011

    Nice but

    “04: AF Auxiliary Flag – Set on a carry or borrow to the value of the > loe lower

 

RSS feed for comments on this post. TrackBack URL

Leave a comment -