Submitted By: Faiza Naseem 22-Arid-4359
Submitted To: Mam Aleeza Falak
Assignment No: 01
Date: 20/05/2024
Topic : Memory Addressing Modes
What are Memory Addressing modes?
Memory addressing modes are methods used by a computer's CPU to access data stored in memory.
These modes define how the processor should interpret the data in instruction operands to access the
correct memory location. Different addressing modes provide flexibility and efficiency in accessing data,
which is crucial for optimizing program execution.
Available addressing modes depend on the address size used
16-bit modes
1. Same as those supported by 8086
32-bit modes
1. Supported by Pentium
2. More flexible set
Reason for using Memory Addressing Modes
To efficiently support high-level language constructs and data structures.
Roles of Memory Addressing Modes
Flexibility: Addressing modes allow for a variety of ways to access memory, making it easier to
write complex programs.
Efficiency: They help optimize memory access patterns, which can enhance the speed and
performance of a program.
Code Density: Different modes can help reduce the number of instructions required for certain
operations, leading to more compact code.
Ease of Use: Provide higher-level abstraction for programmers, simplifying the process of
accessing complex data structures.
Types of Memory Addressing Modes
Direct Addressing
In this addressing mode the effective address of data is the part of instruction.
Role: Provides a straightforward way to access specific memory locations.
Characteristics:
1. The address of the operand is explicitly stated in the instruction.
2. Simplifies code readability and understanding.
Usage:
1. Accessing static or global variables with known addresses.
2. Implementing simple programs with fixed memory layouts.
Impact:
1. Fast access due to no address computation.
2. Limited addressable range constrained by the instruction's address field
Scenario: Summing Different Types of Marks Using Direct Addressing
total_marks = assign_marks + test_marks + exam_marks
Translated into
mov EAX,[assign_marks]
add EAX,[test_marks]
add EAX,[exam_marks]
mov total_marks,[EAX]
Indirect Addressing Modes
This is the mode of addressing where the instruction contain the address of the location where the target
address is stored. So, in this way it is indirectly storing the address of the target location in another
memory location.
Role: Allows dynamic determination of operand addresses, providing flexibility for complex data
structures.
Characteristics:
The instruction specifies a memory location that contains the effective address of the operand.
Adds a level of indirection, requiring additional memory access.
Usage: Accessing elements of arrays or data structures where addresses may change during execution.
Implementing pointers and dynamic data structures.
Impact:
1. Greater flexibility and dynamic data handling.
2. Slower execution due to additional memory fetches. of indirection, requiring additional memory
access.
Scenario: Summing Different Types of Marks Using Indirect Addressing
Let's consider a real-life example where we need to calculate the total marks for a student by summing
assignment marks, test marks, and exam marks. We'll use indirect addressing to achieve this, assuming
the marks are stored in memory.
Variables:
1. Assign_marks at memory address 1000
2. Test_marks at memory address 1004
3. Exam_marks at memory address 1008
4. Total_marks to be stored at memory address 1012
Registers Used:
1. R1: Pointer to Assign_marks
2. R2: Pointer to Test_marks
3. R3: Pointer to Exam_marks
4. R4: Pointer to Total_marks
5. R5: Temporary register for storing values
Register Indirect Addressing
In register indirect addressing mode, the address of the operand is placed in any one of the registers. The
instruction specifies a register that contains the address of the operand. In this addressing the operand’s
offset is placed in any one of the registers BX,BP,SI,DI as specified in the instruction. The effective
address of the data is in the base register or an index register that is specified by the instruction.
Role: Provides efficient and flexible access to operands using registers to hold memory addresses.
Characteristics:
1. The effective address of the operand is contained in a register.
2. Combines the flexibility of indirect addressing with faster register access.
Usage:
1. Iterating over arrays or accessing data structures efficiently.
2. Implementing dynamic data access with low overhead.
Impact:
1. Faster than memory-based indirect addressing.
2. Highly flexible and suitable for dynamic data access.