CH14r-COA11e
CH14r-COA11e
Chapter 14
Instruction Sets:
Addressing Modes and
Formats
Addressing Modes
Immediate
Direct
Indirect
Register
Register indirect
Displacement
Stack
2
Figure 14.1
Addressing Modes
3
Table 14.1
Basic Addressing Modes
Mode Algorithm Principal Advantage Principal Disadvantage
4
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
5
most instruction sets, is small compared with the word length
Direct Addressing
Address field
contains the
effective address
of the operand
Effective address
(EA) = address
field (A)
Was common in
earlier
generations of
computers
Limitation is that
it provides only a
limited address
space
6
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
7
Register Addressing
Address field
refers to a
register rather
EA = R
than a main
memory
address
Advantages: Disadvantage:
• Only a small • The address
address field is space is very
needed in the limited
instruction
• No time-
consuming
memory
references are
required
8
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
9
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
• Postindexing
– Indexing is performed after the indirection
– EA = (A) + (R)
• Preindexing
– Indexing is performed before the indirection 13
– EA = (A + (R))
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
14
Figure 14.2
x86 Addressing Mode Calculation
15
Table 14.2
x86 Addressing Modes
Mode Algorithm
Immediate Operand = A
Register Operand LA = R
Displacement LA = (SR) + A
16
Figure 14.3
ARM Indexing Methods
17
ARM Data Processing Instruction Addressing
and Branch Instructions
• 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
18
Figure 14.4
ARM Load/Store Multiple Addressing
19
Instruction Formats
Must include an
Define the layout opcode and, For most
of the bits of an implicitly or instruction sets
instruction, in explicitly, more than one
terms of its indicate the instruction
constituent fieldsaddressing mode format is used
for each operand
20
Instruction Length
• Most basic design issue
• Affects, and is affected by:
– Memory size
– Memory organization
– Bus structure
– Processor complexity
– Processor speed
Number of Register
Number of
addressing versus
operands
modes memory
Number of
Address Address
register
range granularity
sets
22
Figure 14.5
PDP-8 Instruction Formats
23
Figure 14.6
PDP-10 Instruction Format
24
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
25
Figure 14.7
Instruction Formats for the PDP-11
26
Figure 14.8
Example of VAX Instructions
27
Figure 14.9
x86 Instruction Format
28
Figure 14.10
ARM Instruction Formats
29
Figure 14.11
Examples of Use of ARM Immediate
Constants
30
Figure 14.12
Expanding a Thumb ADD Instruction into
its ARM Equivalent
31
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
32
Figure 14.13
Thumb-2 Encoding
33
• Instruction Sets:
Summary Addressing Modes
and Formats
Chapter 14
• x86 addressing modes
• Addressing modes • ARM addressing modes
– Immediate addressing
– Direct addressing • Instruction formats
– Instruction length
– Indirect addressing
– Allocation of bits
– Register addressing
– Variable-length
– Register indirect instructions
addressing
– Displacement • X86 instruction formats
addressing • ARM instruction formats
– Stack addressing
34