0% found this document useful (0 votes)
7 views7 pages

3 Addressing Modes

Uploaded by

kimdrew715
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)
7 views7 pages

3 Addressing Modes

Uploaded by

kimdrew715
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/ 7

SCS3202

Assembly language
programming
Addressing modes
 Most assembly instruction require to use input values/ arguments which
can either be:
i. Constants or
ii. Values stored in memory – usually represented by variables
representing a memory address, or some form of calculation of an
address;
iii. Values stored in registers
 These then leads to three modes of addressing
 Register addressing – specify register name
 Immediate addressing – the value of the constant is given in the
instruction
 Memory addressing – uses a variable for the calculation of an address
 For data movement instructions, the first argument is usually the
destination, while the second argument is the source of the value
Addressing modes
 Register addressing: In register addressing, one or more of the
inputs to an instruction is a register name
 This illustrated by the instructions below:
MOV DX, len ;
MOV EAX, 1 ;
MOV EAX, EBX;
 Immediate addressing: In immediate addressing, one of the
arguments is a constant
 This is illustrated by the instructions below:
num DB 20 ; define a variable num which stores a byte value – data segment
ADD [num], 10 ; add 10 to the variable num. The result is in num
Addressing modes
 Direct memory addressing: In this addressing mode, one of the operands is a
memory address, usually represented by a variable name
 The variable name is actually stored in a symbol table together with the
offset
 Offset here means how far the address of the variable is from the value in the
data segment register (EDS)
 The offset is usually referred to as the effective address and is calculated by
the assembler during the assembly process
 During the program execution, the sum of EDS and the offset results in the
actual memory address that is accessed.
 The code below illustrates direct memory addressing where one of the
addresses is a variable name (offset)
ADD [num], byte 10;
MOV [num] , DX;
Addressing modes
 Direct-offset memory addressing: In this addressing mode,
arithmetic operations are used to modify a memory address to get
the effective address
 This illustrated in the code below:
section .text
mov CL, nums ; move address of 10 into the CL register; code segment
mov CL, [nums+1] ; move 5 into the CL register;
mov CL, nums+1; move address of 5 into the CL register; code segment
section .data
nums DB 10, 5, 3, 7 ; an array of bytes ; data segment
Addressing modes
 indirect memory addressing: In this addressing mode, base
registers (EBX,EBP) and the index registers (EDI, ESI) are used
together with an offset to get the address of interest
 Square brackets around the register name are used to indicate that
the registers are being used for memory reference
 This mode is usually used for variables like arrays.
 The start address can for instance be stored in the EBX register
 The following code illustrates
nums DB 10, 5, 3, 7 ; an array of bytes ; data segment
mov EBX, nums ; i.e. the address of nums ;code segment
mov [EBX], 20 ; replace 10 with 20 in position 0 of the array
add EBX, 2 ; address of the 3rd element of array
mov [EBX], 15 ; replace 3 with 15
Addressing modes
 The MOV instruction is used to copy data from one location to
another
 It supports data from a source (on the right) to a destination (on the
left) as illustrated bel
i. MOV register, register
ii. MOV register, immediate
iii. MOV register, memory
iv. MOV memory, register
v. MOV memory, immediate
 The source data should fit in the destination location

You might also like