Lecture 9a - Addressing Modes
Lecture 9a - Addressing Modes
Computer Architecture
Lecture 9a
Addressing Modes
Prepared by: Aida Raihanah
Addressing Mode
👉 What is an Addressing Mode?
It determines how and where a computer finds the data
(operands) needed to execute an instruction.
👉 Why is it used?
• As a pointer to memory
• As counters for loop controls
• Indexing of a data
• Program relocation
• To reduce the number of bits in the addressing field of the
instruction
Addressing Mode
Displacem
Direc
ent
t
Operand address (Indexed)
Used for accessing arrays
is directly given
Relati
ve
Immed Used for
branching and
iate loops
Operand is inside
the instruction Stack
Operand is on
the top of the
stack
Immediate Addressing
● Algorithm: Operand = A
✔ Simple & Fast: The memory address is given directly in the instruction.
✔ Single Memory Access: Only one step to fetch the operand.
❌ Limited Address Space: If the memory address field is small, it can only access limited
locations.
Direct Addressing
● Instruction: ADD A
● The instruction contains address A.
The CPU goes directly to memory address A.
The value stored at A is fetched and added to the accumulator.
Indirect Addressing
● Algorithm: EA = (A)
● Algorithm: EA = EA = (R)
✔ Uses LIFO (Last In, First Out) – Always takes the most recent value.
✔ Perfect for function calls, recursion, and temporary data storage.
✔ No need to specify memory addresses—data is managed automatically.
❌ Access is restricted to the top of the stack (no random access).
Stack Addressing
1️⃣Read the expression from left to right.
Each number or operator is processed in order.
2️⃣Push numbers onto the stack.
If the symbol is a number, push it onto the
stack.
3️⃣When an operator is encountered:
Pop the top two values from the stack.
Apply the operator (e.g., addition, subtraction,
multiplication, or division).
Push the result back onto the stack.
4️⃣Repeat until the expression is fully
processed.
Keep performing operations as operators
appear.
5️⃣Final Result:
The last remaining value on the stack is the final
Stack Addressing (Exercise 1)
Stack Addressing (Exercise 2)
Stack Addressing (Exercise 3)
Summary of Addressing Modes
Addressing Mode Algorithms Key Advantage Key Disadvantage
Displacement EA = A + (R) Good for arrays and loops Extra calculation needed
(Indexed)
Relative EA = PC + A Useful for position-independent code Limited range
Stack EA = top of stack Efficient for expression evaluation Stack management overhead
QUIZ
https://kahoot.it/