Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 103 of 9362. Instruction Set Architecture and CPU MicroarchitectureFree lesson

Utilizing Indirect and Indexed Addressing Techniques

Implement advanced addressing modes to support complex data structures like arrays and pointers during the instruction execution cycle.

In this lesson, you will learn how to access complex data structures like arrays and pointers by using indirect and indexed addressing modes to calculate memory addresses dynamically.

Up until now, you have mostly used direct addressing, where the instruction contains the exact memory address of the data. However, in real-world programs, we rarely know exactly where a piece of data lives before the program runs. For example, if you are processing a list of sensor readings (an array), you don't want a separate instruction for every single entry. Instead, you want to point to the start of the list and move through it.

Indexed Addressing

Indexed addressing allows us to calculate an address by adding a constant offset to the value stored in a register (often called an index register). Think of it like this: Address = Base_Address + Index.

If the base address of your sensor array is 0x2000 and your index register holds 4, the CPU automatically computes the effective address as 0x2004. This is incredibly efficient for looping through data:

; Load data from array[i] into R1
; R2 holds the current index 'i'
LOAD R1, [Base_Array_Address + R2] 

Indirect Addressing

While indexed addressing helps us navigate collections, indirect addressing helps us handle pointers. In indirect addressing, the instruction does not contain the data's address; instead, it contains the address of a register (or a memory location) that holds the address of the data.

Think of it as a "pointer to a pointer" or a "treasure map." The instruction tells the CPU: "Go to this register to find the map, and the map will tell you where the treasure (data) is actually hidden."

; R3 contains the memory address of a variable
; Indirectly load the value stored at that address into R1
LOAD R1, [R3] 

By combining these modes, the CPU can traverse complex data structures like linked lists or multidimensional arrays without the programmer having to hard-code every memory location, drastically reducing the number of instructions needed to manage dynamic memory.

Key Takeaway: Indexed addressing uses an offset from a base to traverse arrays, while indirect addressing uses a register as a pointer to find data, both allowing the CPU to handle dynamic memory locations efficiently.