COMPUTER ORGANIZATION AND
ASSEMBLY LANGUAGE
LAB MANUAL 9
Lab Title:
• Assembly Language Programming Addressing Modes
DEPARTMENT OF COMPUTING
1
© Copy Rights, Department of Computer Science, STMU Islamabad
All Rights Reserved
Prepared By: Mr. Shahid Raza
Revised By. Engr. Muhammad Haris Farooq
DEPARTMENT OF COMPUTING
List of Experiments
• Register Operand
• Immediate data operand
• Memory operand Addressing Mode
159
Addressing Modes in Assembly Language
Addressing modes specify the way in which the operand of an instruction is accessed. In x86 assembly
language, there are several addressing modes, each with its syntax and usage. Assembly language
programming addressing modes are mechanisms that define how a computer processor accesses
operands or data during the execution of instructions. These modes determine the way instructions
specify the location of data to be manipulated or processed.
Register Operand Addressing Mode:
Directly operates on data stored in registers, which are fast-access storage locations within the
CPU.
Syntax:
MOV destination_register, source_register
Instruction Format:
MOV AX, BX
Moves the contents of register BX into register AX.
Immediate Data Operand Addressing Mode:
Loads immediate constant values directly into registers or memory locations.
Syntax:
MOV destination_register, immediate_data
Instruction Format:
MOV AX, 1234H
Loads the immediate hexadecimal value 1234H into register AX.
Memory Operand Addressing Mode:
Accesses data stored in memory locations directly.
160
Syntax:
MOV destination_register, [memory_address]
MOV [memory_address], source_register
Instruction Format:
MOV AX, [1234H]
Moves the contents of memory location 1234H into register AX.
Direct Memory Operand Addressing Mode:
Directly accesses memory locations specified by a constant address.
Syntax:
MOV destination_register, [memory_address]
MOV [memory_address], source_register
Instruction Format:
MOV AX, [5678H]
Indirect Register Operand Addressing Mode:
Uses the value in a register as a pointer to access memory indirectly.
Syntax:
MOV destination_register, [register]
MOV [register], source_register
Instruction Format:
MOV AX, [BX]
Moves the contents of the memory location pointed to by register BX into
register AX
161
Based Memory Operand Addressing Mode:
Combines a base register and a displacement to access memory locations.
Syntax:
MOV destination_register, [base_register + displacement]
MOV [base_register + displacement], source_register
Instruction Format:
MOV AX, [BX + 10]
Moves the contents of memory location BX + 10 into register AX.
Index Memory Operand Addressing Mode:
Uses an index register to dynamically access elements of arrays or structures.
Syntax:
MOV destination_register, [base_register + index_register]
MOV [base_register + index_register], source_register
Instruction Format:
MOV AX, [BX + SI]
Moves the contents of memory location BX + SI into register AX.
Base Indexed Memory Operand Addressing Mode:
In this Addressing Mode Combines both base and index registers with a displacement to
access memory, providing flexibility for data structures.
Syntax:
MOV destination_register, [base_register + index_register + displacement]
MOV [base_register + index_register + displacement], source_register
162
Instruction Format:
MOV AX, [BX + SI + 10]
Moves the contents of memory location BX + SI + 10 into register AX.
Advantages of Addressing Modes:
Flexibility:
Addressing modes offer flexibility in how operands are accessed and manipulated,
allowing programmers to write efficient and concise code.
Efficiency:
Different addressing modes optimize memory access and utilization, which can
significantly impact the performance of programs, especially in terms of speed and
resource usage.
Direct Control:
They provide direct control over how data is fetched, stored, or manipulated, enabling
programmers to work closely with hardware capabilities.
163
Lab Activities:
1. Write an assembly program to swap the contents of registers AX and
BX.(Register Operand Addressing Mode).
MOV AX, 1234H ; Sample data in AX
MOV BX, 5678H ; Sample data in BX
MOV CX, AX ; Move contents of AX to
CX MOV AX, BX ; Move contents of BX to
AX
MOV BX, CX ; Move contents of CX (originally AX) to BX
2. Write an assembly program to load the immediate value 25 into register
AX. (Immediate Data Operand Addressing Mode).
MOV AX, 25 ; Load immediate value 25 into AX
; AX now contains the value 25
3. Write an assembly program to copy the contents of memory location 2000H to
register AX (Memory Operand Addressing Mode).
MOV AX, [2000H] ; Copy contents of memory location 2000H into AX
; Assumes 2000H holds a data value that fits into AX
4. Write an assembly program to store the value in register AX into memory
location 3000H (Direct Memory Operand Addressing Mode).
MOV [3000H], AX ; Store contents of AX into memory location 3000H
; AX's contents are now stored at memory location 3000H
5. Write an assembly program to multiply the contents of memory location
pointed to by register BX by 2 and store the result in register AX(Indirect
Register Operand Addressing Mode).
MOV BX, 4000H ; Assume BX holds memory address 4000H
MOV AX, [BX] ; Load contents of memory location pointed to by BX into AX
ADD AX, AX ; Multiply AX by 2 (equivalent to AX = AX * 2)
164
; AX now holds the result of doubling the value at memory location 4000H
6. Write an assembly program to add the contents of memory location
5000H to register AX and store the result back in memory location 5000H
(Based Memory Operand Addressing Mode).
MOV AX, [5000H] ; Load contents of memory location 5000H into AX
ADD AX, AX ; Double the value in AX
MOV [5000H], AX ; Store the result back into memory location 5000H
; Contents of memory location 5000H are now doubled
7. Write an assembly program to sum the contents of an array located at
memory address 6000H with 10 elements, using register BX as the base
index and SI as the loop counter (Index Memory Operand Addressing
Mode).
MOV BX, 6000H ; Base address of the array
MOV SI, 0 ; Initialize SI as the loop counter
MOV CX, 10 ; Number of elements in the array
MOV AX, 0 ; Initialize AX to store the sum
sum_loop:
ADD AX, [BX + SI] ; Add the value of array element to
AX INC SI ; Move to the next element
LOOP sum_loop ; Repeat for all elements
8. Write an assembly program to copy an array located at memory address
7000H to another array located at memory address 8000H, using BX as
the base index for both arrays and DI as the loop counter(Base Indexed
Memory Operand Addressing Mode).
MOV BX, 7000H ; Base address of the source array
MOV DI, 8000H ; Base address of the destination array
MOV CX, 10 ; Number of elements in the array
copy_loop:
MOV AX, [BX + DI] ; Load an element from source array
165
MOV [DI + DI], AX ; Store it in the destination array
INC DI ; Move to the next element
LOOP copy_loop ; Repeat for all elements
; After execution, the array at 8000H will be a copy of the array at 7000H
166
Lab Exercise and Summary:
Summary should cover Introduction, Procedure, Data Analysis and Evaluation.
167
Student’s Name: Date:
168
Evaluation Criteria
Method of Evaluation: Viva, Practical Quiz
Excellent Good Satisfactory Unsatisfactory Poor Marks
Obtained
10 9-7 6-4 3-1 0
Assignment All tasks Most tasks Some tasks Most tasks All tasks were
completed were were were incomplete or
correctly in completed completed incomplete or incorrect.
given time correctly. correctly and incorrect and
and have a Tasks could have an have no Didn’t
complete be improved incomplete understanding perform tasks
understanding further and understanding and have no
have a understanding
complete
understanding
Total
References:
1. https://amritoo.hashnode.dev/a-beginners-guide-to-assembly-language-using-emu8086
2. https://github.com/amritoo/assembly-codes/blob/main/variable_and_io.asm
3. https://www.eng.auburn.edu/~sylee/ee2220/8086_instruction_set.html
4. https://www.eng.auburn.edu/~sylee/ee2220/8086_instruction_set.html#SBB
169