Processor Organization and Architecture Module III.

26
Processor Organization and Architecture Module III

Transcript of Processor Organization and Architecture Module III.

Page 1: Processor Organization and Architecture Module III.

Processor Organization and Architecture

Module III

Page 2: 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

Page 3: Processor Organization and Architecture Module III.

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

Page 4: Processor Organization and Architecture Module III.

Immediate Addressing

OperandOpcode

Instruction

Page 5: Processor Organization and Architecture Module III.

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

Page 6: Processor Organization and Architecture Module III.

Direct Addressing

Address AOpcode

Instruction

Memory

Operand

Page 7: Processor Organization and Architecture Module III.

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

Page 8: Processor Organization and Architecture Module III.

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

Page 9: Processor Organization and Architecture Module III.

Indirect Addressing

Address AOpcode

Instruction

Memory

Operand

Pointer to operand

Page 10: Processor Organization and Architecture Module III.

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

Page 11: Processor Organization and Architecture Module III.

Register Addressing

Register Address ROpcode

Instruction

Registers

Operand

Page 12: Processor Organization and Architecture Module III.

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

Page 13: Processor Organization and Architecture Module III.

Register Indirect Addressing

Register Address ROpcode

Instruction

Memory

OperandPointer to Operand

Registers

Page 14: Processor Organization and Architecture Module III.

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

Page 15: Processor Organization and Architecture Module III.

Displacement Addressing

Register ROpcode

Instruction

Memory

OperandPointer to Operand

Registers

Address A

+

Page 16: Processor Organization and Architecture Module III.

Uses of Displacement Addressing

• Relative Addressing• Base-Register Addressing• Indexed Addressing

Page 17: Processor Organization and Architecture Module III.

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

Page 18: Processor Organization and Architecture Module III.

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

Page 19: Processor Organization and Architecture Module III.

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

Page 20: Processor Organization and Architecture Module III.

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

Page 21: Processor Organization and Architecture Module III.

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

Page 22: Processor Organization and Architecture Module III.

Common Instruction Formats

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

Page 23: Processor Organization and Architecture Module III.

Zero-address instruction

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

Page 24: Processor Organization and Architecture Module III.

One-address instruction

• 1 address– Implicit second address : Usually a register

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

Page 25: Processor Organization and Architecture Module III.

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

Page 26: Processor Organization and Architecture Module III.

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