6.Week
6.Week
3. Instruction sets
—Instruction Sets: Characteristics and Functions
—Instruction Sets: Addressing Modes and Formats
—Assembly Language and Related Topics
+
3.2 Instruction Sets: Addressing
Modes and Formats
3.2 Outline
• Addressing Modes
• x86 and ARM Addressing Modes
• Instruction Formats
• x86 and ARM Instruction Formats
Addressing Modes
Immediate
Direct
Indirect
Register
Register indirect
Displacement
Stack
Addressing Modes
Instruction Instruction Instruction
Operand A A
Memory Memory
Operand
Operand
Operand
Operand Operand
Registers Registers Registers
(d) Register (e) Register Indirect (f) Displacement
Instruction
Implicit
A = contents of an address field in the instruction
R = contents of an address field in the instruction that refers to a
Top of Stack
Register register
(g) Stack
• 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
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
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
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
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
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
– 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
(a) Offset
r1 Offset
Updated
base register 0x20C 0xC 0x20C 0x5
r0 Destination
0x5 register
r1 for STR
Original
base register
0x200 0x200
(b) Preindex
r1 Offset
Updated
base register 0x20C 0xC 0x20C
r0 Destination
0x5 register
r1 for STR
Original
base register
0x200 0x200 0x5
(c) Postindex
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
ARM Load/Store Multiple Addressing
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
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
I nput/Output I nstructions
1 1 0 Device Opcode
0 2 3 8 9 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
Index
Opcode Register I Memory Address
Register
0 8 9 12 14 17 18 35
I = indirect bit
7 Opcode R 8 Opcode
13 3 16
8 bits
0 5 Opcode for RSB RSB
Return from subroutine
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