Coa ch-2
Coa ch-2
1
Various Types of Addressing Modes
2
Introduction
• bit, nibble, byte, word
– single bit is either 0 or 1. Group of 4 bits is nibble, 8 bit is byte. Collection
of n bits is word, n being the word length.
• Addressing Modes
– are the different ways in which the location of an operand (data value) is
specified in an instruction
3
Types of Addressing Modes
Addressing Modes
Index Relative
4
Immediate Addressing Mode
Instruction
Opcode Operand
6
Register Addressing Mode
The operand is the contents of a processor
register; the name (address) of the register is given
in the instruction.
Instruction
LOC
Move LOC,R2
R2
7
RegisterAddressing Mode
Instruction
Opcode R
Registers
R0
R=R1
Operand : 50 R1
R2
9
Direct Addressing Mode
The operand is in a memory location; the address of this
location is given explicitly in the instruction. (This mode
is also called as Absolute Addressing Mode).
Instruction
LOC
Move LOC,R2
R2
10
Direct/Absolute Addressing Mode
Instruction
Opcode A Memory
A=XXXX
Operand : 50
A = Address field
11
Contd..
Advantage:
• Implementation requires less hardware
12
Indirect Addressing Mode
▪ The effective address of the operand is
the contents of a register or memory
location whose address appears in the
instruction.
13
Contd..
• Address field of the instruction gives the
address of a memory word in which effective
or actual address of the operand is found
14
Contd..
▪ Indirect addressing mode is symbolically
represented as (A)
▪ Effective address is calculated as EA=[A]
▪ The register or memory location inside the
bracket gives the effective address of the
operand.
15
Contd…
• Two types of indirect addr. modes :
• Through a general purpose register
– ex: Add (R1), R0
– Register R1 contains the effective address
16
Indirect Addressing Mode
17
Contd..
Advantage:
• Wider address range to refer to a large number
of memory locations
Disadvantage:
• 2 or more memory references to fetch the
desired operand
18
Example: Pgm to add n numbers
19
The Pgm using indirect addressing
Indirect addressing
20
Indexed Addressing Mode
• The effective address of the operand is generated
by adding a constant value to the contents of a
register
• Symbolic Representation
X(Ri)
– X is a constant value given in the instruction
– X may be either Offset Value or Beginning
Address of the data array in memory
– Ri is the name of the register involved
– Ri is also called as Index Register
21
Contd..
• Generation of Effective Address:
EA = X + [Ri]
22
Contd..
Two ways of using Indexed Mode :
1. Index register Ri contains the beginning
address of data array and Value of X
defines the offset
23
Indexed Mode - Type 1
1) Index register Ri contains the beginning
.
address of data array and Value of X defines
the offset
Ex: Add 20(R1), R2
24
Indexed Mode – Type 2
2) Index register Ri contains the offset to the
. operand and Value of X defines the
beginning address of data array
Ex: Add 1000(R1), R2
25
Indexed Mode – contd..
Advantages:
Allows accessing operands whose locations are
defined relative to a reference point
Disadvantage :
Complexity involved in computing the effective
address
A variant of Indexed mode:
(Ri, Rj)
where EA = [Ri] + [Rj]
adv – contents of both registers can be changed
26
Ex: A pgm using Indexed Addressing
• N student records, starting at location LIST
• test1, test2, test3 – marks of 3 tests
• To find separate sums of marks of each test of
all students
• Store these 3 sums at SUM1, SUM2, and SUM3
27
List of Students’ Marks in Memory
28
The Pgm.
Move #LIST, R0 …… R0 points to ID location of 1st student
Clear R1 … stores the sum of Test 1 marks
Clear R2 … stores the sum of Test 2 marks
Clear R3 … stores the sum of Test 3 marks
Move N, R4 … keeps the count of student records
30
Ex: Computation of branch target address using Relative
Addressing mode
Address Contents
. Move N, R1
. Move #NUM1, R2
. Clear R0
1000 LOOP Add (R2), R0
1004 Add #4, R2
1008 Decrement R1
1012 Branch>0 LOOP
1016 Move R0, SUM
• Content of PC at the time of branch target address is
generated will be 1016
• Compute the offset value X needed to branch to location
LOOP (i.e location 1000); i.e, X=-16
• Generate the branch target address as -16(PC)
31
Additional Modes
• Autoincrement Mode
• Autodecrement Mode
• Useful for accessing data items in successive
memory locations
32
Autoincrement Mode
• Written as: (Ri)+
• Content of the register Ri gives the effective
address
• After accessing the operand, the content of the
register is automatically incremented to point to
the next item in a list
• The increment is 1 for byte-sized operands, 2 for
16 bit operand & 4 for 32 bit operands
33
Pgm to add n numbers using-
1.Indirect addr. 2.Autoincrement addr.
34
Autodecrement Mode
• Written as: -(Ri)
• Content of the register Ri is first automatically
decremented which gives the effective address
of the operand
• Operands are accessed in descending address
order
• Ex: Add –(R2), R0
35
Addressing Modes- Summary
Name Assembler Syntax Addressing
function
Immediate #Value Op erand = Value
Register Ri EA = Ri
Indirect (R i ) EA = [R i ]
(LOC) EA = [LOC]
Index X(R i) EA = [R i ] + X
Autoincremen t (R i )+ EA = [R i ] ;
Incremen t R i
Autodecrement − (R i ) Decremen t R i ;
EA = [R i]
36
Acknowledgement
Internet
37