Ch_10_95

Embed Size (px)

Citation preview

  • 7/27/2019 Ch_10_95

    1/25

    William Stallings

    Computer Organizationand Architecture

    Chapter 10

    Instruction Sets:

    Addressing Modes

    and Formats

  • 7/27/2019 Ch_10_95

    2/25

    Addressing Modes

    Immediate

    Direct

    IndirectRegister

    Register Indirect

    Displacement (Indexed)Stack

  • 7/27/2019 Ch_10_95

    3/25

    Immediate Addressing

    Operand is part of instruction

    Operand = address field

    e.g. ADD 5Add 5 to contents of accumulator

    5 is operand

    No memory reference to fetch data

    Fast

    Limited range

  • 7/27/2019 Ch_10_95

    4/25

    Immediate Addressing Diagram

    OperandOpcode

    Instruction

  • 7/27/2019 Ch_10_95

    5/25

  • 7/27/2019 Ch_10_95

    6/25

    Direct Addressing Diagram

    Address AOpcode

    Instruction

    Memory

    Operand

  • 7/27/2019 Ch_10_95

    7/25

    Indirect Addressing (1)

    Memory cell pointed to by address field containsthe address of (pointer to) the operand

    EA = (A)Look in A, find address (A) and look there for

    operand

    e.g. ADD (A)

    Add contents of cell pointed to by contents of A toaccumulator

  • 7/27/2019 Ch_10_95

    8/25

    Indirect Addressing (2)

    Large address space

    2n where n = word length

    May be nested, multilevel, cascadede.g. EA = (((A)))

    Draw the diagram yourself

    Multiple memory accesses to find operand

    Hence slower

  • 7/27/2019 Ch_10_95

    9/25

    Indirect Addressing Diagram

    Address AOpcode

    Instruction

    Memory

    Operand

    Pointer to operand

  • 7/27/2019 Ch_10_95

    10/25

    Register Addressing (1)

    Operand is held in register named in addressfiled

    EA = RLimited number of registers

    Very small address field needed

    Shorter instructions

    Faster instruction fetch

  • 7/27/2019 Ch_10_95

    11/25

    Register Addressing (2)

    No memory access

    Very fast execution

    Very limited address space

    Multiple registers helps performanceRequires good assembly programming or compiler

    writing

    N.B. C programming

    register int a;

    c.f. Direct addressing

  • 7/27/2019 Ch_10_95

    12/25

    Register Addressing Diagram

    Register Address ROpcode

    Instruction

    Registers

    Operand

  • 7/27/2019 Ch_10_95

    13/25

    Register Indirect Addressing

    C.f. indirect addressing

    EA = (R)

    Operand is in memory cell pointed to bycontents of register R

    Large address space (2n)

    One fewer memory access than indirectaddressing

  • 7/27/2019 Ch_10_95

    14/25

    Register Indirect Addressing Diagram

    Register Address ROpcode

    Instruction

    Memory

    OperandPointer to Operand

    Registers

  • 7/27/2019 Ch_10_95

    15/25

    Displacement Addressing

    EA = A + (R)

    Address field hold two values

    A = base valueR = register that holds displacement

    or vice versa

  • 7/27/2019 Ch_10_95

    16/25

    Displacement Addressing Diagram

    Register ROpcode

    Instruction

    Memory

    OperandPointer to Operand

    Registers

    Address A

    +

  • 7/27/2019 Ch_10_95

    17/25

    Relative Addressing

    A version of displacement addressing

    R = Program counter, PC

    EA = A + (PC) i.e. get operand from A cells from current

    location pointed to by PC

    c.f locality of reference & cache usage

  • 7/27/2019 Ch_10_95

    18/25

    Base-Register Addressing

    A holds displacement

    R holds pointer to base address

    R may be explicit or implicite.g. segment registers in 80x86

  • 7/27/2019 Ch_10_95

    19/25

    Indexed Addressing

    A = base

    R = displacement

    EA = A + RGood for accessing arrays

    EA = A + R

    R++

  • 7/27/2019 Ch_10_95

    20/25

    Combinations

    Postindex

    EA = (A) + (R)

    Preindex

    EA = (A+(R))

    (Draw the diagrams)

  • 7/27/2019 Ch_10_95

    21/25

    Stack Addressing

    Operand is (implicitly) on top of stack

    e.g.

    ADD Pop top two items from stackand add

  • 7/27/2019 Ch_10_95

    22/25

    Instruction Formats

    Layout of bits in an instruction

    Includes opcode

    Includes (implicit or explicit) operand(s)Usually more than one instruction format in an

    instruction set

  • 7/27/2019 Ch_10_95

    23/25

    Instruction Length

    Affected by and affects:

    Memory size

    Memory organization

    Bus structure

    CPU complexity

    CPU speed

    Trade off between powerful instructionrepertoire and saving space

  • 7/27/2019 Ch_10_95

    24/25

    Allocation of Bits

    Number of addressing modes

    Number of operands

    Register versus memoryNumber of register sets

    Address range

    Address granularity

  • 7/27/2019 Ch_10_95

    25/25

    Foreground Reading

    Stallings chapter 10

    Intel and PowerPC Web sites