IC220 Computer Architecture SOLUTION 12-week Exam SOLUTION Wed April 6, 2016

advertisement
IC220 Computer Architecture
SOLUTION 12-week Exam SOLUTION
Wed April 6, 2016
Last Name ____________________ First Name _______________
Alpha _____________________
Section:
(circle one)
5002
(McDowell)
1001
(Roth)
3001
(Rye)
3002
(McDowell)
5001
(Rye)
Note: This exam is closed-book, closed-notes.
Exception: A reference sheet (the “green card”) is attached to the last page. You may freely
use this, but only this sheet (not any other notes, or a copy of the sheet that you brought
yourself).
No calculators are permitted.
To receive partial credit, show all work.
WORK QUICKLY AND DO THE EASY PROBLEMS FIRST!
Page 1 (9 pts)
______________
Page 2 (8 pts)
______________
Page 3 (13 pts)
______________
Page 4 (12 pts)
______________
Page 5 (11 pts)
______________
TOTAL (max 53)
______________
Possibly useful information:
1. A copy of the single-cycle datapath is provided to you – see end of exam.
2. For function calls:
Integer values are passed in $a0, $a1, $a2, $a3
Floating point values are passed in $f12, $f14
Integer values are returned in $v0
Floating point values are returned in $f0.
3. ALU control
ALUOp = 00  ALU will Add
ALUOp = 01  ALU will Subtract
ALUOp = 10  ALU will perform action indicated by the instruction’s function field
NOTE: This is an exam that will be given to multiple sections and possibly to students after the
primary exam day. You may not discuss it with anyone until after Thursday April 7, 2016.
(3 pts) The following is a 4 bit, two’s complement number: 1100
What decimal number does it represent?
Looks negative. Must invert and add one:
1100  0011 + 1 = 0100. That is “4” – but was negative, so answer is -4.
Answer: ____-4__________
(2 pts) Add the following 4-bit binary, two’s complement numbers.
(1 pts) Did overflow occur?(circle one) Yes No
1011
+ 0111
10010 – must get rid of leading 1. Answer: 0010
No overflow possible – adding positive and negative.
(2 pts) Below is a 4-bit binary, two’s complement number. What would the equivalent number be as an 8-bit
binary, two’s complement number?
0111
Answer: ____0000 0111__________
(1 pts) How many bits does MIPS use to store one “double precision” floating point value?
Answer: ______64_______
SOLUTION IC220 12 Week Exam – Wed April 6, 2016 SOLUTION
1
The questions on this page all refer to the Single-Cycle Datapath
(see attached figure)
(4 pts) Provide the requested control signals for the following instruction. Show don’t cares if appropriate.
sub $s0, $t1, $a0
(just show the answer – no explanation needed)
ALUOp
=
10 (can’t tell what to do from opcode – must look at function field)
(00 can’t work b/c this control must be based only on opcode, and that only says “R-type”)
ALUSrc
=
0 (want Read Data 2 (e.g. $t1) to go to ALU)
Branch
=
0
MemtoReg
=
0 (send result of ALU back to register file)
MemRead
=
0 or X
MemWrite
=
0 (do NOT want to write to memory)
RegDst
=
1 (destination is $s0, this comes from rd field for R-type instruction)
RegWrite
=
1 (want to store final result in register file)
(4 pts) Provide the requested control signals for the following instruction. Show don’t cares if appropriate.
beq $s0, $t1, Loop
(just show the answer – no explanation needed)
ALUOp
=
01 (force to subtract, to compare $s0 and $t1)
ALUSrc
=
0 (want $t1 to go to ALU, from Read Data 2)
Branch
=
1
MemtoReg
=
X (not sending anything to a register)
MemRead
=
0 or X
MemWrite
=
0 (don’t want any kind of write)
RegDst
=
X (not sending anything to a register)
RegWrite
=
0 (do NOT want to write anything)
SOLUTION IC220 12 Week Exam – Wed April 6, 2016 SOLUTION
2
(4 pts) Below is a K-map representing some function Y. What is the simplified version of Y?
(draw on the K-map to show your work)
CD
AB
1
AB
0
AB
0
AB
1
C D CD CD
1
0
1
0
1
1
X
1
1
X
0
0
B C  BC  A C D
Answer: Y= ___
______________________________________
(4 pts) Simplify the following two equations. SHOW your work.
( A  1)  ( B  0)  (C  C )( D  1)  1  B  D  B  D
( A  B )( A  C )  ( A  B )( AC )  A AC  B AC  B AC
(1 pts) A certain multiplexor has fifteen (15) data inputs. How many selector bits does it need?
Answer: ______24 = 16_-- so 4 bits is the minimum needed.______
.
(4 pts) Circle the correct answer to each question.
Which kind of logic is an AND gate?
COMBINATIONAL
SEQUENTIAL
TRANSITIVE
RELATIONAL
SEQUENTIAL
TRANSITIVE
Your donut counting machine was an example of what?
Boolean Field
Finite State Machine
Karnaugh System
Which kind of logic is a “register”?
COMBINATIONAL
RELATIONAL
What kind of memory stores information using capacitors?
CRAM
DRAM
FRAM
ORAM
PRAM
SOLUTION IC220 12 Week Exam – Wed April 6, 2016 SOLUTION
Two-level Logic
SRAM
3
(8 pts) Convert the following C code into MIPS.
#
a0
a1
a2
void mergeAndSet (float A[], float B[], int index) {
float mergedVal;
mergedVal = A[index] + B[index];
A[index] = mergedVal;
}
mergeAndSet:
sll $t0, $a2, 2
add $t1, $a0, $t0
add $t2, $a1, $t0
lwc1 $f0, 0($t1)
lwc1 $f1, 0($t2)
add.s $f2, $f0, $f1
swc1 $f2, 0($t1)
jr $ra
#
#
#
#
#
#
#
t0 = 4*index
t1 = a0+4*index = &A[index]
t2 = a1+4*index = &B[index]
f0 = A[index]
f0 = B[index]
mergedVal = A[index]*B[index]
A[index] = mergedVal
(4 pts) Suppose x, y, and z are C++ variables of type “float”, and are stored in registers $f6, $f8, and $f10,
respectively. Convert the following C code into MIPS.
x = z * z;
if (x > y)
z = x – y;
mul.s
c.gt.s
bc1f
sub.s
$f6, $f10, $f10
$f6, $f8
Else
$f10, $f6, $f8
#
#
#
#
x = z * z
Is x > y?
if not, go to Else
z = x - y
Else:
SOLUTION IC220 12 Week Exam – Wed April 6, 2016 SOLUTION
4
(11 pts) Consider the hypothetical MIPS instruction jwdd (jump with dynamic dispatch). It loads a value from
a particular location in memory (based on the values of two registers), then sets the PC equal to that value.
Formally, it does this:
PC = Mem[ Regs[rs] + Regs[rt] ]
Example: jwdd $s2, $t1
- This will set the PC equal to the contents of memory at the address $s2+$t1.
This instruction is encoded as an I-type instruction. For instance, given the sample instruction above, the details
on the encoding would be:
rs
= 18 (because $s2 is register number 18)
rt
=
9 (because $t1 is register number 9)
immediate =
0 (unused)
The specific value of the opcode is irrelevant, so we’re omitting the details.
a.) (6 pts) On the next page is a copy of the Single-Cycle Datapath we have discussed in class. Add any
hardware (gates, adders, wires, etc.) to this figure that is necessary to support the new jwdd
instruction. Be sure to draw your changes neatly and clearly. Plan in advance how your
picture can clearly indicate what is happening!
Your changes must NOT break the functioning of existing instructions!!!!
c.) (5 pts) Show the control signals here for this new instruction. Show don’t cares if appropriate. If
you need any new control signal(s), add them and also show their value(s).
ALUOp
=
00 (force ALU to Reg[rs] and Reg[rt])
ALUSrc
=
0 (send ReadData2, which is Reg[rt], to ALU)
Branch
=
X
(irrelevant b/c of new mux)
MemtoReg
=
X
(not storing anything back to register file)
MemRead
=
1
(we ARE reading from memory)
MemWrite
=
0
(do NOT write to memory)
RegDst
=
X
(not storing anything back to register file)
RegWrite
=
0
(do NOT store any new value in register file)
New_mux_ctrl = 1
(send output of memory back to PC)
SOLUTION IC220 12 Week Exam – Wed April 6, 2016 SOLUTION
5
Use this page for your answer for the new instruction.
If you need to start over, clearly cross out this page, and use the copy on the back of this paper instead.
SOLUTION IC220 12 Week Exam – Wed April 6, 2016 SOLUTION
6
Use this page for general reference, or if you need to start over on adding the new instruction.
Work on this page will NOT be graded unless the picture on the other side is clearly crossed out.
SOLUTION IC220 12 Week Exam – Wed April 6, 2016 SOLUTION
7
Download