0% found this document useful (0 votes)
15 views37 pages

Coa ch-2

The document discusses various types of addressing modes used in machine instructions and programs. It describes 6 addressing modes: immediate, register, direct, indirect, indexed, and relative. Each mode is explained in 1-2 sentences with examples given to illustrate how the effective address is calculated for each mode. The document also provides examples of programs that use indirect and indexed addressing modes.

Uploaded by

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

Coa ch-2

The document discusses various types of addressing modes used in machine instructions and programs. It describes 6 addressing modes: immediate, register, direct, indirect, indexed, and relative. Each mode is explained in 1-2 sentences with examples given to illustrate how the effective address is calculated for each mode. The document also provides examples of programs that use indirect and indexed addressing modes.

Uploaded by

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

UNIT 1 contd..

Machine Instructions And Programs

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.

• Data and Address


– memory of the computer is a collection of words, each memory has a
distinct name or address.

• 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

Immediate Register Direct Indirect

Index Relative

4
Immediate Addressing Mode
Instruction
Opcode Operand

•Operand is given explicitly in the instruction


•Opcode is followed by operand rather than an
address
Example
Move 50immediate, R0

Places data item 50 in register R0


5
Contd…
• This mode is only used to indicate the value of
the source operand
• Immediate operand is indicated by preceding
the data by a #
• Move #50, R0
• Adv:
• Only one memory fetch cycle is enough to access
both operand & opcode
• Useful in initializing variables & registers
• Disadv:
• Size of the immediate operand is restricted to the
size of address field & opcode size of that
instruction

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

R is a general purpose register


8
Contd..
Advantages:
• No memory reference is required
• Shorter address field
• Speedy execution of instruction
Disadvantages:
• Limited registers - Limited address space

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.

▪ Effective address : is the address of the


operand obtained from the computation
dictated by the given addressing mode.

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

• Accessing an operand requires minimum of


two memory fetches
• Fetch the effective address of the operand
• Fetch the operand from the effective address location

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.

▪ The memory location or register containing the


effective address of the operand is called as
Pointer.
▪ A is a pointer in the above example

15
Contd…
• Two types of indirect addr. modes :
• Through a general purpose register
– ex: Add (R1), R0
– Register R1 contains the effective address

• Through a memory location


– ex: Add (A), R0
– Memory location A contains the effective address
of the operand

16
Indirect Addressing Mode

Add (R1),R0 Add (A),R0


. Main Memory .
. .
. .
B Operand A B
.
.
B Operand
R1 B Register

(a) Through general purpose register (b) Through a memory location

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]

• Contents of Index register is not changed


during address generation

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

2. Index register Ri contains the offset to the


operand and Value of X defines the
beginning address of data array

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

LOOP Add 4(R0), R1 …. Acess the scores and


Add 8(R0), R2 …. add them to the running sum
Add 12(R0), R3 …. held in respective registers

Add # 16, R0 ..... Point to the ID location of next student


Decrement R4
Branch>0 LOOP …. Loop until R4 reaches 0

Move R1, Sum1


Move R2, Sum2 …. Store sums from register to memory
Move R3, Sum3
29
Relative Addressing Mode
• The effective address is determined by the index mode
using the Program Counter in place of the general-
purpose register Ri.
• Symbolic Representation
X(PC)

Addresses a memory location that is X bytes away


from the location presently pointed to by the PC
i.e., EA = X + [PC]

• Commonly used to specify the target address in branch


instructions

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.

Move N,R1 Move N,R1


Move #NUM1, R2 Move #NUM1, R2
Clear R0 Clear R0
LOOP Add (R2), R0 LOOP Add (R2)+, R0
Add #4, R2 Decrement R1
Decrement R1 Branch > 0 LOOP
Branch > 0 LOOP Move R0, SUM
Move R0, SUM

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

Absolute (Direct) LOC EA = LOC

Indirect (R i ) EA = [R i ]
(LOC) EA = [LOC]
Index X(R i) EA = [R i ] + X

Base with index (R i ,R j ) EA = [R i ] + [R j ]

Relative X(PC) EA = [PC] + 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

PPT compiled/prepared by:


Dr. Raju K., Assoc. Prof.
CSE Dept, NMAMIT

37

You might also like