0% found this document useful (0 votes)
12 views26 pages

Lecture 9a - Addressing Modes

The document discusses various addressing modes in computer architecture, which determine how a computer locates data needed for instruction execution. It outlines different types of addressing modes, including immediate, direct, indirect, register, register indirect, displacement (indexed), relative, and stack addressing, along with their algorithms, advantages, and disadvantages. The information serves as a guide for understanding how data is accessed and manipulated within a computer system.

Uploaded by

aidaraihanah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views26 pages

Lecture 9a - Addressing Modes

The document discusses various addressing modes in computer architecture, which determine how a computer locates data needed for instruction execution. It outlines different types of addressing modes, including immediate, direct, indirect, register, register indirect, displacement (indexed), relative, and stack addressing, along with their algorithms, advantages, and disadvantages. The information serves as a guide for understanding how data is accessed and manipulated within a computer system.

Uploaded by

aidaraihanah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

5604TECYPC

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

👉 How Does It Work?


• Each instruction contains an operation field (what to do) and an
address field (where to find data).
• The Program Counter (PC) keeps track of which instruction to
execute next.
• Every time an instruction is fetched, the PC moves to the next
instruction automatically.
Mode Field
● The mode field in an instruction tells the CPU where to find the
data (operands) needed for an operation.

● Opcode (operation code): what operation the CPU should perform


● Mode (addressing mode): where to find the operand (data)
● Address (memory or register reference): where to get the data
from

● Example: ADD | Direct | 2000


Types of Addressing Mode
Indir Regis Register
ect ter Indirect
Operand address Operand is Register holds memory address of
points to another inside the CPU operand
address register

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

✔ Operand (data) is inside the instruction.


✔ No need to fetch from memory—fast execution.
❌ Limited to small values since the instruction has a fixed size.
Immediate Addressing
● Instruction: ADD 5
● The ADD instruction takes a value (operand) and adds it to the
current value stored in a register (usually the accumulator in
basic processors).
● The result is stored back in the register.
Direct Addressing
● Algorithm: EA = A
● Effective Address (EA) = address field of operand

✔ 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)

✔ Supports larger memory space (useful when memory locations change


dynamically).
✔ Enables flexible programming (pointers, dynamic data structures).
❌ Slower execution (multiple memory accesses).
❌ More complex than direct addressing.
Indirect Addressing
● Instruction: ADD (A)
● Look in memory at address A.
● The value at A contains another memory address (pointer).
● Go to that new address and retrieve the actual operand.
● Perform the addition.
Register Addressing
● Algorithm: EA = R

✔ Fastest method (no memory access).


✔ Efficient for small, frequently used data (loop counters, variables).
✔ Shorter instructions (saves space in code).
❌ Limited storage (only a few registers available).
❌ Requires smart programming (compiler/assembly must manage registers well).
Register Addressing
● Instruction: ADD R1
● Look inside register R1
(instead of searching in
memory).
● Take the value from R1 and
add it to the accumulator.
Register Indirect Addressing

● Algorithm: EA = EA = (R)

✔ Uses registers to store memory addresses, making access faster.


✔ More flexible than Direct Addressing (dynamic memory access).
✔ Better than Indirect Addressing because it requires fewer memory accesses.
❌ Slightly more complex than simple register addressing.
Register Indirect Addressing
● Instruction: ADD (R1)
● The register R1 holds a
memory address (not the
actual data).
● The CPU looks inside R1 to
find the memory address.
● The CPU fetches the operand
from that memory location
and processes it.
Displacement (Indexed) Addressing
● Algorithm: EA = A + (R)
● A = Base Address
● R = Displacement

✔ Perfect for handling arrays & tables efficiently.


✔ Uses a base address & dynamic offset for flexible memory access.
✔ Common in loops, relative addressing, and indexing.
❌ Slightly more complex than direct addressing.
Displacement (Indexed) Addressing
● Instruction: LOAD A, (R1)
● A (Base Address) is a fixed starting point.
● R1 (Displacement) changes dynamically to access different
locations.
● The CPU calculates EA = A + R1 to find the operand.
Relative Addressing
● Algorithm: EA = PC + A

✔ Ideal for program jumps, loops, and branch instructions.


✔ More flexible than direct addressing (no fixed memory locations).
✔ Improves efficiency using locality of reference.
❌ Requires extra calculation (PC + Offset).
Relative Addressing
● Instruction: LOAD A, (PC)
● A (Offset/Displacement) tells how far to move from the current
instruction.
● PC (Program Counter) holds the address of the current
instruction.
● The CPU calculates EA = PC + A to find the operand.
Stack Addressing

Algorithm: EA = top of stack

✔ 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

Immediate Operand = A No memory access (fast) Limited operand range

Direct EA = A Simple and easy to use Limited address space

Indirect EA = (A) Large address space Slower (multiple memory accesses)

Register EA = R Very fast, no memory access Limited number of registers

Register Indirect EA = EA = (R) Faster than indirect addressing Requires registers

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/

You might also like