Assembly Registers
## Assembly Language - Registers
Registers (Register) are high-speed storage units inside the CPU, and are the most frequently operated objects in assembly programming. Understanding registers is the key first step to learning assembly language.
* * *
## What are Registers
Registers are ultra-high-speed small memory units integrated inside the CPU chip, used to temporarily store instructions, data, and addresses.
Unlike memory, registers are embedded inside the CPU. Accessing registers takes almost zero delay, while accessing memory requires dozens to hundreds of clock cycles.
In assembly language, most operations revolve around registers β data is loaded from memory into registers, calculations are performed in registers, and results are stored back to memory.
> You can think of registers as the CPU's "workbench". Tools on the workbench are available at any time, while memory is like a warehouse where you need to walk to fetch and store items.
* * *
## x86 32-bit Register Classification
The x86 32-bit architecture provides various types of registers, each with different purposes. The following image shows the complete register classification:

Each category of registers is described in detail below:
* * *
## General Purpose Registers
General Purpose Registers are the most commonly used registers for storing operational data and temporary results.
x86 provides 8 32-bit general purpose registers:
| 32-bit | 16-bit | Low 8-bit | High 8-bit (of low 16-bit) | Main Purpose |
| --- | --- | --- | --- | --- |
| EAX | AX | AL | AH | Accumulator, stores function return values and arithmetic operation results |
| EBX | BX | BL | BH | Base register, often used to store memory base address |
| ECX | CX | CL | CH | Counter, often used for loop counting and shifting |
| EDX | DX | DL | DH | Data register, stores high-order results of multiplication/division |
| ESI | SI | SIL | - | Source index register, source address for string operations |
| EDI | DI | DIL | - | Destination index register, destination address for string operations |
| EBP | BP | BPL | - | Base pointer, points to the bottom of the current stack frame |
| ESP | SP | SPL | - | Stack pointer, always points to the top of the stack |
Naming convention: The E prefix stands for Extended (extended to 32-bit), and the X suffix indicates it can be split into high and low bytes.
## Example
; File path: register_parts.asm
; Demonstrates accessing different parts of registers
section.text
global _start
_start:
mov eax,0x12345678; Full 32-bit register
; At this point: EAX = 0x12345678
; AX = 0x5678 (low 16 bits)
; AH = 0x56 (high 8 bits, high 8 bits of AX)
; AL = 0x78 (low 8 bits)
mov ax,0xAABB; Modify AX (low 16 bits)
; At this point: EAX = 0x1234AABB (high 16 bits unchanged!)
; AX = 0xAABB
; AL = 0xBB
mov al,0xCC; Modify AL (lowest 8 bits)
; At this point: EAX = 0x1234AACC (only low 8 bits changed)
; AX = 0xAACC
; AL = 0xCC
mov eax,1
mov ebx,0
int 0x80
> When modifying the low 16 bits of a 32-bit register (such as AX), the high 16 bits remain unchanged. However, when using a 32-bit register as the destination operand, it will overwrite the entire 32 bits. This is a common mistake for beginners.
* * *
## Segment Registers
Segment registers are used to specify the currently used memory segment:
| Register | Name | Purpose |
| --- | --- | --- |
| CS | Code Segment Register | Points to the segment where the current instruction is located |
| DS | Data Segment Register | Points to the segment where data is located |
| SS | Stack Segment Register | Points to the segment where the stack is located |
| ES | Extra Segment Register | Additional data segment |
| FS | Extra Segment Register | General purpose, often used for thread-local storage |
| GS | Extra Segment Register | General purpose, often used for thread-local storage |
When programming in 32-bit protected mode, the operating system has already set up the segment registers, so you usually don't need to modify them manually.
* * *
## Pointer and Index Registers
These registers are mainly used for accessing memory, storing memory addresses:
| Register | Full Name | Purpose |
| --- | --- | --- |
| EIP | Instruction Pointer | Points to the address of the next instruction the CPU will execute (cannot be accessed directly) |
| ESP | Stack Pointer | Points to the top of the stack, PUSH/POP instructions automatically adjust it |
| EBP | Base Pointer | Points to the bottom of the current function's stack frame, used to access function parameters and local variables |
| ESI | Source Index | Source address for string/memory operations |
| EDI | Destination Index | Destination address for string/memory operations |
> ESP and EBP cannot be used
YouTip