In this lesson, you will learn how the CPU identifies the location of data operands using different addressing modes to optimize memory access.
When an instruction tells the CPU to "add," it needs to know where the numbers are. Addressing modes are the specific rules that define how the CPU calculates the effective address of an operand. Choosing the right mode helps us balance instruction size, execution speed, and hardware simplicity.
1. Immediate Addressing
In immediate addressing, the value to be used is literally embedded inside the instruction itself. Because the data is right there in the instruction stream, the CPU doesn’t need to perform a memory access.
- Example:
ADD R1, #10 - Use case: Useful for constants or loop counters.
2. Register Addressing
Here, the operand is stored in one of the CPU's internal registers. This is the fastest way to access data because it bypasses the memory hierarchy entirely, avoiding the "Memory Wall" issues we’ve discussed previously.
- Example:
ADD R1, R2 - Use case: Excellent for high-speed arithmetic involving frequently used variables.
3. Direct Addressing
In direct addressing, the instruction contains the absolute memory address where the data resides. The CPU must use this address to fetch the value from the data cache or main memory.
- Example:
LOAD R1, [1000] - Use case: Accessing global variables that have a fixed location in memory.
Why does this matter?
Think of these modes as different ways to retrieve an item from a warehouse. Immediate is like having the item in your hand; Register is like having it in your pocket; Direct is like walking to a specific, labeled shelf in the back.
In a RISC architecture, we prefer simplicity, often keeping most operations focused on registers to minimize memory latency. Conversely, CISC designs might offer more complex modes to reduce the number of total instructions required, though this often increases the complexity of the instruction decoding hardware. By selecting the most efficient mode for your task, you minimize the number of memory transactions and improve overall execution throughput.
Key Takeaway: Addressing modes define the bridge between the instruction and its data; choosing the right one optimizes speed by minimizing memory accesses and simplifying hardware decoding.