NASA

A Handbook for Assembly | Chapter 4: Indirect Addressing



 

Chapter 4: Indirect Addressing


### 4.1 Introduction


Indirect addressing is a powerful addressing mode in assembly language that allows the manipulation of data indirectly through a memory location specified by a register or another memory location. This chapter explores the concept of indirect addressing, its syntax, and its applications in data manipulation.


### 4.2 Understanding Indirect Addressing


#### 4.2.1 Definition


- **Indirect Addressing:**

  - Operand is not directly specified; instead, a register or memory location holds the address of the data.


#### 4.2.2 Memory Access


- **Accessing Data:**

  - Retrieves data from the memory location whose address is stored in a register or another memory location.


#### 4.2.3 Syntax


- **Example:**

  ```assembly

  mov eax, [ebx]   ; Move the value stored at the memory location pointed to by register ebx into register eax

  ```


### 4.3 Use Cases


#### 4.3.1 Dynamic Memory Access


- **Example:**

  ```assembly

  mov esi, [memory_ptr]   ; Move the value stored at the memory location pointed to by memory_ptr into register esi

  ```


#### 4.3.2 Array Access through Index


- **Example:**

  ```assembly

  mov ecx, [base_array + 4*index]   ; Move the value at the memory location (base_array + 4*index) into register ecx

  ```


#### 4.3.3 Pointers and Linked Structures


- **Example:**

  ```assembly

  mov edx, [node_ptr + offset]   ; Move the value at the memory location (node_ptr + offset) into register edx

  ```


### 4.4 Modifying Data in Memory


#### 4.4.1 Updating Values


- **Example:**

  ```assembly

  inc dword [ebx]   ; Increment the value stored at the memory location pointed to by register ebx

  ```


#### 4.4.2 Writing to Memory


- **Example:**

  ```assembly

  mov [memory_ptr], eax   ; Move the value in register eax to the memory location pointed to by memory_ptr

  ```


### 4.5 Address Calculations


#### 4.5.1 Effective Address


- **Calculation:**

  - The effective address is determined by the value in the register or memory location used for indirect addressing.


#### 4.5.2 Example


- **Example:**

  ```assembly

  mov esi, [base_register + 2*index]   ; Calculate the effective address (base_register + 2*index) and move its value to esi

  ```


### 4.6 Conclusion


Indirect addressing provides flexibility in accessing and manipulating data in memory. By allowing the use of registers or memory locations to dynamically determine the address, it enables more dynamic and efficient programming. Understanding how to use indirect addressing is crucial for advanced assembly language programming.


Comments

Houston We Have a Podcast

Translate