Академический Документы
Профессиональный Документы
Культура Документы
5/11/16
LECTURE OUTLINE
Addressing Modes
5/11/16
ADDRESSING MODES
Immediate
Direct
Indirect
Register
Register Indirect
Displacement (Indexed)
Stack
5/11/16
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
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.
Address A
Memory
Operand
5/11/16
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.
5/11/16
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
Address A
Memory
Pointer to operand
Operand
5/11/16
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.
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
11
REGISTER ADDRESSING
DIAGRAM
Instruction
Opcode
Register Address R
Registers
5/11/16
12
5/11/16
MEQUANENT
DMU
ARGAW,
13
Register Address R
R1,
CPU
Memory
Address
R1
R2
101
Memor
y
99
78
100
96
101
Ans:
MEQUANENT ARGAW, DMU
14
DISPLACEMENT
ADDRESSING
EA = A + (R)
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
15
DISPLACEMENT ADDRESSING
CNTD
e.g. Assume we have an array of four elements.
Let the
(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
16
DISPLACEMENT ADDRESSING
DIAGRAM
Instruction
Opcode Register R Address A
Memory
Registers
Pointer to Operand
Operand
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
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.
displacement
value
5/11/16
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
20
COMBINATIONS
Postindex
EA = (A) + (R)
Preindex
EA = (A+(R))
(Draw the diagrams)
5/11/16
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
201
200
23
199
15
22
X 86
ADDRESSING MODES
DI)
Based:
5/11/16
23