25
1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

Embed Size (px)

Citation preview

Page 1: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

1

William Stallings Computer Organization and Architecture

Chapter 10Instruction Sets:Addressing Modesand Formats

Page 2: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

2

Addressing Modes

ImmediateDirectIndirectRegisterRegister IndirectDisplacement (Indexed) Stack

Page 3: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

3

Immediate Addressing

Operand is part of instructionOperand = address fielde.g. ADD 5

Add 5 to contents of accumulator 5 is operand

No memory reference to fetch dataFastLimited range

Page 4: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

4

Immediate Addressing Diagram

OperandOpcode

Instruction

Page 5: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

5

Direct AddressingAddress field contains address of operandEffective address (EA) = address field (A)e.g. ADD A

Add contents of cell A to accumulator Look in memory at address A for operand

Single memory reference to access data

No additional calculations to work out effective address

Limited address space

Page 6: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

6

Direct Addressing Diagram

Address AOpcode

Instruction

Memory

Operand

Page 7: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

7

Indirect Addressing (1)

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: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

8

Indirect Addressing (2)

Large address space 2n where n = word lengthMay be nested, multilevel, cascaded

e.g. EA = (((A)))Draw the diagram yourself

Multiple memory accesses to find operandHence slower

Page 9: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

9

Indirect Addressing Diagram

Address AOpcode

Instruction

Memory

Operand

Pointer to operand

Page 10: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

10

Register Addressing (1)

Operand is held in register named in address filed

EA = RLimited number of registersVery small address field needed

Shorter instructions Faster instruction fetch

Page 11: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

11

Register Addressing (2)No memory accessVery fast executionVery limited address spaceMultiple registers helps performance

Requires good assembly programming or compiler writing

N.B. C programming register int a;

c.f. Direct addressing

Page 12: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

12

Register Addressing Diagram

Register Address ROpcode

Instruction

Registers

Operand

Page 13: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

13

Register Indirect Addressing

C.f. indirect addressingEA = (R)Operand is in memory cell pointed to by

contents of register RLarge address space (2n)One fewer memory access than indirect

addressing

Page 14: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

14

Register Indirect Addressing Diagram

Register Address ROpcode

Instruction

Memory

OperandPointer to Operand

Registers

Page 15: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

15

Displacement Addressing

EA = A + (R)Address field hold two values

A = base value R = register that holds displacement or vice versa

Page 16: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

16

Displacement Addressing Diagram

Register ROpcode

Instruction

Memory

OperandPointer to Operand

Registers

Address A

+

Page 17: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

17

Relative Addressing

A version of displacement addressingR = Program counter, PCEA = A + (PC)i.e. get operand from A cells from current

location pointed to by PCc.f locality of reference & cache usage

Page 18: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

18

Base-Register Addressing

A holds displacementR holds pointer to base addressR may be explicit or implicite.g. segment registers in 80x86

Page 19: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

19

Indexed Addressing

A = baseR = displacementEA = A + RGood for accessing arrays

EA = A + R R++

Page 20: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

20

Combinations

PostindexEA = (A) + (R)

PreindexEA = (A+(R))

(Draw the diagrams)

Page 21: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

21

Stack Addressing

Operand is (implicitly) on top of stacke.g.

ADD Pop top two items from stackand add

Page 22: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

22

Instruction Formats

Layout of bits in an instructionIncludes opcodeIncludes (implicit or explicit) operand(s)Usually more than one instruction format

in an instruction set

Page 23: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

23

Instruction Length

Affected by and affects: Memory size Memory organization Bus structure CPU complexity CPU speed

Trade off between powerful instruction repertoire and saving space

Page 24: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

24

Allocation of Bits

Number of addressing modesNumber of operandsRegister versus memoryNumber of register setsAddress rangeAddress granularity

Page 25: 1 William Stallings Computer Organization and Architecture Chapter 10 Instruction Sets: Addressing Modes and Formats

25

Foreground Reading

Stallings chapter 10Intel and PowerPC Web sites