NASA

A Handbook for Assembly | Chapter 4: General-Purpose Registers



Chapter 4: General-Purpose Registers


### 4.1 Introduction


General-purpose registers are crucial components in assembly language programming, serving as temporary storage for data and operands during program execution. This chapter explores the architecture of general-purpose registers, their naming conventions, and their role in various operations.


### 4.2 Register Architecture


#### 4.2.1 x86 Architecture


- **Registers:**

  - Small, fast storage locations within the CPU.

  - Perform arithmetic and logical operations.


#### 4.2.2 Common x86 Registers


- **EAX, EBX, ECX, EDX:**

  - General-purpose data registers.

  - Used for arithmetic and data manipulation.


- **ESP (Stack Pointer):**

  - Points to the top of the stack.


- **EBP (Base Pointer):**

  - Used for referencing parameters and local variables on the stack.


- **ESI, EDI:**

  - Source and destination indexes for string operations.


### 4.3 Register Naming Conventions


#### 4.3.1 Naming Scheme


- **E Prefix:**

  - Extended registers (32 bits).


- **R Prefix:**

  - 64-bit registers (e.g., RAX).


#### 4.3.2 Register Usage


- **EAX (RAX):**

  - Accumulator register.

  - Used in arithmetic and data manipulation.


- **EBX (RBX):**

  - Base register.

  - Used as a pointer to data in the data segment.


- **ECX (RCX):**

  - Counter register.

  - Used in loop control and string manipulation.


- **EDX (RDX):**

  - Data register.

  - Used in arithmetic operations and I/O.


### 4.4 Register States


#### 4.4.1 User and System States


- **User State:**

  - Maintained during user-level program execution.


- **System State:**

  - Maintained during system-level operations and interrupts.


### 4.5 Register Operations


#### 4.5.1 Moving Data


- **MOV Instruction:**

  - Transfers data between registers and memory.


- **Example:**

  ```assembly

  mov eax, ebx   ; Move the value in register ebx to register eax

  ```


#### 4.5.2 Arithmetic Operations


- **ADD, SUB, MUL, DIV:**

  - Perform addition, subtraction, multiplication, and division.


- **Example:**

  ```assembly

  add eax, 5     ; Add 5 to the value in register eax

  ```


#### 4.5.3 Logical Operations


- **AND, OR, XOR, NOT:**

  - Perform bitwise logical operations.


- **Example:**

  ```assembly

  and eax, ebx   ; Bitwise AND of registers eax and ebx

  ```


### 4.6 Flags Register


- **Flags Register:**

  - Stores information about the state of the processor.

  - Flags include zero, carry, overflow, and more.


### 4.7 Conclusion


General-purpose registers are essential components in x86 architecture, providing temporary storage for data during program execution. Understanding their naming conventions, usage, and the operations they support is fundamental to effective assembly language programming.


Comments

Houston We Have a Podcast

Translate