KEMBAR78
Addressing Modes | PDF | Computer Science | Computer Architecture
0% found this document useful (0 votes)
91 views34 pages

Addressing Modes

The document outlines various addressing modes used in computer architecture, including immediate, direct, indirect, register, register indirect, displacement, and stack addressing. Each mode is described with its advantages and disadvantages, along with examples of how operands are referenced in instructions. Additionally, it discusses the implications of these addressing modes on performance and memory access.

Uploaded by

thangedikishore
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)
91 views34 pages

Addressing Modes

The document outlines various addressing modes used in computer architecture, including immediate, direct, indirect, register, register indirect, displacement, and stack addressing. Each mode is described with its advantages and disadvantages, along with examples of how operands are referenced in instructions. Additionally, it discusses the implications of these addressing modes on performance and memory access.

Uploaded by

thangedikishore
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/ 34

Addressing Modes

• Immediate
• Direct
• Indirect
• Register
• Register Indirect
• Displacement (Indexed)
• Stack
Addressing Modes
– Addressing refers to how an operand
refers to the data we are interested in
for a particular instruction

– In the Fetch part of the instruction


cycle, there are three common ways
to handle addressing in the
instruction
• Immediate Addressing
• Direct Addressing
• Indirect Addressing
we use the following notation:
A = Contents of an address field in the
instruction that refers to a memory
R = Contents of an address field in the
instruction that refers to a register
EA = Actual (effective) address of the
location containing the referenced
operand
(X) = Contents of location X

Simple Instruction Format


Immediate Addressing

Operand is part of instruction


Operand = address field
ADD 5
Add 5 to contents of accumulator
5 is operand
• No memory reference to fetch data
• Fast
• Limited range
Immediate Addressing
The simplest form of addressing is immediate
addressing, in which the operand is actually
present in the instruction:
OPERAND = A
This mode can be used to define and use
constants or set initial values of variables.

The advantage of immediate addressing is that


no memory reference other than the instruction
fetch is required to obtain the operand.

The disadvantage is that the size of the number


is restricted to the size of the address field,
which, in most instruction sets, is small
compared with the world length.
Direct Addressing
• Address field contains address of operand
• Effective address (EA) = address field of A
– Add contents of cell A to accumulator
– Look in memory at address A for operand
• Single memory reference to access data
• No additional calculations to work out
effective address
• Limited address space
Direct Addressing Diagram
A very simple form of addressing is direct addressing, in which the
address field contains the effective address of the operand:
EA = A
It requires only one memory reference and no special calculation.
Indirect Addressing
• Memory cell pointed to by address field
contains the address of (pointer to) the
operand
• EA = (A)
– Look in A, find address (A) and look there
for operand
• e.g. ADD (A)
– Add contents of cell pointed to by
contents of A to accumulator
Indirect Addressing
• Large address space
• 2n where n = word length
• May be nested, multilevel, cascaded
– e.g. EA = (((A)))
• Draw the diagram yourself
• Multiple memory accesses to find
operand
• Hence slower
Indirect Addressing Diagram
1. With direct addressing, the length of the address field is usually
less than the word length, thus limiting the address range.
2. One solution is to have the address field refer to the address of a
word in memory, which in turn contains a full-length address of
the operand. This is know as indirect addressing:
EA = (A)
Register Addressing:
• Register addressing is similar to direct addressing.
The only difference is that the address field refers to
a register rather than a main memory address:
EA = R
• The advantages of register addressing are that only
a small address field is needed in the instruction
and no memory reference is required.
• The disadvantage of register addressing is that the
address space is very limited.
Register Addressing
• No memory access
• Very fast execution
• Very limited address space
• Multiple registers helps performance
– Requires good assembly programming or
compiler writing
– C programming
• register int a;
Register Indirect Addressing
• Register indirect addressing is similar to indirect addressing,
except that the address field refers to a register instead of a
memory location.
• It requires only one memory reference and no special
calculation.
EA = (R)
• The first information is available in a register which is nothing
but a memory address. From that memory location, we use to
get the data or information.
• In general, register access is much more faster than the
memory access.
Register Indirect Addressing

• EA = (R)
• Operand is in memory cell pointed to
by contents of register R
• Large address space (2n)
• One fewer memory access than
indirect addressing
Displacement Addressing
• A very powerful mode of addressing combines the capabilities
of direct addressing and register indirect addressing, which is
broadly categorized as displacement addressing:
EA = A + (R)
• Displacement addressing requires that the instruction have
two address fields, at least one of which is explicit. The value
contained in one address field (value = A) is used directly. The
other address field, or an implicit reference based on opcode,
refers to a register whose contents are added to A to produce
the effective address.

• Three of the most common use of displacement addressing


are:
– l Relative addressing
– l Base-register addressing
– l Indexing
Displacement Addressing
Displacement Addressing
• EA = A + (R)
• Address field hold two values
– A = base value
– R = register that holds displacement
– or vice versa
Displacement Addressing
Relative Addressing Modes

The Address fields of an instruction specifies the part of the


address (abbreviated address) which can be used along with a
designated register to calculate the address of the operand

PC Relative Addressing Mode( R = PC)


- EA = PC + IR(address)

- Address field of the instruction is short


- Large physical memory can be accessed with a small
number of address bits

Indexed Addressing Mode

XR: Index Register:


EA = XR + IR(address)

Base Register Addressing Mode


BAR: Base Address Register:
EA = BAR + IR(address)
Relative Addressing
Relative Addressing:
For relative addressing, the implicitly referenced register is the
program counter (PC). That is, the current instruction address is
added to the address field to produce the EA. Thus, the effective
address is a displacement relative to the address of the instruction.

• A version of displacement addressing


• R = Program counter, PC
• EA = A + (PC)
• i.e. get operand from A cells from current
location pointed to by PC
Relative Addressing
• Relative Address
– EA = PC + Relative Addr 0
1
PC = 2 2

100
AR = 100
101
102 1 1 0 A
Could be Positive or 103
Negative 104
(2’s Complement)
Base-Register Addressing
The reference register contains a memory address, and the
address field contains a displacement from that address. The
register reference may be explicit or implicit.

In some implementation, a single segment/base register is


employed and is used implicitly.

In others, the programmer may choose a register to hold the


base address of a segment, and the instruction must
reference it explicitly.

• A holds displacement
• R holds pointer to base address
• R may be explicit or implicit
• e.g. segment registers in 8086
Base-Register Addressing
• Base Register
– EA = Base Register + Relative Addr

Could be Positive or AR = 2
Negative
(2’s Complement)
+

100 0 0 0 5
BR = 100
101 0 0 1 2
102 0 0 0 A
Usually points to 103 0 1 0 7
the beginning of an 104 0 0 5 9
array
Indexing
• The address field references a main memory address, and the
reference register contains a positive displacement from that address.
In this case also the register reference is sometimes explicit and
sometimes implicit.

• Generally index register are used for iterative tasks, it is typical that
there is a need to increment or decrement the index register after
each reference to it. Because this is such a common operation, some
system will automatically do this as part of the same instruction
cycle. This is known as auto-indexing.
We may get two types of auto-indexing:
-- auto-incrementing
-- auto-decrementing.

• If certain registers are devoted exclusively to indexing, then auto-


indexing can be invoked implicitly and automatically. If general
purpose register are used, the auto index operation may need to be
signaled by a bit in the instruction.
Addressing Modes
• Indexed
– EA = Index Register +
Relative Addr

Useful with XR = 2
“Autoincrement” or
“Autodecrement”
+

100
AR = 100
101
Could be Positive or
Negative 102 1 1 0 A
(2’s Complement) 103
104
Indexing
Auto-indexing using increment can be depicted as
follows:
EA = A + (R)
R = (R) + 1

Auto-indexing using decrement can be depicted as


follows:
EA = A + (R)
R = (R) - 1
Indexed Addressing
• A = base
• R = displacement
• EA = A + R
• Good for accessing arrays
– EA = A + R
– R++
Combinations
• Post-index
• EA = (A) + (R)

• Pre-index
• EA = (A+(R))
Stack Addressing
The stack mode of addressing is a form of implied addressing. The
machine instructions need not include a memory reference but
implicitly operate on the top of the stack.

The stack pointer is maintained in a register.

Thus, references to stack locations in memory are in fact register


indirect addresses.

• Operand is (implicitly) on top of stack


e.g.
– ADD Pop top two items from stack
and add
Addressing Example
• What value is loaded into the accumulator for
each addressing mode?

Load 800
Load 800
Load 800
Load R1[800]
Addressing Example
• These are the values loaded into the accumulator
for each addressing mode.
x86 Addressing Modes
• Virtual or effective address is offset into segment
– Starting address plus offset gives linear address
– This goes through page translation if paging enabled
• 12 addressing modes available
– Immediate
– Register operand
– Displacement
– Base
– Base with displacement
– Scaled index with displacement
– Base with index and displacement
– Base scaled index with displacement
– Relative
Addressing modes
Mode Meaning Pros Cons

Implied Fast fetch Limited instructions

Immediate Operand=A No memory ref Limited operand

Direct EA=A Simple Limited address space

Indirect EA=[A] Large address space Multiple memory ref

Register EA=R No memory ref Limited address space

Register
EA=[R] Large address space Extra memory ref
indirect

Displacement EA=A+[R] Flexibility Complexity

stack EA=stack top No memory ref Limited applicability


ADDRESSING MODES - EXAMPLES
Address Memory
200 Load to AC Mode
PC = 200 201 Address = 500
202 Next instruction
R1 = 400

399 450
XR = 100
400 700

AC
500 800

600 900
Addressing Effective Content
Mode Address of AC
Direct address 702 325
Immediate operand
Indirect address
Relative address 800 300
Indexed address
Register
Register indirect
Autoincrement
Autodecrement
ADDRESSING MODES - EXAMPLES
Address Memory
200 Load to AC Mode
PC = 200 201 Address = 500
202 Next instruction
R1 = 400

399 450
XR = 100
400 700

AC
500 800

600 900
Addressing Effective Content
Mode Address of AC
Direct address 500 /* AC  (500) */ 800 702 325
Immediate operand - /* AC  500 */ 500
Indirect address 800 /* AC  ((500)) */ 300
Relative address 702 /* AC  (PC+500) */ 325 800 300
Indexed address 600 /* AC  (XR+500) */ 900
Register - /* AC  R1 */ 400
Register indirect 400 /* AC  (R1) */ 700
Autoincrement 400 /* AC  (R1)+ */ 700
Autodecrement 399 /* AC  -(R) */ 450

You might also like