+ All Categories
Home > Documents > TEST next Tuesday

TEST next Tuesday

Date post: 04-Feb-2016
Category:
Upload: sian
View: 22 times
Download: 0 times
Share this document with a friend
Description:
TEST next Tuesday. GB.21 90 Mins Worth 20% Closed Book. Assignment Four. Convert_float. my_float *convert_my_float(float num) { struct my_float * my_num = new(my_float); if (my_num) { union converter c; c.f = num; my_num->sign = c.i >> 31; - PowerPoint PPT Presentation
32
TEST next Tuesday GB.21 90 Mins Worth 20% Closed Book
Transcript
Page 1: TEST next Tuesday

TEST next Tuesday

GB.2190 Mins

Worth 20%Closed Book

Page 2: TEST next Tuesday

Assignment Four

Page 3: TEST next Tuesday

Convert_float

my_float *convert_my_float(float num){ struct my_float * my_num = new(my_float); if (my_num) { union converter c; c.f = num;

my_num->sign = c.i >> 31; my_num->exponent = ((c.i >> 23) & 0xff); my_num->mantissa = (((c.i & 0x7FFFFF) | 0x800000) << 3) ;

}

return my_num;}

Page 4: TEST next Tuesday

Print Binary function

void print_binary(int num){ unsigned mask = 0x80000000; int anded;

for (int i = 0; i < 32; i ++) { if ((i > 0) && (i % 4) == 0) cout << " " ; anded = num & mask; if (anded) { cout << "1"; } else { cout << "0"; } mask = mask >> 1; }}

Page 5: TEST next Tuesday

Add function

struct my_float * my_float_add(struct my_float *first, struct my_float *second,\ int rnd_mode){ int first_mantissa = first->mantissa; int second_mantissa = second->mantissa; int exp_diff = first->exponent - second->exponent;

my_float *my_result = new(my_float);

DBG(cout << "Starting to add" << endl); if (exp_diff > 0){

#define DBG(a) a

Page 6: TEST next Tuesday

Processor Design

• Clocking Methodology– Defines when signals can be read and written

– Going to assume and edge triggered clocking methodology

Page 7: TEST next Tuesday

Clock cycle

Stateelement

1Combinational logic

Stateelement

2

Page 8: TEST next Tuesday

Control Step

• Each control step takes one clock cycle

Clock cycle

Source registers output here

Destination registers read values here

Signals propagate through system

Page 9: TEST next Tuesday

Stateelement

Combinational logic

Page 10: TEST next Tuesday

Datapth Design

Chapter 5 P & H

Page 11: TEST next Tuesday

Introduction

• Deigning an implementation which contains subset of core MIPS instruction set:– Memory reference instructions (lw & sw)– Arthitmetic-logic instructions (add, sub, and, or

and slt)– Branch an d jump instructions (beq, j)

Page 12: TEST next Tuesday

Overview of Implementation

• Consider exection of an instruction

• First two steps identical– Use PC to fetch an instruction from memory– Read 1 or 2 registers as specified in instruction– Rest of steps dependent on instruction class

• Most will use ALU

• Many write value back to register file

Page 13: TEST next Tuesday

Overview of Implementation

Registers

Register #

Data

Register #

Datamemory

Address

Data

Register #

PC Instruction ALU

Instructionmemory

Address

• Will start with simple single cycle implementation• Implementation will comprise datapath plus

control

Page 14: TEST next Tuesday

Instruction Fetch

PC

Instructionmemory

Readaddress

Instruction

4

Add

Page 15: TEST next Tuesday

R-type Instructions

O P(6 b its )

R S(5 b its )

R T(5 b its )

R D(5 b its )

S H A M T(5 b its )

F U N C(6 b its )

Page 16: TEST next Tuesday

Components

ALU control

RegWrite

RegistersWriteregister

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Writedata

ALUresult

ALU

Data

Data

Registernumbers

a. Registers b. ALU

Zero5

5

5 3

Page 17: TEST next Tuesday

Datapath for R-Type Instructions

InstructionRegisters

Writeregister

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Writedata

ALUresult

ALU

Zero

RegWrite

ALU operation3

Page 18: TEST next Tuesday

lw and sw Instructions

• Lw $7, offset($8) or sw $7, offset($8)

• These instructions– Compute the memory address (16 bit signed offset + base register)

– If sw then value must also be loaded from reg file

– If lw the value read from memory must be stored to reg file

O P(6 b its )

R S(5 b its )

R T(5 b its )

IM M E D IA T E(1 6 b its )

Page 19: TEST next Tuesday

Datapath for lw and sw

Instruction

16 32

RegistersWriteregister

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Datamemory

Writedata

Readdata

Writedata

Signextend

ALUresult

ZeroALU

Address

MemRead

MemWrite

RegWrite

ALU operation3

Page 20: TEST next Tuesday

beq Instruction

• beq $7, $8, offset• If ($7 == $8) then pc <= pc + 4 + (offset << 2)else pc <= pc + 4

Page 21: TEST next Tuesday

beq datapath

16 32Sign

extend

ZeroALU

Sum

Shiftleft 2

To branchcontrol logic

Branch target

PC + 4 from instruction datapath

Instruction

Add

RegistersWriteregister

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Writedata

RegWrite

ALU operation3

Page 22: TEST next Tuesday

Simple Implementation Scheme

• All instructions execute in single clock cycle:– No data path resource used more than once per

clock cycle– Components of different instruction classes

may be shared if no conflicts occur• May require multiple connections to same input

• Multiplexer used to select appropriate input

Page 23: TEST next Tuesday

Combining datapath for R-type and memory instructions

• Datapaths very similar

• Two main differences– Second input to ALU is a register (for R-type)

or signed extened lower half of instruction (lw and sw)

– Value stored in dest register comes from ALU (R-type) or memory (lw)

Page 24: TEST next Tuesday

Combined Datapath

I n s t r u c t i o n

1 6 3 2

R e g is t e r s

W r i t e

re g i s t e r

R e a d

d a t a 1

R e a d

d a t a 2

R e a d

re g i s t e r 1

R e a d

re g i s t e r 2

D a t a

m e m o r yW r i t e

d a t a

R e a d

d a t aM

u

x

M

u

xW r i t e

d a t a

S i g n

e x t e n d

A L U

r e s u l t

Z e r o

A L U

A d d r e s s

R e g W r i t e

A L U o p e r a t i o n3

M e m R e a d

M e m W r i t e

A L U S r c

M e m t o R e g

Page 25: TEST next Tuesday

Adding Datapath for instruction fetch

P C

I n s t r u c t io n

m e m o r y

R e a d

a d d r e s s

In s t r u c t i o n

1 6 3 2

R e g is te r s

W r ite

r e g is te r

W r ite

d a ta

R e a d

d a ta 1

R e a d

d a ta 2

R e a d

r e g is te r 1

R e a d

r e g i s t e r 2

S ig n

e x t e n d

A L Ur e s u l t

Z e r o

D a ta

m e m o r y

A d d r e s s

W r i te

d a ta

R e a d

d a taMux

4

A d d

Mux

A L U

R e g W r i t e

A L U o p e r a t io n3

M e m R e a d

M e m W r i t e

A L U S r c

M e m t o R e g

Page 26: TEST next Tuesday

Add in beq components

PC

Instructionmemory

Readaddress

Instruction

16 32

Add ALUresult

Mux

Registers

WriteregisterWritedata

Readdata 1

Readdata 2

Readregister 1Readregister 2

Shiftleft 2

4

Mux

ALU operation3

RegWrite

MemRead

MemWrite

PCSrc

ALUSrc

MemtoReg

ALUresult

ZeroALU

Datamemory

Address

Writedata

Readdata M

ux

Signextend

Add

Page 27: TEST next Tuesday

ALU Control

ALU control input

Function

000 AND

001 OR

010 ADD

110 Subtract

111 Set on less than

• For R-Type instructions need to perform operation dependent of function field

• For load instructions use ALU to compute memory address by addition

• For branch instructions ALU used for subtraction

ALUOp operation

00 Add

01 Subtract

10 Use func field

A L U C o n tro l

A L U O p fu n c

2 6

O p e ra tio n

3

Page 28: TEST next Tuesday

Truth Table for ALU controlALUOp Funct field Operation

ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F00 0 X X X X X X 010X 1 X X X X X X 1101 X X X 0 0 0 0 0101 X X X 0 0 1 0 1101 X X X 0 1 0 0 0001 X X X 0 1 0 1 0011 X X X 1 0 1 0 111

• Note multiple levels of control– Main control unit generates ALUOp

– ALU control generates operation

Page 29: TEST next Tuesday

Main Control Unit Design

• Opcode fiels always bits 31 – 26 (Op[5-0])• Two regs to be read are always rs and rt• Base reg for loads and stores always rs• 16 bit ofset always bits 15 – 0• Destination register is in one of two places

– Rtype instructions RD– Lw it is RT

0 R S R T R D S H A M T F U N C

3 5 o r 4 3 R S R T IM M E D IA TE

4 R S R T IM M E D IA TE

Page 30: TEST next Tuesday

Datapath

MemtoReg

MemRead

MemWrite

ALUOp

ALUSrc

RegDst

PC

Instructionmemory

Readaddress

Instruction[31– 0]

Instruction [20– 16]

Instruction [25– 21]

Add

Instruction [5– 0]

RegWrite

4

16 32Instruction [15– 0]

0Registers

WriteregisterWritedata

Writedata

Readdata 1

Readdata 2

Readregister 1Readregister 2

Signextend

ALUresult

Zero

Datamemory

Address Readdata M

ux

1

0

Mux

1

0

Mux

1

0

Mux

1

Instruction [15– 11]

ALUcontrol

Shiftleft 2

PCSrc

ALU

Add ALUresult

Page 31: TEST next Tuesday

Control Signals

Page 32: TEST next Tuesday

Datapath with Control Unit

PC

Instructionmemory

Readaddress

Instruction[31– 0]

Instruction [20 16]

Instruction [25 21]

Add

Instruction [5 0]

MemtoReg

ALUOp

MemWrite

RegWrite

MemRead

BranchRegDst

ALUSrc

Instruction [31 26]

4

16 32Instruction [15 0]

0

0Mux

0

1

Control

Add ALUresult

Mux

0

1

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Signextend

Mux

1

ALUresult

Zero

PCSrc

Datamemory

Writedata

Readdata

Mux

1

Instruction [15 11]

ALUcontrol

Shiftleft 2

ALUAddress


Recommended