+
Instruction Sets:
Chapter 13 Addressing Modes and
Formats
William Stallings, Computer Organization and Architecture, 9 th Edition
+ 2
Objectives
After studying this chapter, you should be able to:
Describe the various types of addressing modes common in
instruction sets.
Present an overview of x86 and ARM addressing modes (ARM:
Advanced RISC Machine, RISC: Reduced Instruction Set
Computer).
Summarize the issues and trade-offs involved in designing an
instruction format.
Present an overview of x86 and ARM instruction formats.
Understand the distinction between machine language and
assembly language.
+ 3
Contents
13.1 Addressing Modes
13.3 Instruction Formats
13.5 Assembly Language
+ 4
13.1- Addressing Modes
Immediate
Direct
Ways to specify an operand
Indirect
in an instruction:
Register
Register indirect
Displacement (replace)
Stack
+
Addressing Immediate :
Operand is a
Direct :
Operand is the
value of a
Modes specific value
variable
Indirect : Operand
Register : Operand is
address is stored in
a specific register
another variable
Displacement :
Register Indirect : Replace the value of a
Operand address is variable with an
stored in a register expression
Implicit : Operand
address is stored in
stack register
+ 6
Basic Addressing Modes
A = contents of an address field in the instruction
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 memory location X or register X
+ 7
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
Direct Addressing
8
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
+ 9
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
+ 10
Register Addressing
Address
field refers to a register rather than a main
memory address
EA = R
Advantages:
Only a small address field is needed in the instruction
No time-consuming memory references are required
Disadvantage:
The address space is very limited
+ 11
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
+ 12
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
+ 13
Relative Addressing
Theimplicitly 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
Savesaddress bits in the instruction if most memory
references are relatively near to the instruction being
executed
+ 14
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
+ Indexed Addressing 15
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))
+ 16
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
Must include an
For most opcode and, Define the layout
instruction sets implicitly or of the bits of an
more than one explicitly, indicate instruction, in
instruction format the addressing terms of its
is used mode for each constituent fields
operand
17
13.3- Instruction Formats
+ Instruction Length 18
Most basic design issue
Affects, and is affected by:
Memory size
Memory organization
Bus structure
Processor complexity
Processor speed
Shouldbe 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
+ 19
Allocation of Bits
Number of addressing modes
Number of operands
Register versus memory
Number of register sets
Address range
Address granularity (cốt lõi)
PDP-8 Instruction Format 20
+ 21
PDP-10 Instruction Format
+ Variable-Length Instructions 22
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
PDP-11 Instruction Format 23
+
VAX Instruction
Examples
x86 Instruction Format 25
13.5- Assembly Language 26
Consider the simple BASIC statement: N = I + J + K
Suppose we wished to program this statement in machine language
and to initialize I, J, and K to 2, 3, and 4, respectively.
This is shown in Figure 13.13a. (next slide)
The program starts in location 101 (hexadecimal). Memory is
reserved for the four variables starting at location 201.
The program consists of four instructions:
1. Load the contents of location 201 into the AC ( variable I)
2. Add the contents of location 202 to the AC (J)
3. Add the contents of location 203 to the AC.(K)
4. Store the contents of the AC in location 204(N)
This is clearly a tedious (buồn tẻ) and very error-prone (dễ mắc lỗi) process.
Assembly Language
Assembler – Assembly Compiler 27
How can we understand
it?
More understandable
More readable
( Assembly program
looks like this)
Assembly Language (Wiki) 28
• Assembly language (or assembler language) is a low-level
programming language for a computer, or other programmable
device
• There is a very strong (generally one-to-one) correspondence
between the language and the architecture's machine
code instructions.
• Each assembly language is specific to a particular computer
architecture, in contrast to most high-level programming languages,
which are generally portable across multiple architectures, but
require interpreting or compiling.
• Assembly language is converted into executable machine code by
a utility program referred to as an assembler; the conversion process
is referred to as assembly, or assembling the code.
Assembly Language (Wiki)... 29
• Assembly language uses a mnemonic to represent each low-
level machine instruction or operation. Typical operations
require one or more operands in order to form a complete
instruction, and most assemblers can therefore take labels,
symbols and expressions as operands to represent addresses and
other constants, freeing the programmer from tedious manual
calculations.
• Macro assemblers include a macro instruction facility so that
(parameterized) assembly language text can be represented by a
name, and that name can be used to insert the expanded text into
other code.
• Many assemblers offer additional mechanisms to facilitate
program development, to control the assembly process, and to
aid debugging.
Exercises 30
13.1 Briefly define immediate addressing.
13.2 Briefly define direct addressing.
13.3 Briefly define indirect addressing.
13.4 Briefly define register addressing.
13.5 Briefly define register indirect addressing.
13.6 Briefly define displacement addressing.
13.7 Briefly define relative addressing.
13.8 What is the advantage of autoindexing?
13.9 What is the difference between postindexing and
preindexing?
13.10 What facts go into determining the use of the addressing
bits of an instruction?
13.11 What are the advantages and disadvantages of using a
variable-length instruction format?
+ Summary Instruction Sets:
31
Addressing Modes and
Chapter 13 Formats
Addressing modes
Immediate addressing Instruction formats
Direct addressing Instruction length
Indirect addressing Allocation of bits
Register addressing Variable-length
Register indirect instructions
addressing Instruction to Assembly
Displacement
language
addressing
Stack addressing