April 26, 2004

EE3755 EXAM 3:

Do not turn over the page till I say so.

Some problems are very easy so do not spend

Too much time on them.

If you think a problem is difficult, try to solve

The easy ones First.

Name:

SSN:

Problem 01(20pts):  10mins  (how much did you spend?      Min)

Problem 02(10pts):  05mins  (how much did you spend?      Min)

Problem 03(10pts):  05mins  (how much did you spend?      Min)

Problem 04(10pts):  05mins  (how much did you spend?      Min)

Problem 05(10pts):  06mins  (how much did you spend?      Min)

Problem 06(04pts):  02mins  (how much did you spend?      Min)

Problem 07(08pts):  03mins  (how much did you spend?      Min)

Problem 08(12pts):  02mins  (how much did you spend?      Min)

Problem 09(10pts):  10mins  (how much did you spend?      Min)

Problem 10(04pts):  01mins  (how much did you spend?      Min)

Bonus(02pts):   01mins

Total 100pts  50mins

//Solution

Problem 1: MIPS program.(20pts, 10mins)

1-a). Write a MIPS subroutine program to  add   two  numbers,  16bits  at a time

and return the result  (similar to  packed bcd).(14pts)

Ignore Carry out.

//C code

Int c;

.. ……..//c= {{left half of a+ left half of b} ,{right half of a + right half of b}}

return c;

}

For example )… a = 0x0001  0002,  //32 bits data

b = 0x0001  0002,  //32 bits data then

c = 0x0002  0004   //add 2 - 16bits….

(checking points for grading: proper usage of registers, instructions, algorithm, length)

Use \$a0,\$a1 for passing parameters

Use \$v0 for return value.  #(1pts)

.data

newline: .asciiz "\n"

.text

.globl __start           # Must be global

__start: li  \$a0,0x00000002

li  \$a1,0x00000002

nop

move \$a0,\$v0

jal PRINT_SUB

nop

syscall

li \$t0,0xffff0000 # MASK UPPER 16BITS

and \$t4,\$t4,\$t0

or  \$v0,\$t3,\$t4 # save return value to \$v0.

jr \$ra

nop

syscall

la \$a0,newline

syscall

jr \$ra

nop

syscall

syscall

1-b) Write a MIPS  drive program(calling program)  for the above ADDTWO16_BITS routine.(6pts)

//C code.

a = 0x00010002; //line 1

b = 0x00010002; //line 2

(hint: Write a MIPS code for above line 1, line 2 and line 3)

(checking points for grading: proper usage of registers, instructions)

sol)

li  \$a0,0x00000002

li  \$a1,0x00000002

problem 2:  Complete the module(10pts,5min)

###########################################

input [15:0]  multiplicand, multiplier;

input         start, clk;

output        prod;

reg [32:0]    product;

wire [31:0]   prod = product[31:0];

reg [3:0]     bit;

reg           d;

initial bit = 0;

wire [16:0]   multsx = {multiplicand[15],multiplicand};  //Fill here

always @( posedge clk )

if( ready && start ) begin

bit     = 8;

product = { 17'd0, multiplier }; //Fill here

d = 0;

end else if( bit ) begin

case ( {product[1:0],d} ) //Fill here

3'b001: product[32:16] = product[32:16] + multsx;

3'b010: product[32:16] =  product[32:16] + multsx;

3'b011: product[32:16] =  product[32:16] + 2 * multiplicand; //Fill here

3'b100: product[32:16] =  product[32:16] - 2 * multiplicand; //Fill here

3'b101: product[32:16] =  product[32:16] - multsx; //Fill here

3'b110: product[32:16] =  product[32:16] - multsx; //Fill here

endcase

d = product[1];

product = { product[32], product[32], product[32:2] };//Fill here

bit     = bit - 1; //Fill here

end

endmodule

Problem 3: Complete the module(10pts,5mins).

################################################################

// A 5-bit CLA using five cla slice parts.  The generate and propagate

// signals are used to produce the carry  signals.

module cla_5(sum,cout, a,b,cin);

input [4:0] a, b;

input cin;

output [4:0] sum;

output  cout;

wire [4:0]   g, p, carry;

/// Logic for Carry  Signals

// Fill carry[1], carry[2],carry[3] and sum[0] . DON’T FILL carry[4]

assign       carry[0] =  g[0] | cin & p[0];

assign       carry[1] =  g[1]  |    g[0] & p[1] |            //FILL HERE

cin & p[0] & p[1];

assign       carry[2] =  g[2]  |    g[1] & p[2] |            //FILL HERE

g[0] & p[1] & p[2]  |

cin & p[0] & p[1] & p[2];

assign       carry[3] =  g[3] |      g[2] &p[3] |            //FILL HERE

g[1] &p[2] & p[3] |

g[0] & p[1] & p[2] &p[3] |

cin  & p[0] & p[1] & p[2] & p[3];

assign       carry[4] =      DON’T Have to FILL carry[4]

g[4] |      g[3] & p[4] |

g[2] & p[3] & p[4] |

g[1] & p[2] & p[3] & p[4]  |

g[0] & p[1] & p[2] &p[3] & p[4] |

cin  & p[0] & p[1] & p[2] & p[3] & p[4];

assign      sum[0]  =  p[0] ^ cin;  //FILL HERE

assign      sum[1]  = p[1] ^ carry[0];

assign      sum[2]  = p[2] ^ carry[1];

assign      sum[3]  = p[3] ^ carry[2];

assign      sum[4]  = p[4] ^ carry[3];

assign      cout    = carry[4];

//#####################

cla_slice_part s0(g[0],p[0],a[0],b[0]);

cla_slice_part s1(g[1],p[1],a[1],b[1]);

cla_slice_part s2(g[2],p[2],a[2],b[2]);

cla_slice_part s3(g[3],p[3],a[3],b[3]);

cla_slice_part s4(g[4],p[4],a[4],b[4]);

endmodule

Problem 4: Convert the following numbers(10pts,5mins):

Hint (7/8) = 0.875

a) Decimal  11  to 8-bit Binary:

//00001011

b) Decimal  -11     to 8-bit Binary:

// 11110101

c) Decimal 11.875  to Binary (as many bits as needed):

//1011.111

d) Decimal    -11.875  to IEEE 754 Single Precision (Show in hexadecimal):

//c13e

Problem 5:  What will be the synthesizer output for module something?(10pts, 6Mins)

(Draw simple one just what we did at the class)

module something(x,y,a,b,c);

input  a;

input  [7:0] b,c;

output   [8:0] x,y;

wire [7:0] b, c;

reg [8:0]x, y;

always @( a or b or c ) begin

if( a ) begin

x = b + c;

y = b - c;

end else begin

x = b - c;

end

end

endmodule

//Hw5…Solution..

Problem 6:  Name the four basic steps of synthesis(4pts. 2Mins)

(1) Synthesize to RTL (Inference)

(2) Technology Mapping

(3) Optimization

(4) Place and Route

Problem7:Convert following pseudo instructions to real instructions.

(8pts  3Mins).

la \$t0,0x12345678; (2pts)

//lui \$t0,0x1234

ori \$t0,\$t0,ox5678

move \$t0,\$t1;(1pts)

nop;   (1pts)

//sll \$0,\$0,0

abs \$t1,\$t0;(3pts) //take absolute value of \$t0 and put it into \$t1.

//hint..bgez \$reg, target.

//4instructions .more will be OK, too.

bgez \$t0 TARGET

nop

sub \$t1,\$0,\$t0

TARGET:

mul \$2, \$3, \$4 (1pts)

mult \$3, \$4

mflo  \$2

Problem 8: True(right ) or False(wrong) (12pts,2Mins).

T      F

8-2)  subi \$t0,\$t1,0x1234  F :subi is not a real instruction (HW)

8-3)  jr    \$0x123456     F: jr reg..not address

8-4)  jal   2500          T : jal address is OK. But since SPIM

8-5)  j     0x123456789   F: j Max. 26 bits address

(0x123456789  is 33bits).

8-6)   9 decimal digits are enough to represent the significant  field floating point IEEE754 single precision .

(Hint : opposite way to HW)

T .: Mantissa field is only (23+1)

24 bits long. So 9 decimal digits is enough.

Problem 9: What is the MIPS assembly code for the following C code?

(15pits 10Mins)

//c..

# Reg Usage: j, \$8;  sum, \$9;

for(j = 0, j < 4;++j){

sum = sum + j;

}

//sol

.data

newline: .asciiz "\n"

.text

.globl __start           # Must be global

__start:

add \$9,\$0,\$0  # sum = 0; #don't need for the solution.

##########solution

addi \$10,\$0,4  #test j == 4

j TEST

nop

LOOP:

#BODY

add \$9,\$9,\$8 # sum = sum +j

#Increment

#Test condition

TEST:

slt \$11,\$8,\$10  #j <4

bne \$11,\$0,LOOP

nop

#############

move \$a0,\$9

syscall

Problem 10:  Fill the Blank.(4pts. 1mins)

MIPS coding format:

OPCODE   field is ( 6  ) bits long.

Each Reg.  field is ( 5  ) bits long.

Immediate  field is (16  ) bits long.

Jump instruction.

JALR rs     \$31 <- PC +( 8  )…//return address will be saved at \$31.

.// the return address will be PC +….

Bonus (2pts).

Write down the time you spent for each problems on the very first page or next to each problems.