Вы находитесь на странице: 1из 23

Lecture 06

Instruction Set Addressing Modes

Taken from W. Stallings Computer Organization and Architecture 8th Edition

5/11/16

MEQUANENT ARGAW, DMU

LECTURE OUTLINE

Addressing Modes

5/11/16

MEQUANENT ARGAW, DMU

ADDRESSING MODES
Immediate
Direct
Indirect
Register
Register Indirect
Displacement (Indexed)
Stack

5/11/16

MEQUANENT ARGAW, DMU

IMMEDIATE
ADDRESSING
Operand is part of instruction
Operand = address field
e.g. ADD 5; // Add 5 to contents of accumulator. 5 is the operand
itself.
Advantage: Does not require extra memory reference to fetch the
operand.

Instruction

Drawback :
Only a constant can be supplied.

Opcode

Operand

Range is limited by size of the operand field (e.g. 0 to 255 for 8bit field).
5/11/16

MEQUANENT ARGAW, DMU

DIRECT ADDRESSING
Address field contains address of operand.
Effective address (EA) = address field (A).
e.g. ADD A
Add the operand located in memory address A to accumulator.

Single memory reference to access data.


No additional calculations to work out effective address.
Limited address space. (e.g. 8 bit field can only access 256
memory locations.)
5/11/16

MEQUANENT ARGAW, DMU

DIRECT ADDRESSING DIAGRAM


Instruction
Opcode

Address A

Memory

Operand

5/11/16

MEQUANENT ARGAW, DMU

INDIRECT ADDRESSING
(1)
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.

5/11/16

MEQUANENT ARGAW, DMU

INDIRECT ADDRESSING
(2)
Large address space of 2n where n = word length.
May be nested, multilevel, cascaded.
e.g. EA = (((A)))
Multiple memory accesses to find operand.

Hence slower

5/11/16

MEQUANENT ARGAW, DMU

INDIRECT ADDRESSING DIAGRAM


Instruction
Opcode

Address A

Memory
Pointer to operand

Operand

5/11/16

MEQUANENT ARGAW, DMU

REGISTER ADDRESSING
(1)
Operand is held in register named in address filed.
EA = R
Limited number of registers exist in CPU.
Very small address field is needed to access them.
Shorter instructions and faster instruction fetch.
Most common addressing mode in most computers.

Q. If a CPU has 32 registers, how many bits are


required for register address field of Ans:
an instruction?
5
5/11/16

MEQUANENT ARGAW, DMU

10

REGISTER ADDRESSING
(2)
No memory access and very fast execution.
Very limited address space
Multiple registers in CPU helps performance.
Requires good assembly programming or compiler
writing
N.B. C programming
register int a;

5/11/16

MEQUANENT ARGAW, DMU

11

REGISTER ADDRESSING
DIAGRAM
Instruction
Opcode

Register Address R
Registers

e.g. MOV R1, 100 (R1 100)


Register Address
Operand

5/11/16

MEQUANENT ARGAW, DMU

12

REGISTER INDIRECT ADDRESSING


Register that holds memory address is specified in
the address field of the instruction.
EA = (R)
Can address larger number of memory locations;
(2n).
One fewer memory access than indirect addressing.

5/11/16

MEQUANENT
DMU

ARGAW,

13

REGISTER INDIRECT ADDRESSING


EXAMPLE
Instruction
Opcode
e.g. MOV
[R2]

Register Address R
R1,
CPU
Memory
Address

R1

R2

101

Memor
y

99

78

100

96

101

Q. If a CPU has 32 registers (16 bits each), how many


memory locations can be addressed using register
indirect addressing?
5/11/16

Ans:
MEQUANENT ARGAW, DMU

14

DISPLACEMENT
ADDRESSING

e.g. MOV R1,


[R2+100]

EA = A + (R)

Address field hold two values


Main
added
value

memory
with
to

get

address

displaceme
nt value

is

displacement
the

R1

55

Memor
y
109 36

R2

10

110

55

111

effective

address in memory.

EA=
R2+100
=10+100=110

CPU

Typical application is to access arrays using the displacement as a pointer to


the start of the array and the register value as an array index.
5/11/16

MEQUANENT ARGAW, DMU

15

DISPLACEMENT ADDRESSING
CNTD
e.g. Assume we have an array of four elements.

Let the

memory address of the first element is 100. A program that


adds 1 to every element of the array is given below:
MOV R1,4
MOV R2,0
loop:
INC [R2+100]
INC R2
DEC R1
JNZ loop

(100+
(100+
0)
1)
(100+
2)
(100+
3)

Memor
y

Memory

100

52

100

53

101

55

101

56

102

102

103

93

103

94

104

23

104

23

Q. What other addressing modes are used in the above program?


5/11/16

MEQUANENT ARGAW, DMU

16

DISPLACEMENT ADDRESSING
DIAGRAM
Instruction
Opcode Register R Address A
Memory

Registers

Pointer to Operand

Operand

Three of the most common uses of displacement addressing are


discussed below.
5/11/16

MEQUANENT ARGAW, DMU

17

RELATIVE ADDRESSING
R = Program counter, PC
EA = (PC) + A // A= displacement value
i.e. get operand at A cells from current location pointed to by PC.
Typically, the address field is treated as a twos complement
number for this operation.
If most memory references are relatively near to the instruction
being executed, then the use of relative addressing saves address
bits in the instruction.

5/11/16

MEQUANENT ARGAW, DMU

18

BASE-REGISTER
ADDRESSING
R holds pointer to main memory base address.
The address field A holds the displacement value
(usually unsigned integer).
R may be explicit or implicit.

e.g. MOV R1, [R2+100]

displacement
value
5/11/16

MEQUANENT ARGAW, DMU

19

INDEXED ADDRESSING
EA = A + R: where A = base main memory address and R =
displacement.
The address field contains more field than base-register.
Good for accessing arrays
EA = A + R
R++

5/11/16

MEQUANENT ARGAW, DMU

20

COMBINATIONS
Postindex
EA = (A) + (R)
Preindex
EA = (A+(R))
(Draw the diagrams)

5/11/16

MEQUANENT ARGAW, DMU

21

STACK ADDRESSING
The stack is a reserved block of locations. Items are appended
to the top of the stack so that, at any given time, the block is
partially filled. Associated with the stack is a pointer whose
value is the address of the top of the stack.
Operand is (implicitly) on top of stack.
It is implied that the address is contained in Stack
side a stack
pointer register.

Stack
e.g. PUSH
R1 pointer
Register
5/11/16

R1
SP

CPU

201

MEQUANENT ARGAW, DMU

201

200

23

199

15
22

X 86

ADDRESSING MODES

Register, Immediate: e.g. MOV AX, 0546


Direct: e.g. ADD AX, [0546]
Register Indirect: e.g. MOV [BX],AX
Displacement
Indexed:

e.g. MOV AX, [R+0645]

where R is an Index register (SI or

DI)

Based:

5/11/16

e.g. MOV AX, [R+0645]

where R is a base register (BX or BP)

MEQUANENT ARGAW, DMU

23

Вам также может понравиться