Professional Documents
Culture Documents
4
X86 Processor
• X86 processor started as 8-bit and subsequent
generations expanded to 16 bit, 32 bit and 64
bit registers.
• This overlapping led to certain overlapping in
the naming of registers.
Types of registers
Registers are categorized into:
• General purpose registers
• EFLAG registers
• Segment registers
General purpose register
64 bit 32 bit 16 bit 8 bit Register
RAX EAX AX AH,AL Accumulator
RCX ECX CX CH, CL Counter
RDX EDX DX DH,DL Data
RBX EBX BX BH,BL Base
RSI ESI SI Source Index
RDI EDI DI Destination
Index
RSP ESP SP Stack
Pointer
RBP EBP BP Base Pointer
General-Purpose Registers (GPR)
• Accumulator register (AX)- Used in arithmetic operations
• Counter register (CX) - Used in shift/rotate instructions and
loops.
• Data register (DX) -Used in arithmetic operations and I/O
operations.
• Base register (BX) - Used as a pointer to data (located in segment
register DS, when in segmented mode).
• Stack Pointer register (SP)-Pointer to the top of the stack.
• Stack Base Pointer register (BP)-Used to point to the base of the
stack.
• Source Index register (SI)- Used as a pointer to a source in
stream operations.
• Destination Index register (DI)- Used as a pointer to a
destination in stream operations.
32-bit and 64-bit
• In 32-bit mode, this two-letter abbreviation is
prefixed with an 'E' (extended). For example,
'EAX' is the accumulator register as a 32-bit
value.
• Similarly, in the 64-bit version, the 'E' is
replaced with an 'R' (register), so the 64-bit
version of 'EAX' is called 'RAX'.
EFLAGS register
• The EFLAGS is a register used as a collection of
bits representing Boolean values to store the
results of operations and the state of the
processor.
Control/flag registers
• The flags register maintains the current
operating mode of the CPU and some
instruction state information.
• Mathematical operations and conditional
operations affect the status of these flags.
Flag registers
• Overflow flag (OF)
• Direction flag (DF)
• Interrupt flag (IF)
• Trace Flag (TF)
• Sign Flag (SF)
• Zero Flag (ZF)
• Auxiliary Carry Flag (AF)
• Parity Flag (PF)
• Carry Flag (CF)
Overflow Flag (OF)
• This flag contains a one if the result does not fit
in the signed destination operand.
• For example, if you attempt to add the 16 bit
signed numbers 7FFFh and 0001h the result is
too large so the CPU sets the overflow flag.
• If the result of the arithmetic operation does
not produce a signed overflow, then the CPU
clears this flag.
Direction Flag (DF)
• Direction Flag (DF) determines left or right
direction for moving or comparing string data.
• When the DF value is 0, the string operation
takes left-to-right direction and when the value
is set to 1, the string operation takes right-to-
left direction.
Interrupt Flag (IF):
• Some programs contain certain instruction
sequences that the CPU must not interrupt.
• The interrupt enable/disable flag turns
interrupts on or off to guarantee that the CPU
does not interrupt those critical sections of
code.
Trace Flag (TF)
• The trace flag enables or disables the trace mode.
• Debuggers (such as CodeView)
use this bit to enable or disable the single step/trace
operation.
• When set, the CPU interrupts each instruction and
passes control to the debugger software, allowing the
debugger to single step through the application.
• If the trace bit is clear, then the 80x86 executes
instructions without the interruption.
Sign Flag (SF)
• If the result of some computation is negative, the
80x86 sets the sign flag.
• The sign is indicated by the high-order of leftmost
bit.
• A positive result sets the value of SF to 0 and
negative result sets it to 1.
Zero Flag (ZF)
• Use this flag to see if two values are equal (e.g., after
subtracting two numbers, they are equal
if the result is zero).
• This flag is also useful after various logical operations to see
if a specific bit in a register or memory location contains
zero or one