In this lesson, you will learn how the CPU identifies the exact location of data in memory using direct and indirect addressing techniques.
Direct Addressing (Absolute Pointers)
In direct addressing, the instruction itself contains the exact memory address where the data resides. Think of this like a house number written on an envelope; the postman (the CPU) knows exactly where to go because the destination is specified explicitly in the instruction.
If we want to load the value at memory address 0x2000 into a register, our instruction looks like this:
LOAD R1, [0x2000]
Here, 0x2000 is the "absolute" destination. The CPU does not need to perform extra calculations; it simply reaches into that specific slot in the memory array.
Indirect Addressing (Pointer Dereferencing)
Indirect addressing adds a layer of abstraction. Instead of the instruction containing the data's address, it contains the address of a memory location that holds the address of the data. This is the hardware equivalent of a treasure hunt: you open a box, and instead of finding the gold, you find a note telling you which box the gold is actually in.
If register R2 holds the value 0x2000, and we want to access the data at the address stored in R2, we use indirect addressing:
LOAD R1, [R2]
The CPU first checks R2, sees 0x2000, then performs a second memory access to reach 0x2000 to fetch the final value. This is powerful because we can change the value of R2 during program execution to point to different data arrays without rewriting the instruction code.
Calculating the Effective Address
The "Effective Address" (EA) is the final memory location the CPU settles on.
- Direct: EA =
Instruction Address Field - Indirect: EA =
Memory[Instruction Register Field]
By mastering these modes, you gain the ability to manipulate data structures like arrays and linked lists, as indirect addressing allows you to iterate through memory by simply incrementing the pointer stored in your register.
Key Takeaway: Direct addressing provides the location directly in the instruction, while indirect addressing uses a pointer to "look up" the location, allowing for dynamic data access.