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|
Now we gonna explain these registers step by step:
- 1 Data Registers In x86 Assembly
- 2 Address Registers
- 3 Status Registers
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 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 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 is preferred to use as a loop counter. i.e. while shifting and rotating bits CX is used as counter.
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 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:
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:
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.
It stores the starting address of data segment as well as the complete data.
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 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.
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.
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).
Sometimes called as index pointer store the offset address of next instruction to be executed. It is combined with code segment (CS:IP).
32-bit index registers are ESI and EDI whereas the 16-bit rightmost are SI and DI. They are mentioned below:
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
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 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:
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
|Auxiliary Carry Flag||AF||4|
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:
If low Bytes of result has an even number of one, then Parity flag is:
If low bytes has an odd number of one then parity flag is:
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:
An auxiliary flag is used in binary coded decimal.
If a result is zero then zero flag is:
and if a result is non-zer0 then zero flag is:
If the most significant bit of a result is 1, it means its a negative value so then sign flag will be:
If MSB is zero then the value of sign flag will be:
If signed overflow is occurred then the value of overflow flag is:
otherwise it will be:
There are three main control flags. See table below:
Control Flags Table
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.
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.
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.