Docsity

instruction set addressing modes, Slides of Computer Architecture and Organization

Partial preview of the text

Download instruction set addressing modes and more Slides Computer Architecture and Organization in PDF only on Docsity!

Instruction Sets -

Addressing Modes and

Formats

Addressing Modes

◼ Addressing modes are an aspect of the instruction

set architecture in most Central Processing Unit

(CPU) designs.

◼ The various addressing modes define how the

machine language instructions in that architecture

identify the operand of each instruction

(b) Direct Memory Instruction A A Operand (a) Immediate Instruction Operand Registers (d) Register Instruction R R (c) Indirect Memory Instruction Registers (f) Displacement Memory Instruction R A Registers (e) Register Indirect Memory Instruction Top of Stack Register (g) Stack Implicit Instruction Operand Operand Operand Operand 4

Notation

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

Immediate Addressing

◼ Simplest form of addressing
Operand = A

◼ e.g. ADD 5

◼ Add 5 to contents of accumulator

◼ This mode can be used to define and use constants or set initial
values of variables

◼ 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

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

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

Indirect Addressing Diagram Address

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 ◼ Most common uses: ◼ Relative addressing ◼ Base-register addressing ◼ Indexing

Relative Addressing

The implicitly referenced register is the program counter (PC) EA = A + (PC)

  • The next instruction address is added to the address field to produce the EA
  • 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

Base-Register Addressing

  • A holds displacement
  • R holds pointer to base address
◼ 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
◼ 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

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

  • The stack pointer is maintained in a register
  • Or, the top two elements of the stack may be in processor registers e.g. ADD ◼ Pop top two items from stack and add ◼ The machine instructions need not include a memory reference but implicitly operate on the top of the stack

Stack Addressing

Example: 5 + 3 – (2 * 1)