Unformatted text preview: CS30 Fall 2009 Midterm
LAST NAME
FIRST NAME
PERM Number n 2n n 2n Instructions
• Please turn off all pagers, cell phones 1 2 17 131072 and beepers. Remove all hats & 2 4 18 262144 3 8 19 524288 headphones. Place your backpacks, 4 16 20 1048576 laptops and jackets at the front. 5 32 21 2097152 6 64 22 4194304 7 128 23 8388608 8 256 24 16777216 9 512 25 33554432 You have 75 minutes to complete this 10 1024 26 67108864 exam. 11 2048 27 134217728 12 4096 28 268435456 13 8192 29 536870912 14 16384 30 1073741824 15 32768 31 2147483648 16 65536 32 4294967296 • Sit in every other seat. Nothing may
be placed in the “no fly zone” spare
seat/desk between students. • • This exam is closed book, closed
notes, no computers, PDAs or calculators.
• WRITE YOUR NAME on EACH PAGE
OF THIS TEST. You deducted 2 points otherwise. will be Your Name Perm #: Important – please note: The MIPS instructions shown in this table are the
ones that you must use on the entire exam. Do not use any instructions that
are not in this table. If you use any instructions not listed below, you will lose
points.
Name Syntax Meaning add add rd, rs, rt rd=rs+rt sub sub rd, rs, rt rd=rsrt and and rd, rs, rt rd=rs AND rt or or rd, rs, rt rd=rs OR rt sll sll rd, rt, shamt rd=logic shift rt left shamt bits srl srl rd, rt, shamt rd=logic shift rt right shamt bits sra sra rd, rt, shamt rd=arithmetic shift rt right shamt bits slt slt rd, rs, rt If rs<rt, rd=1, else rd=0 slti slti rd, rs, imm If rs<imm, rd=1, else rd=0 jr jr rs jump to the instruction held by the memory
location indicated by rs addi addi rt, rs, imm rt=rs+imm andi andi rt, rs, imm rt=rs AND imm ori ori rt, rs, imm rt=rs OR imm lw lw rt, imm(rd) rt=MEMORY[rd+imm] sw sw rt, imm(rd) MEMORY[rd+imm]=rt beq beq rs, rt, label Branch if rs==rt bne bne rs, rt, label Branch if rs != rt j j label Jump to label jal jal label Jump to label and link Your Name Perm #: Part I: General concept of MIPS [5pt, 5 minutes]: 1. MIPS was invented in 1985 with 32 integer registers. According to Moore's Law,
named after Intel founder Gordon Moore, the number of transistors per
microprocessor doubles every 1.5 years. Thus, microprocessors could have 1000
times the number of transistors in 2000 as they could in 1985. It would seem that
we could easily build microprocessors with, say, 256 registers.
Select all the reasons why MIPS has not increased the number of integer
registers from 32 to 256. A) 32 registers are much smaller than 256 registers, and since smaller is
faster, the 32 registers makes it easier to build fast microprocessors than
if there were 256 registers.
B) There is no need for more than 32 registers, as compilers have difficulty
using the 32 registers in the MIPS architecture now.
C) Moore's Law applies to Intel microprocessors, not MIPS microprocessors,
hence the hypothesis is false. The MIPS chip would be too expensive if it
had 256 registers.
D) None of the above Your Answer _________________________________________________ Your Name Perm #: Part II: Number Representation
2. (10pt, 5 min) Assume a 16bit system
Consider the following Hex pattern
0xFFFF
What is the (decimal) value of this bit pattern assuming that it is in one’s
complement format
a) 1
b) 32767
c) 32767
d) 0
e) 1
f) None of the above
Your Answer_________
What is the (decimal) value of this bit pattern assuming that it is in two’s
complement format
a) 1
b) 32767
c) 32767
d) 0
e) 1
f) None of the above
Your Answer_________ 3. (5pt, 3min) Assume a 16bit system, explain why one’s complement format and
sign and magnitude format have a “dirty zero.” Your Name Perm #: 4. (10pt, 5min) Assume a 16bit system
What is the largest positive number that can be represented by unsigned integer
format? Write it in both decimal and hexadecimal forms. What are the largest positive number and smallest negative number that can be
represented by two’s complement format? Write them in both decimal and
hexadecimal forms. What are the largest positive number and smallest negative number that can be
represented by sign and magnitude format? Write them in both decimal and
hexadecimal forms. Your Name Perm #: Part III. Assembly Language
5. (10pt, 10min) Assume a 32bit system with two’s complement format
Register $a0 contains
0xFFFF0FFF
Register $a1 contains
0x10011111
Register $a2 contains
0x00FFFFFF
at the beginning of each of the following instructions. For each instruction, give
the contents of the destination register in hexdecimal format addi $s0, $a0, $a1 _______________________________ sub $s0, $a0, $a1 _______________________________ andi $s0, $a0, 0xFF00 _______________________________ or _______________________________ $s0, $a0, $a2 addi $s0, $a0, 0xF0 _______________________________ 6. (5pt, 2min) Memory access
Which of the following addresses are valid memory addresses? Select all that
apply:
a) 0x01000201
b) 0x00014430
c) 0x000B073C
d) 0x0E0D8846
Your Answer _____________________ Your Name Perm #: 7. (10pt, 10min) Each part below specifies an instruction that could be defined to
be a pseudoinstruction for a particular MIPS simulator. The effect of each
instruction is described so there will be no confusion. You need to:
I. For each, specify whether it can be translated into a single MIPS native
instruction by circling YES or NO. The native instructions are listed in
the 2nd page of this exam.
II. Also for each write out the shortest sequence of native instructions that
could be used to simulate the given instruction. Aside from the
registered declared in the instruction, you can only use $at and $0.
A) copy
$reg1, $reg2
Effect: The value in 'reg2' is copied into 'reg1'.
Yes No ________________________________________________ B) sbg
$reg1,$reg2,label
Effect: 'reg1' gets the value (reg2reg1*0.5). If this value is positive, branch to
the given 'label'.
Yes No ________________________________________ Your Name Perm #: 8. (15pt, 15min) Implement the following function in MIPS, filling the blanks in
Assembly (no need to add comments)
C program int sum( int n ) {
if ( n <1 ) return 1;
else return (n +sum ( n  1 ) );
}
Corresponding MIPS program: note that the input n is assigned to $a0
sum: sub $sp, $sp, _____ sw $ra, 4($sp) #save the return address on the stack sw ______, 0($sp) #save the argument on the stack slti $t0, $a0, 1 beq $t0, $zero, _______ add $v0, $zero, 1 _______________________
else: addi $a0, $a0, 1 jal sum lw _____, 0($sp) lw $ra, 4($sp) add $v0, $a0, $v0 return: add $sp, $sp, _____ ____________________ #restore the return address #release the save area on the stack #return to mai Your Name Perm #: Congratulations!
You have finished the Midterm. To ensure that you get credit
for your hard work, WRITE YOUR NAME on EACH PAGE OF
THIS TEST. You will be deducted 2 points you can not finish
this task. ...
View
Full Document
 Fall '09
 Zheng
 MIPS architecture, andi rt, complement format, rd=logic shift rt, rt right shamt

Click to edit the document details