+
William Stallings
Computer Organization
and Architecture
10th Edition
© 2016 Pearson Education, Inc., Hoboken,
NJ. All rights reserved.
+ Chapter 13
Instruction Sets: Addressing
Modes and Formats
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Addressing Modes
Immediate
Direct
Indirect
Register
Register indirect
Displacement
Stack
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Instruction Instruction Instruction
Operand A A
Memory Memory
Operand
Operand
(a) Immediate (b) Direct (c) Indirect
Instruction Instruction Instruction
R R R A
Memory Memory
Operand
Operand Operand
Registers Registers Registers
(d) Register (e) Register Indirect (f) Displacement
Instruction
Implicit
Top of Stack
Register
(g) Stack
Figure 13.1 Addressing Modes
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Table 13.1
Basic Addressing Modes
M ode Algorithm Principal Advantage Principal Disadvantage
Immediate Operand = A No memory reference Limited operand magnitude
Direct EA = A Simple Limited address space
Indirect EA = (A) Large address space Multiple memory references
Register EA = R No memory reference Limited address space
Register indirect EA = (R) Large address space Extra memory reference
Displacement EA = A + (R) Flexibility Complexity
Stack EA = top of stack No memory reference Limited applicability
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+ Immediate Addressing
Simplest form of addressing
Operand = A
This mode can be used to define and use constants or set initial
values of variables
Typically the number will be stored in twos complement form
The leftmost bit of the operand field is used as a sign bit
Advantage:
No memory reference other than the instruction fetch is required to
obtain the operand, thus saving one memory or cache cycle in the
instruction cycle
Disadvantage:
The size of the number is restricted to the size of the address field, which,
in most instruction sets, is small compared with the word length
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Direct Addressing
Address field
contains the
effective address of
the operand
Effective address
(EA) = address field
(A)
Was common in
earlier generations
of computers
Requires only one
memory reference
and no special
calculation
Limitation is that it
provides only a
limited address
space
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+
Indirect Addressing
Reference to the address of a word in memory which contains a
full-length address of the operand
EA = (A)
Parentheses are to be interpreted as meaning contents of
Advantage:
For a word length of N an address space of 2N is now available
Disadvantage:
Instruction execution requires two memory references to fetch the operand
One to get its address and a second to get its value
A rarely used variant of indirect addressing is multilevel or cascaded
indirect addressing
EA = ( . . . (A) . . . )
Disadvantage is that three or more memory references could be required
to fetch an operand
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Register Addressing
Address field
refers to a
register rather EA = R
than a main
memory address
Advantages: Disadvantage:
• Only a small • The address space
address field is is very limited
needed in the
instruction
• No time-consuming
memory references
are required
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+
Register Indirect Addressing
Analogous to indirect addressing
The only difference is whether the address field refers to a
memory location or a register
EA = (R)
Address space limitation of the address field is overcome by
having that field refer to a word-length location containing an
address
Uses one less memory reference than indirect addressing
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+
Displacement Addressing
Combines the capabilities of direct addressing and register
indirect addressing
EA = A + (R)
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 refers to a register whose contents are added
to A to produce the effective address
Most common uses:
Relative addressing
Base-register addressing
Indexing
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Relative Addressing
The implicitly referenced register is the program counter (PC)
• The next instruction address is added to the address field to produce the EA
• Typically the address field is treated as a twos complement number for this
operation
• Thus the effective address is a displacement relative to the address of the
instruction
Exploits the concept of locality
Saves address bits in the instruction if most memory references
are relatively near to the instruction being executed
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+
Base-Register Addressing
The referenced register contains a main memory address and
the address field contains a displacement from that address
The register reference may be explicit or implicit
Exploits the locality of memory references
Convenient means of implementing segmentation
In some implementations 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
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Indexing
The address field references a main memory address and the referenced
register contains a positive displacement from that address
The method of calculating the EA is the same as for base-register addressing
An important use is to provide an efficient mechanism for performing
iterative operations
Autoindexing
Automatically increment or decrement the index register after each reference to it
EA = A + (R)
(R) (R) + 1
Postindexing
Indexing is performed after the indirection
EA = (A) + (R)
Preindexing
Indexing is performed before the indirection
EA = (A + (R))
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+
Stack Addressing
A stack is a linear array of locations
Sometimes referred to as a pushdown list or last-in-first-out queue
A stack is a reserved block of locations
Items are appended to the top of the stack so that the block is partially filled
Associated with the stack is a pointer whose value is the address of 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
Is a form of implied addressing
The machine instructions need not include a memory
reference but implicitly operate on the top of the stack
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Table 13.2
x86 Addressing Modes
M ode Algorithm
Immediate Operand = A
Register Operand LA = R
Displacement LA = (SR) + A
Base LA = (SR) + (B)
Base with Displacement LA = (SR) + (B) + A
Scaled Index with Displacement LA = (SR) + (I) ´ S + A
Base with Index and Displacement LA = (SR) + (B) + (I) + A
Base with Scaled Index and Displacement LA = (SR) + (I) ´ S + (B) + A
Relative LA = (PC) + A
LA = linear address
(X) = contents of X
SR = segment register
PC = program counter
A = contents of an address field in the instruction
R = register
B = base register
I = index register
S = scaling factor
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
STRB r0, [r1, #12]
Offset
0xC 0x20C 0x5
r0 Destination
0x5 register
r1 for STR
Original
base register
0x200 0x200
(a) Offset
STRB r0, [r1, #12]!
r1 Offset
Updated
base register 0x20C 0xC 0x20C 0x5
r0 Destination
0x5 register
r1 for STR
Original
base register
0x200 0x200
(b) Preindex
STRB r0, [r1], #12
r1 Offset
Updated
base register 0x20C 0xC 0x20C
r0 Destination
0x5 register
r1 for STR
Original
base register
0x200 0x200 0x5
(c) Postindex
Figure 13.3 ARM Indexing Methods
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+ ARM Data Processing Instruction Addressing
and Branch Instructions
Data processing instructions
Use either register addressing or a mixture of register and
immediate addressing
For register addressing the value in one of the register operands
may be scaled using one of the five shift operators
Branch instructions
The only form of addressing for branch instructions is immediate
Instruction contains 24 bit value
Shifted 2 bits left so that the address is on a word boundary
Effective range ± 32MB from from the program counter
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
LDMxx r10, {r0, r1, r4}
STMxx r10, {r0, r1, r4}
Increment Increment Decrement Decrement
after (IA) before (IB) after (DA) before (DB)
r10
Base register 0x20C (r4) 0x218
(r4) (r1) 0x214
(r1) (r0) 0x210
(r0) (r4) 0x20C
(r1) (r4) 0x208
(r0) (r1) 0x204
(r0) 0x200
Figure 13.4 ARM Load/Store Multiple Addressing
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Instruction Formats
Must include
Define the
an opcode For most
layout of the
and, implicitly instruction
bits of an
or explicitly, sets more than
instruction, in
indicate the one
terms of its
addressing instruction
constituent
mode for each format is used
fields
operand
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+
Instruction Length
Most basic design issue
Affects, and is affected by:
Memory size
Memory organization
Bus structure
Processor complexity
Processor speed
Should be equal to the memory-transfer length or one should
be a multiple of the other
Should be a multiple of the character length, which is usually
8 bits, and of the length of fixed-point numbers
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Allocation of Bits
Number of Register
Number of
addressing versus
operands
modes memory
Number of Address Address
register sets range granularity
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
M emory Reference I nstructions
Opcode D/I Z/C Displacement
0 2 3 4 5 11
I nput/Output I nstructions
1 1 0 Device Opcode
0 2 3 8 9 11
Register Reference I nstructions
Group 1 Microinstructions
1 1 1 0 CLA CLL CMA CML RAR RAL BSW IAC
0 1 2 3 4 5 6 7 8 9 10 11
Group 2 Microinstructions
1 1 1 1 CLA SMA SZA SNL RSS OSR HLT 0
0 1 2 3 4 5 6 7 8 9 10 11
Group 3 Microinstructions
1 1 1 1 CLA MQA 0 MQL 0 0 0 1
0 1 2 3 4 5 6 7 8 9 10 11
D/I = Direct/Indirect address IAC = Increment ACcumulator
Z/C = Page 0 or Current page SMA = Skip on Minus Accumulator
CLA = Clear Accumulator SZA = Skip on Zero Accumulator
CLL = Clear Link SNL = Skip on Nonzero Link
CMA = CoMplement Accumulator RSS = Reverse Skip Sense
CML = CoMplement Link OSR = Or with Switch Register
RAR = Rotate Accumultator Right HLT = HaLT
RAL = Rotate Accumulator Left MQA = Multiplier Quotient into Accumulator
BSW = Byte SWap MQL = Multiplier Quotient Load
Figure 13.5 PDP-8 I nstruction Formats
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Index
Opcode Register I Memory Address
Register
0 8 9 12 14 17 18 35
I = indirect bit
Figure 13.6 PDP-10 I nstruction Format
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+
Variable-Length Instructions
Variations can be provided efficiently and compactly
Increases the complexity of the processor
Does not remove the desirability of making all of the
instruction lengths integrally related to word length
Because the processor does not know the length of the next
instruction to be fetched a typical strategy is to fetch a number of
bytes or words equal to at least the longest possible instruction
Sometimes multiple instructions are fetched
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
1 Opcode Source Destination 2 Opcode R Source 3 Opcode Offet
4 6 6 7 3 6 8 8
4 Opcode FP Destination 5 Opcode Destination 6 Opcode CC
8 2 6 10 6 12 4
7 Opcode R 8 Opcode
13 3 16
9 Opcode Source Destination Memory Address
4 6 6 16
10 Opcode R Source Memory Address
7 3 6 16
11 Opcode FP Source Memory Address
8 2 6 16
12 Opcode Destination Memory Address
10 6 16
13 Opcode Source Destination Memory Address 1 Memory Address 2
4 6 6 16 16
Numbers below fields indicate bit length
Source and Destination each contain a 3-bit addr essing mode field and a 3-bit register number
FP indicates one of four floating-point registers
R indicates one of the general-purpose r egisters
CC is the condition code field
Figure 13.7 Instruction Formats for the PDP-11
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Hexadecimal Explanation Assembler Notation
Format and Description
8 bits
0 5 Opcode for RSB RSB
Return from subroutine
D 4 Opcode for CLRL CLRL R9
5 9 Register R9 Clear register R9
B 0 Opcode for MOVW MOVW 356(R4), 25(R11)
Word displacement mode,
C 4 Register R4
Move a word from address
that is 356 plus contents
6 4 356 in hexadecimal of R4 to address that is
0 1 25 plus contents of R11
Byte displacement mode,
A B Register R11
1 9 25 in hexadecimal
C 1 Opcode for ADDL3 ADDL3 #5, R0, @A[R2]
0 5 Short literal 5 Add 5 to a 32-bit integer in
R0 and store the result in
5 0 Register mode R0
location whose address is
4 2 Index prefix R2 sum of A and 4 times the
Indirect word relative contents of R2
D F (displacement from PC)
Amount of displacement from
PC relative to location A
Figure 13.8 Examples of VAX Instructions
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
0 or 1 0 or 1 0 or 1 0 or 1
bytes bytes bytes bytes
Operand Address
Instruction Segment
size size
prefix override
override override
0 or 1 0 or 1
0, 1, 2, 3, or 4 bytes 1, 2, or 3 bytes bytes bytes 0, 1, 2, or 4 bytes 0, 1, 2, or 4 bytes
Instruction prefixes Opcode ModR/m SIB Displacement Immediate
Mod Reg/Opcode R/M Scale Index Base
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
Figure 13.9 x86 Instruction Format
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+
Thumb-2 Instruction Set
The only instruction set available on the Cortex-M microcontroller
products
Is a major enhancement to the Thumb instruction set architecture (ISA)
Introduces 32-bit instructions that can be intermixed freely with the older 16-
bit Thumb instructions
Most 32-bit Thumb instructions are unconditional, whereas almost all ARM
instructions can be conditional
Introduces a new If-Then (IT) instruction that delivers much of the functionality
of the condition field in ARM instructions
Delivers overall code density comparable with Thumb, together with the
performance levels associated with the ARM ISA
Before Thumb-2 developers had to choose between Thumb for size and
ARM for performance
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Address Contents Address Contents
101 0010 0010 101 2201 101 2201
102 0001 0010 102 1202 102 1202
103 0001 0010 103 1203 103 1203
104 0011 0010 104 3204 104 3204
201 0000 0000 201 0002 201 0002
202 0000 0000 202 0003 202 0003
203 0000 0000 203 0004 203 0004
204 0000 0000 204 0000 204 0000
(a) Binary program (b) Hexadecimal program
Address I nstruction Label Operation Operand
101 LDA 201 FORMUL LDA I
102 ADD 202 ADD J
103 ADD 203 ADD K
104 STA 204 STA N
201 DAT 2 I DATA 2
202 DAT 3 J DATA 3
203 DAT 4 K DATA 4
204 DAT 0 N DATA 0
(c) Symbolic program (d) Assembly program
Figure 13.14 Computation of the Formula N = I + J+ K
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+ Summary Instruction Sets:
Addressing Modes
and Formats
Chapter 13
x86 addressing modes
Addressing modes
ARM addressing modes
Immediate addressing
Direct addressing Instruction formats
Indirect addressing Instruction length
Register addressing Allocation of bits
Register indirect addressing Variable-length instructions
Displacement addressing
X86 instruction formats
Stack addressing
ARM instruction formats
Assembly language
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.