x86 Assembly Registers[All Types Explained]

As a whole, there are fourteen(14) x86 registers and 35 MIPS registers. They are classified into three parts:

  • Data Registers: Holds data for operations.
  • Address Register: Holds Address of instruction.
  • Status Registers: Store the current status of the processor.

Table X86 Registers

DATA REGISTERS ADDRESS REGISTERS STATUS REGISTERS
32 bit 16 bit 8+8 bit Segment Pointer Index Status Flags Control Flags
EAX AX AL+AH CS SP SI CF SF TF
EBX BX BL+BH DS BP DI PF OF IF
ECX CX CL+CH SS AF ZF DF
EDX DX DL+DH ES

 

Now we gonna explain these registers step by step:

Data Registers In x86 Assembly

Four sets of registers contain in the x86 assembly are for general data manipulation. However, a processor can operate on data stored in memory, but processor can perform data manipulation at the much faster rate when data is in registers. Read further to find out the functionalities of these registers.

Data registers are divided into three parts according to sizes:

  • EAX, EBX, ECX, EDX are 32-bit data registers.
  • Further lower part of EAX, EBX, ECX, EDX are used as 16-bit data registers which are AX, BX, CX, DX.
  • Furthermore, higher and lower parts of AX, BX, CX, DX can be used as 8-bit data registers which are AL, BL, CL, DL and AH, BH, CH, DH whereas H is used for the higher part and L is used for the lower part.

Accumulator Register(AX)

Accumulator register is preferred to use in arithmetic, logic, and data transfer operations. i.e. In division and multiplication, one of the numbers must be in AX(32-bit) or AL(16-bit).

Base Register(BX)

Base Register is the register, hold the address of the base storage location from where the data were stored continuously. Base register value is used to find the data that is required.

Count Register(CX)

Count register is preferred to use as a loop counter. i.e. while shifting and rotating bits CX is used as counter.

Data Register(DX)

The data register is used in I/O operations as well as preferred in division and multiplication while execution of large values.(DX and DL)

Address Registers

Address registers typically store the memory address from where data will be fetched into CPU or address to which data will be sent or stored. Address registers are further divided into three parts:

Segment Registers

To understand the use of segment registers you have to understand the logic of memory segmentation. In 8086 we have an address of size 20-bits whereas the size of the processor is 16-bit, so we need to divide the address into segments. We divide it into the segment and offset address and by the combination of both we get the actual address. Here comes the use of segment registers which are:

Code Segment(CS)

As in code segment, we write the instructions that need to be executed. So Code Segment(CS) register contain all the instruction that are to be executed and also has the starting address of code segment.

Data Segment(DS)

It stores the starting address of data segment as well as the complete data.

Stack Segment(SS)

There is a data structure called stack used by the processor to implement the subroutine calls. The SS register store the address of subroutine or procedure.

Extra Segment(ES, FS, GS)

If a program needs to access second data segment, it can use the extra segment register.

Pointer Registers

Pointer registers of 32-bit are ESP, EBP, EIP whereas the 16-bit pointer registers are as SP, BP, IP. These registers point to the memory location, but they can also be used in arithmetic and other registers, unlike segment registers.

Stack Pointer(SP)

The stack pointer is used in combination with stack segment(SS) as SS: SP for accessing the stack segment. It contains the top address of the stack.

Base Pointer(BP)

Unlike stack pointer, the base pointer contains the base address of the stack. It is used to access the data on a stack. It is combined with stack segment (SS:BP).

Instruction Pointer(IP)

Sometimes called as index pointer store the offset address of next instruction to be executed. It is combined with code segment (CS:IP).

Index Registers

32-bit index registers are ESI and EDI whereas the 16-bit rightmost are  SI and DI. They are mentioned below:

Source Index(SI)

The SI 1source index) register is used to point to memory locations in the data segment addressed by OS. By incrementing the contents of SI, we can eaSily access Consecutive memory locations. I

Destination Index(DI)

The DI (destination Index) register performs the same functions as SI. There is a class of instructions, called string operations, that use DI to access memory locations addressed by ES.

Status Registers

Status registers are called as flags which represent the state of a processor. It is done by setting the bits called flags.

There are two types of flags described below:

Status Flags

The status flags are used by the processor to reflect the result of an operation. I.e. let an instruction SUB AX, AX has executed the zero flag become 1 which return zero results. Status flags are discussed below:

Status Flags Table

NAME SYMBOL BIT
Carry Flag CF 0
Parity Flag PF 2
Auxiliary Carry Flag AF 4
Zero Flag ZF 6
Sign Flag SF 7
Overflow Flag OF 11

Carry Flag(CF)

On addition if there is a carry-out from the most significant bit or there is a borrow into msb on subtraction then carry flag will be:

CF=1

Otherwise:

CF=0

Parity Flag(PF)

If low Bytes of result has an even number of one, then Parity flag is:

PF=1

If low bytes has an odd number of one then parity flag is:

PF=0

For Example: If a result of a addition in 10101000, it ha 3 one bits, so parity flag is 0.

Auxiliary Carry Flag(AF)

If there is carry out from bit number 3 on addition or carry into bit number three then the value of Auxiliary Carry flag is:

AF=1

An auxiliary flag is used in binary coded decimal.

Zero Flag(ZF)

If a result is zero then zero flag is:

ZF=1

and if a result is non-zer0 then zero flag is:

ZF=0

Sign Flag(SF)

If the most significant bit of a result is 1, it means its a negative value so then sign flag will be:

SF=1

If MSB is zero then the value of sign flag will be:

SF=0

Overflow Flag(OF)

If signed overflow is occurred then the value of overflow flag is:

OF=1

otherwise it will be:

OF=0

Control Flags

There are three main control flags. See table below:

Control Flags Table

NAME SYMBOL BIT
Trap Flag TF 8
Interrupt Flag IF 9
Direction Flag DF 10

Trap Flag(TF)

It allows setting the operation of the processor in single-step mode. The DEBUG program we used sets the trap flag, so we could step through the execution one instruction at a time.

Interrupt Flag(IF)

If decides whether the external interrupts are to be ignored or processed. It disables the external interrupt when the value is 0 and enables interrupts when the value is 1.

Direction Flag(DF)

It 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.

 

This was all about x86 assembly registers if you have any problems regarding registers you can freely ask in the comment box.

Nauman Rehmat
 

Nauman Rehmat is the owner of Assembly Language Tuts.He is interested in Programming and SEO. He is also pursuing a degree in Computer Software Engineering from Comsats.