Processor Organization and Architecture Module III.

Post on 24-Dec-2015

217 views 1 download

Transcript of Processor Organization and Architecture Module III.

Processor Organization and Architecture

Module III

Addressing Modes

• How to specify operands• The different modes are:– Immediate– Direct– Indirect– Register– Register Indirect– Displacement (Indexed) – Stack

Immediate Addressing• Operand is part of instruction• e.g. ADD 5– Add 5 to contents of accumulator– 5 is operand

• Adv:– No memory reference to fetch data– Fast

• Disadv:– Limited range

Immediate Addressing

OperandOpcode

Instruction

Direct Addressing

• Address field contains effective address of operand

• e.g. ADD A– Look in memory at address A for operand

• Adv:– Single memory reference to access data– No additional calculations to work out effective

address• Disadv: Limited address space

Direct Addressing

Address AOpcode

Instruction

Memory

Operand

Indirect Addressing

• Memory cell pointed to by address field contains the 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 to accumulator

Indirect Addressing

• Adv:– Large address space – 2n where n = word length– May be nested, multilevel, cascaded• e.g. EA = (((A)))

• Disadv: Multiple memory accesses to find operand and hence slower

Indirect Addressing

Address AOpcode

Instruction

Memory

Operand

Pointer to operand

Register Addressing

• Address field refers to a register• EA = R• Adv:– Only a small address field is needed in the

instruction– Less access time

• Disadv:– Limited number of registers– Limited address space

Register Addressing

Register Address ROpcode

Instruction

Registers

Operand

Register Indirect Addressing

• Similar to indirect addressing• EA = (R)• Operand is in memory cell pointed to by

contents of register R• One fewer memory access than indirect

addressing

Register Indirect Addressing

Register Address ROpcode

Instruction

Memory

OperandPointer to Operand

Registers

Displacement Addressing

• Combines direct and register indirect addressing

• EA = A + (R)• Address field hold two values– A = base value– R = register that holds displacement– or vice versa

Displacement Addressing

Register ROpcode

Instruction

Memory

OperandPointer to Operand

Registers

Address A

+

Uses of Displacement Addressing

• Relative Addressing• Base-Register Addressing• Indexed Addressing

Relative Addressing

• R = Program counter, PC• EA = A + (PC)• i.e. get operand from A cells from current

location pointed to by PC• Exploits locality of reference• If memory references are near to the

instruction being executed, this saves address bits in the instruction

Base-Register Addressing

• The referenced register (R) may contain– A main memory address – Displacement from that address

• R may be explicit or implicit• Exploits locality of reference

Indexed Addressing

• just opposite of base register addressing• Address field contains main memory address

A = base• Register contains displacement

R = displacement• EA = A + R• Good for accessing arrays

Stack Addressing

• Stack is a reserved block of locations• Stack pointer holds the address of the top of

the stack.• It is a form of implied addressing: as no

memory reference is required but operate on the top of the stack

Instruction Formats

• Defines the layout of bits in an instruction• Includes opcode & (implicit or explicit)

operand(s)• Usually more than one instruction format in

an instruction set

Common Instruction Formats

• Four of them area) Zero-address instructionb) One-address instructionc) Two-address instructiond) Three-address instruction

Zero-address instruction

• 0 (zero) addresses– All addresses implicit– Example: stack• push a• push b• pop c

One-address instruction

• 1 address– Implicit second address : Usually a register

(accumulator)– E.g. Add C // C=C+A(accumulator)

Two-address instruction

• 2 addresses– One address doubles as operand and result– a = a + b– Reduces length of instruction– Requires temporary storage to hold some results

Three-address instruction

• 3 addresses– Operand 1, Operand 2, Result– a = b + c;– May be a forth - usually implicit– Not common– Needs very long words to hold everything