You are on page 1of 28

Instruction Sets:

Addressing Modes
and Formats
Addressing : Introduction

We have seen in the previous chapter how


Instruction formats work to specify operands
and operations .
This chapter deals with how to specify the
operands and operations in the instructions.
This is done in two parts:
i. Specification of address of operand.
ii. Organising the bits of the instruction to
define operand addresses and
operation of the of the instructions.
Addressing : Types Of Addressing

Address fields in a typical instruction format


are limited.
We should be able to reference a large range
of memory locations in main memory or
sometimes virtual memory.
A variety of addressing techniques are used
.They usually involve a trade-off between
address range and / or addressing
flexibility on one hand and number of
memory references and / or complexity
of addressing calculation on the other
hand .
Addressing : Types Of Addressing

These are the most commonly used


addressing modes :

i. Immediate
ii. Direct
iii. Indirect
iv. Register
v. Register Indirect
vi. Displacement
vii. Stack
Note:
Almost all computer architectures provide
more than one of these addressing modes .
Several approaches are taken in order for the
control unit to determine the addressing
mode to be used :
Often different opcodes will use different
addressing modes .
One or more bits in the instruction format can be
used as addressing mode specifier .
For the description the following naming
convention is used:

A =contents of the address field in


the instruction .
EA = Actual / Effective address of
the location of the referenced
operand .
( X ) = Contents of location X.
Immediate Addressing :

This is the simplest form of addressing , wherein


the operand is actually present in the instruction

Instructio
n
OPERAND

OPERAND = A
This mode can be used to define and store
constants or to set initial values of variables .
Typically the number will be stored as a 2s complement
form with leftmost bit being sign bit .When operand is
loaded into data register , sign bit is extended to full
data word length .
Immediate Addressing : (Contd)

Advantages:
No memory reference is required . Hence saving
cache or instruction reference in the instruction
cycle .

Disadvantages:
Size of the number is limited to size of address
field ,which in the case of most instruction sets is
small compared to word length .
Direct Addressing :

A simple type of addressing is direct


addressing in which the address field contains
effective address of the operand .
Instructio
n
A Memory

OPERAND

EA = A
Direct Addressing : (Contd)

Advantages:
Only one memory reference is required .
No special calculation is needed .
Disadvantages:
Provides only limited address space .

This type of addressing was found on earlier


computer systems and is still found on small
computer systems
Indirect Addressing :

Here the address field refers to the address of


a word in memory ,which in turn contain the
full length address of the operand .
Instructio
n
A Memory

EA = ( A )

OPERAND
Indirect Addressing : (Contd)

Advantages:
For a word length N ,address space of 2N is now availiable .
Disadvantages:
Instruction execution requires two memory references to
fetch the operand , one to get the address of the operand
and the next to get the value of the operand .
Note:A rarely used variant of indirect addressing is
multilevel or cascaded indirect addressing .
EA = (.( A ).)
This uses an indirect flag to indicate whether the word
contains the EA whether it contains another level of
indirection .This method has no apparent advantage and
has the disadvantage of requiring three or more memory
references to fetch the operand .
Register Addressing :

This is similar to direct addressing .The only


difference is that the address field refers to a
register rather than a main memory address .
Instructio
n
R Register

OPERAND
EA = R
Typically an address field that references
registers will have 3 4 bits so a total of
8 16 general purpose registers can be
referenced .
Register Addressing : (Contd)

Advantages:
For a word length N ,address space of 2N is now
availiable .
Disadvantages:
Instruction execution requires two memory
references to fetch the operand , one to get the
address of the operand and the next to get the
value of the operand .
Register Indirect Addressing :

This is analogous to indirect addressing . The


only difference is that the address field refers
to a register rather than a main memory
address . Instructio
n
R Register

Memory

OPERAND EA = ( R )
Register Indirect Addressing : (Contd)

Advantages:
Address space limitation of address field is
overcome by having that field refer to a word
length location containing an address .
Register indirect addressing uses one less memory
reference than indirect addressing .
Disadvantages:
Same as indirect addressing .
Displacement Addressing :

It combines the capabilities of direct


addressing and register indirect addressing .
Instructio
n
R A

Memory
Register

OPERAND
EA = A + ( R )
Displacement Addressing : (Contd)

Displacement addressing requires that the


instructions have two address fields , atleast
one of them being explicit
The value contained in one address field is used
directly and the other address field ( or an
implicit reference based on opcode ) refers to a
register whose contentsare added to A to
produce the effective address .
Advantages:
It offers flexibility of design .
Disadvantages:
It is complex .
Displacement Addressing : (Contd)

There are three main types of displacement


addressing :
i. Relative Addressing
ii. Base Register Addressing
iii. Indexing
Displacement Addressing : Relative Addressing

The implicitly referenced register is the program


counter (PC) , i.e. the current instruction address
is added to the address field to produce the
effective address .
Thus the relative address is a displacement
relative to the address of the instruction .
Note: Typically the effective address is treated
as a 2s complement number for this operation .
It exploits the concept of locality .If most
memory references are relatively near to the
address of the instruction being executed ,then
it saves address bits in the instruction .
Displacement Addressing : Base-Register
Addressing

The referenced register contains a memory


address and the address field contains a
displacement (usually an unsigned integer
expression ) from that address .The register
reference may be implicit or explicit .
It also exploits the concept of locality of
,memory addresses .
Displacement Addressing : Indexing

The address field refers to a main memory


address and the referenced register contains a
positive displacement from that address .
Address field is considered a memory address
in indexing ,it generally contains more bits than
an address field in base register instruction .
This kind of instructions are used for iterative
tasks.

EA= A + R
R=( R ) + 1
Stack Addressing :

Associated with the stack is a pointer whose


value is the address of the top element of the
stack .
The stack pointer is maintained in a register
.Thus references to stack locations in memory
are in fact register indirect addressing .
It is a form of implied addressing .The machine
instructions need not include a memory
address but implicitly operate at the top of the
stack.
Usually used in microprocessors .
Instruction Formats:

An instruction format defines the layout of


bits of an instruction ,in terms of its
constituent parts .
An instruction format must include
i. An opcode
ii. Zero or more operands (implicitly or explicitly).
Addressing modes must be declared for each
operand .
Instruction formats: Design considerations

1. Instruction Length
Affects and is affected by memory size memory organisation,
bus structure ,CPU complexity and CPU speed.
Larger instruction length provides programmers with more
opcodes and larger address fields. Resulting in easier coding
and shorter programs .However it also may result in wasteful .
2. Bit allocation
There is a trade-off between number of opcodes and
power of addressing .
Variable length opcodes can be used .This means
opcodes have a minimum bit length ,but for opcodes
which require fewer operands or less powerful
addressing larger amount of bits are allocated to
opcode field .
Instruction formats: (Contd)

The following interrelated factor are taken


into consideration when determining the use
of addressing bits :
i. Number of addressing modes .
ii. Number of operands .
iii. Register vs. memory .
iv. Number of Register sets .
v. Address range .
vi. Address granularity .
Variable length instructions :

So far we have discussed fixed instructions


,but the designer may decide to provide
instruction formats of different lengths .
This makes it easy to provide a variety of
opcodes of different lengths.
Addressing can be more flexible with various
combinations of register and memory
references plus addressing modes .
This however results in an increase in the
complexity of the CPU .(disad)
The End

You might also like