2.2 microarchitecture 2.2b – instruction phases

40
Required : PM: Ch 8.1-3, pgs 109- 114 Recommended : Wiki : Microarchitecture Wiki : Addressing_mode Wiki : Three-state logic 2.2 Microarchitecture 2.2b – Instruction Phases

Upload: wylie

Post on 04-Jan-2016

52 views

Category:

Documents


0 download

DESCRIPTION

2.2 Microarchitecture 2.2b – Instruction Phases. Required :PM : Ch 8.1-3, pgs 109-114 Recommended : Wiki : Microarchitecture Wiki : Addressing_mode Wiki : Three-state logic. Learning Objectives…. After watching this video and studying the reading assignments, you should be able to: - PowerPoint PPT Presentation

TRANSCRIPT

Page 2: 2.2 Microarchitecture 2.2b  –  Instruction Phases

ISA 2

Learning Objectives…

After watching this video and studying the reading assignments, you should be able to:

Describe computer instruction cycles. Explain the purpose of the fetch cycle. Understand the cycle relationship to addressing modes. Explain the difference between PC-relative and absolute

addressing modes.

BYU CS 124

Page 3: 2.2 Microarchitecture 2.2b  –  Instruction Phases

Instruction Cycles

Page 4: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 4

The Instruction Cycle

INSTRUCTION FETCH Obtain the next instruction from memory

DECODE Examine the instruction, and determine how to execute it

SOURCE OPERAND FETCH Load source operand

DESTINATION OPERAND FETCH Load destination operand

EXECUTE Carry out the execution of the instruction

STORE RESULT Store the result in the designated destination

Not all instructions require all six

phases

Instruction Cycle

Page 5: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 5

Fetching an Instruction

PC

Fetch Cycle

PC can be incremented

anytime during the

Fetch phase

Page 6: 2.2 Microarchitecture 2.2b  –  Instruction Phases

MSP430 Microarchitecture 6BYU CS 124

Addressing Modes

The MSP430 has four basic addressing modes: 00 = Rs - Register 01 = x(Rs) - Indexed Register 10 = @Rs - Register Indirect (source only) 11 = @Rs+ - Indirect Auto-increment (source only)

When used in combination with registers R0-R3, three additional source addressing modes are available: label - PC Relative, x(PC) &label – Absolute, x(SR) #n – Immediate, @PC+ (source only)

Addressing Modes

Page 7: 2.2 Microarchitecture 2.2b  –  Instruction Phases

MSP430 Microarchitecture 7

Addressing Mode Demo

BYU CS 124

Addressing Modes

.textstart:

add.w r4,r10 ; r4 += r10;add.w 6(r4),r10 ; r10 += M[r4+6];add.w @r4,r10 ; r10 += M[r4];add.w @r4+,r10 ; r10 += M[r4++];add.w cnt,r10 ; r10 += cnt;add.w &cnt,r10 ; r10 += cnt;add.w #100,r10 ; r10 += 100;add.w #1,r10 ; r10++;push cnt ; M[--r1] = cnt;jmp start

cnt: .word 0x000a

8000: 540A8002: 541A 00068006: 542A8008: 543A800a: 501A 0012800e: 521A 801e8012: 503A 00648016: 531A8018: 1210 0004801c: 3ff1

801e: 000a

Page 8: 2.2 Microarchitecture 2.2b  –  Instruction Phases

MSP430 Microarchitecture 8BYU CS 124

00 = Register ModeAddressing Modes

Registers

CPUMemory

ADDER

add.w r4,r10 ; r10 += r4

PCPC

R10

R4

IRData Bus (1

cycle)0x540

a0x540a PC

ALU

Address Bus

+2

Page 9: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 9

Source: Register Mode – Rs

Rs

Evaluate Source Operand

Select the source

register

Page 10: 2.2 Microarchitecture 2.2b  –  Instruction Phases

MSP430 Microarchitecture 10

Memory

BYU CS 124

01 = Indexed ModeAddressing Modes

Registers

Address Bus

Data Bus (+1 cycle)

Data Bus (+1 cycle)

CPU

ADDER

add.w 6(r4),r10 ; r10 += M[r4+6]

0x0006

PCPCPC

R10

R4

IRData Bus (1

cycle)0x541

a0x541a PC

ALU

Address

Bus

+2+2

Page 11: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 11

Source: Indexed Mode – x(Rs)

Rs

PC

PC

PC incremented

at end of phase

Evaluate Source Operand

Use PC to obtain index,

use Rs for base register

Page 12: 2.2 Microarchitecture 2.2b  –  Instruction Phases

MSP430 Microarchitecture 12

Memory

BYU CS 124

10 = Indirect Register ModeAddressing Modes

Registers

Address Bus

Data Bus (+1 cycle)

CPU

ADDER

add.w @r4,r10 ; r10 = M[r4]

PCPC

R10

R4

IRData Bus (1

cycle)0x542

a

Address Bus

0x542a PC

ALU

+2

Page 13: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 13

Source: Indirect Mode – @Rs

Rs

Evaluate Source Operand

Page 14: 2.2 Microarchitecture 2.2b  –  Instruction Phases

MSP430 Microarchitecture 14

Memory

BYU CS 124

Addressing Modes

Registers

Data Bus (+1 cycle)

CPU

ADDER

11 = Indirect Auto-increment Mode

add.w @r4+,r10 ; r10 += M[r4++]

PCPC

R10

R4

IRData Bus (1

cycle)0x543

a

Address Bus

PC0x543

a

Address Bus0002

ALU

+2

Page 15: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 15

Source: Indirect Auto Mode – @Rs+

Rs

Evaluate Source Operand

Increment by 1 (.b) or 2

(.w)

Page 16: 2.2 Microarchitecture 2.2b  –  Instruction Phases

MSP430 Microarchitecture 16

Memory

BYU CS 124

Addressing Modes

Registers

Address Bus

Data Bus (+1 cycle)

Data Bus (+1 cycle)

CPU

ADDER

01 w/R0 = Symbolic Mode

cnt

add.w cnt,r10 ; r10 += M[cnt]

0x000c

PCPCPC

PC

R10

IRData Bus (1

cycle)0x501

a0x501a PC

ALU

Address

Bus

+2+2

*Also called PC Relative address mode

Page 17: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 17

Source: Symbolic Mode – label

PC

PC

PC

PC incremented

at end of phase

Evaluate Source Operand

Use PC to obtain relative index and for base register

Page 18: 2.2 Microarchitecture 2.2b  –  Instruction Phases

MSP430 Microarchitecture 18

Memory

BYU CS 124

Addressing Modes

Registers

Address Bus

Data Bus (+1 cycle)

Data Bus (+1 cycle)

CPU

ADDER

cnt

01 w/R2 = Absolute Mode

0000

add.w &cnt,r10 ; r10 += M[cnt]

0xc018

PCPCPC

R10

IRData Bus (1

cycle)0x521

a0x521a PC

ALU

Address

Bus

+2+2

Page 19: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 19

Source: Absolute Mode – &Address

#0

PC

Evaluate Source Operand

Use PC to obtain absolute address, use #0 for base

register

PC can be incremented

anytime during the

phase

Page 20: 2.2 Microarchitecture 2.2b  –  Instruction Phases

MSP430 Microarchitecture 20

Memory

BYU CS 124

Addressing Modes

Registers

CPU

ADDER

11 w/R0 = Immediate Mode

add.w #100,r10 ; r10 += 0x0064

PCPCPC

R10

Data Bus (+1 cycle)

IRData Bus (1

cycle)0x503

a PC0x503

a0x0064

ALU

Address

Bus

+2+2

Page 21: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 21

Source: Immediate Mode – #n

PC

PC can be incremented

anytime during the

phase

Evaluate Source Operand

Page 22: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 22

MSP430 Source Constants

To improve code efficiency, the MSP430 "hardwires" six register/addressing mode combinations to commonly used source values: #0 - R3 in register mode (00) #1 - R3 in indexed mode (01) #2 - R3 in indirect mode (10) #-1 - R3 in indirect auto-increment mode (11) #4 - R2 in indirect mode (10) #8 - R2 in indirect auto-increment mode (11)

Eliminates the need to use a memory location for the immediate value - commonly reduces code size by 30%.

Evaluate Source Operand

Page 23: 2.2 Microarchitecture 2.2b  –  Instruction Phases

MSP430 Microarchitecture 23

Memory

BYU CS 124

Addressing Modes

Registers

CPU

ADDER

Constant Generator

add.w #1,r10 ; r10 += 1

PCPC

R10

00000001000200040008ffff

IRData Bus (1

cycle)0x531

a

Address Bus

PC0x531

a

ALU

+2

Page 24: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 24

Constant Mode – #{-1,0,1,2,4,8}

R3

Evaluate Source Operand

Page 25: 2.2 Microarchitecture 2.2b  –  Instruction Phases

MSP430 Microarchitecture 25

Memory

BYU CS 124

Addressing Modes

Registers

Address Bus

Data Bus (+1 cycle)

Data Bus (+1 cycle)

CPU

ADDER

3 Word Instruction

cnt

add.w cnt,var ; M[var] += M[cnt]

0x000c

PCPCPC

varAddress Bus

Data Bus (+1 cycle)

Data Bus (+1 cycle)

PC

Data Bus (+1 cycle)0x021

8

IRData Bus (1

cycle)0x509

00x5090PC PC

ALU

Address

Bus

+2+2+2

Page 26: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 26

Final Instruction Phases

Execute PUSH

Decrement stack pointer (R1) Ready address for store phase

JUMP Compute 10-bit, 2’s complement, sign extended Add to program counter (R0)

Store Move data from ALU to register, memory, or

I/O port

Page 27: 2.2 Microarchitecture 2.2b  –  Instruction Phases

MSP430 Microarchitecture 27

Memory

BYU CS 124

Registers

Address Bus

Data Bus (+1 cycle)

Data Bus (+1 cycle)

CPU

Push Instruction

cnt

push.w cnt ; M[--sp] = M[cnt]

0x000c

PCPCPC

IRData Bus (1

cycle)0x1210

0x1210 PCPC

fffe

(+1 cycle)

Address Bus

SPSP

0xa5a5

Data Bus (+1 cycle)

0xa5a5 AL

U

ADDER

SP

Execute Phase

Address

Bus

+2+2

Page 28: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 28

Execute Phase: PUSH.WExecute Cycle

SP

SP = SP - 2

Use Store Phase to push on stack

Page 29: 2.2 Microarchitecture 2.2b  –  Instruction Phases

MSP430 Microarchitecture 29

Memory

BYU CS 124

Addressing Modes

Registers

CPU

ADDER

Execute Phase: jne func

jne func ; pc += sext(IR[9:0]) << 1

PCPC R2

IRData Bus (1

cycle)0x3c2

a

Address Bus

PC0x3c2

1

ALU

+2

SEXT[9:0]<<1

func

CONDJump Next

Page 30: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 30

Execute Phase: JumpExecute Cycle

PC

2’s complement, sign-extended

Select “COND” to conditionally change PC

Page 31: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 31

Store Phase: Rd

Store Cycle

Page 32: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 32

Store Phase: Other…

Store Cycle

Page 33: 2.2 Microarchitecture 2.2b  –  Instruction Phases

Review Questions

Page 34: 2.2 Microarchitecture 2.2b  –  Instruction Phases

MSP430 Microarchitecture 34

2.2.4 Review Questions

1. add.w tab(r10),r9

2. and.w &mask,r12

3. bis.b #0x08,r6

4. mov.b cnt,r11

5. mov.w r4,r5

6. mov.w #100,r14

7. sub.w @r4+,r5

8. xor.b @r8,r15

a. Absolute

b. Constant

c. Immediate

d. Indexed register

e. Indirect auto-increment

f. Indirect register

g. Register

h. Symbolic

BYU CS 124

Match the following source operand modes:

Page 35: 2.2 Microarchitecture 2.2b  –  Instruction Phases

MSP430 Microarchitecture 35

2.2.4 Review Questions (answers)

1. add.w tab(r10),r9

2. and.w &mask,r12

3. bis.b #0x08,r6

4. mov.b cnt,r11

5. mov.w r4,r5

6. mov.w #100,r14

7. sub.w @r4+,r5

8. xor.b @r8,r15

a. Absolute

b. Constant

c. Immediate

d. Indexed register

e. Indirect auto-increment

f. Indirect register

g. Register

h. Symbolic

BYU CS 124

Match the following source operand modes:

Page 36: 2.2 Microarchitecture 2.2b  –  Instruction Phases

MSP430 Microarchitecture 36

PCPCPCPC

BYU CS 124

2.2.5 Review QuestionsPresent the destination operand of the following instruction to the ALU: add.w r4,cnt ; M[cnt] += r4

cnt

Memory

Registers

CPU

ADDER

IR

PC

ALU

0x5480

R40x021

8

0x5480

Page 37: 2.2 Microarchitecture 2.2b  –  Instruction Phases

MSP430 Microarchitecture 37

0x0218

0x5480

PCPCPCPC

BYU CS 124

2.2.5 Review Questions (answers)

Present the destination operand of the following instruction to the ALU: add.w r4,cnt ; M[cnt] += r4

cnt

Memory

Registers

CPU

ADDER

IR

PC

ALU

Address

Bus

1. Put PC on Address Bus

Data Bus (+1 cycle)

2. Present ADDER Op1 w/Data Bus

PC

3. Present ADDER OP2 w/PC

Address Bus

4. Put ADDER on Address Bus

Data Bus (+1 cycle)

5. Load ALU OP2 from Data Bus

+2

6. Increment PC by 2

PC R4

0x5480

Page 38: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 38

2.2.6 Review QuestionsShow how to retrieve a PC-relative destination operand from memory and present to the ALU:

Page 39: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 39

2.2.6 Review Questions (answers)

PC

PC

PC

Show how to retrieve a PC-relative destination operand from memory and present to the ALU:

Page 40: 2.2 Microarchitecture 2.2b  –  Instruction Phases

BYU CS 124 MSP430 Microarchitecture 40