MIDTERM SOLUTIONS AND GRADING STANDARDS
READ THIS FIRST:
Each problem was graded either by a single TA or by a small subset of TAs.
If you have a question or a complaint about a problem, be sure to consult
the correct TA(s), since the others won't be able to help you much.
REGARDING COMPLAINTS AND REGRADES:
We did the best we could to correctly and fairly grade all the exams.
However, with 400 exams, we likely made mistakes, sometimes in the
student's favor, sometimes in the opposite direction. If you feel that
there's been a mistake in the grading of your exam, whether in the actual
grading or in the tallying of points, you are free to ask for a regrade.
However, the TAs and Professor Patterson will regrade YOUR ENTIRE EXAM,
even if you only have a dispute with one question. This is intended to
discourage scrounging for points. The TAs will gladly answer questions
about the exam problems, but you will have to submit the complete exam
for a regrade if you really feel there's been an error.
IMPORTANT -- CORRECTIONS TO MAKE:
We've found two locations in the test where we've decided to be slightly
more lenient for certain answers. Please check your test. If you find
that you made either of these mistakes, take your test to your own TA,
who will give you the extra point(s) and fix the grade.
1. In the matching question, when we graded part F, we accepted numbers
21, 8, 2, and 9. However, we've decided that answer choice 4 is just as
correct as the others. So if you put down 4 and got marked off, go to
your TA.
2. In the Pliable Data Question, part C, the instruction represented should
be "lb $0, 0($0)". A few people misread the chart and put down "lwc2"
instead of "lb". The graders took off 2 points for this mistake, out of
the available 3. We've decided this is a little bit too harsh, so if
you've made this mistake, take your test to your TA and you may get 1
point back. (The reason I use the word "may" instead of the word "will"
is that, if your answer is completely wrong in the first place, you'll
still get 0 points. It's up to your TA to check for this.)
SOLUTIONS AND STANDARDS:
SIGNIN: (MAX PTS: -1 to 0)
Grader: Tai-Ping
Either you did it, or you didn't. Not too hard, people.
OVERFLOW: (MAX PTS: 6)
Graders: Josh, Mark
Correct Answers:
Part A: Yes. When two large unsigned numbers are added and the result
is a small unsigned number, overflow has occurred.
Part B: No. Adding a positive number to a negative number will never
result in overflow.
Part C: No. Adding a positive number to a negative number will never
result in overflow.
Grading Standards: One point each for the three correct answers. One point
each for a reasonable explanation to each. The definition of reasonable
was at the discretion of the graders. Above are examples of concise,
reasonable explanations.
REGISTER SIZE: (MAX PTS: 2)
Graders: Josh, Mark
Correct Answers: B and C
Grading Standards: Half a point each for circling B and C. Half a point each for
NOT circling A and D.
Side Note: Those of you who circled D should be ashamed! That was a joke,
people!
PLIABLE DATA: (MAX PTS: 7)
Grader: Brendan
Correct Answers:
Part A: Yes. -2,147,483,648
Part B: Yes. 2,147,483,648
Part C: Two possible answers:
Yes. lb $0, 0($0)
Nothing is modified.
-- OR --
No. In this case, points were given completely at the
discretion of the grader. Full credit was given for
saying that this would be lb $0, 0($0), except that $0
cannot be modified. There were many variations on this,
but mentioning "lb" and mentioning that $0 cannot be
changed are both integral parts of this solution. Zero
points for saying that there is no instruction with that
opcode.
Grading Standards: For parts A and B, one point each for circling Yes, and
one point each for the correct values. For part C, points were given at the
discrection of the grader, but they were given consistently across all
midterms.
INTERRUPT: (MAX PTS: 4)
Grader: Mark
Answer choice D has been discarded due to some ambiguity we didn't discover
until after the exam.
Correct Answers: B and C
Grading Standards: One point each for circling B and C. One point each for
NOT circling A and E.
NETWORK ADDRESS: (MAX PTS: 4)
Grader: Gek, Tai-Ping
Correct Answers:
Part A: 0x8020277C
Part B: 255.255.255.248
Grading Standards: For part A, it's all or nothing. Binary was not
accepted. You had to give the correct hexadecimal solution. For part B,
1 point for the first three bytes of the mask (255.255.255). Two points
for the final byte (248). Thus, 255.255.255.0 would receive one point,
120.32.39.248 would receive two points, and 255.255.255.248 would receive
all three points. There was one exception: 255.255.255.120 received two
points. All other answers received 0 points. Solutions given in hex
instead of in the IP Address notation also lost points.
ASM TO HLL: (MAX PTS: 7)
Grader: Mike, Tai-Ping
The blank associated with choice N, the "C while statement", has been
discarded due to ambiguity. This leaves 21 blanks, each worth one-third of
a point. There is no rounding at the end. Here is a list of the acceptable
answers for each blank:
A. 10
B. 9, (2)
C. 3
D. 2
E. 16
F. 21, 8, (2), (9), (4)
G. 19
H. 22
I. 6
J. 2
K. 5
L. 6
M. 11, 15
O. 4
P. 7
Q. NONE
R. 10, 14, (15)
S. 13
If there are more acceptable answers than there are blanks corresonding to
a letter, then the extra acceptable answers are in parentheses. These are
only there if the TAs decided that there was adequate ambiguity to justify
these extra answers. If you think that we missed an acceptable answer
somewhere, feel free to discuss it with one of the graders. However,
remember that we've been through these many, many times, and this is the
largest set of matches we could justify.
SHIFTY: (MAX PTS: 8)
Grader: Dmitriy, Nemanja
First of all, here is the solution we came up with:
RightRotate: srlv $t0, $a0, $a1
ori $t1, $0, 32
sub $t1, $t1, $a1
sllv $v0, $a0, $t1
or $v0, $v0, $t0
jr $ra
There was a completely different type of solution that many people
chose to write. This was to write a loop that right rotates by one, and
then running this loop the correct number of times. Since we never
asked for concise code in this problem, a correct implementation of such
a solution would receive full credit. However, such a solution provided
much greater opportunity for error than the above one. In general, for
either type of solution, we began each problem with a score of 8 and then
subtracted points. Here are some of the things that resulted in a -1:
- no "jr $ra" at the end (you were told to follow MIPS function
conventions); IMPORTANT NOTE: If you wrote "j $ra" instead of "jr $ra",
you should NOT have lost any points. However, we may have accidentally
deducted points on some papers for this. If so, bring it to either one
of us and we'll fix it.
- not using $v0 as the return register
- not having comments
- using the number 31 instead of 32 above: this is an off-by-one
error, so think about it carefully if it seems unclear
- using subi for any reason
- putting the immediate in the second field of an addi (or subi)
instead of the third, such as in "addi $t0, 1, $0"
- using an "and" instead of an "or" in the second to last line
above
- using $at for any reason
- using a pseudoinstruction (such as "addi 0x80000000")
Here is a list of things that resulted in a -2 (because they show a
lack of understanding rather than a mistake in coding):
- using "lw $t0, 0($a0)" in place of "add $t0, $a0, $0": these
two instructions are completely different, so be sure to be crystal
clear on this difference
- using "s" registers without saving them
In addition to these clear-cut standards, we reserved the right to use
our own discretion on certain things, such as code that clearly doesn't
work, but that shows an understanding of what needs to be done. For the
vast majority of papers, though, the above errors perfectly define the
grade.
Side Note for those who care: On the exam, we said the shortest correct
solution is six lines long. Given the information we gave in the problem,
this is incorrect. We never specified that sllv, srlv and srav cannot
shift by a negative value. It is logical to assume that this would
simply mean shifting in the opposite direction. Though this is illegal
in the MIPS instruction set, we never specified this, so a correct five
line solution would replace the second and third lines above with simply
"addi $t1, $a1, -32" and the fourth line with "srlv $v0, $a0, $t1". This
is all, however, a moot point since no one in the class came up with a
completely working five line solution.
COMPILE BY HAND: (MAX PTS: 12)
Grader: Kelvin
Here's the solution we were looking for and maybe 3 of you got it
completely right. Kelvin is the only one who graded the problem so you
should talk to him if you have any questions/concerns about the problem.
checksum:
addi $sp, $sp, -16 # prologue
sw $ra, 0($sp)
sw $s0, 4($sp)
sw $s1, 8($sp) # sum, don't need result
sw $s2, 12($sp)
sll $a0, $a0, 2 # *4 for start since it's array of ints
add $s0, $a1, $a0 # frame + 4*start
add $s1, $0, $0 # sum = 0
add $s2, $a1, 2048 # frame + 4*max_length
floop: lw $a0, 0($s0)
jal getdata
add $s1, $s1, $v0 # sum += (result = getdata(frame[x]))
addi $s0, $s0, 4 # pointer to int so increment by 4
bne $s0, $s2, floop # not ending address yet so branch
sub $v0, $0, $s0 # get minus by subtracting from 0
addi $v0, $v0, -1 # -sum - 1
lw $ra, 0($sp) # epilogue
lw $s0, 4($sp)
lw $s1, 8($sp)
lw $s2, 12($sp)
addi $sp, $sp, 16
jr $ra # return
The idea is to have the least amount of instructions in the loop since you
were asked to minimized the amount of instructions. It's not the amount of
lines in your code as much as how many instructions will be executed
potentially when the program runs. Some people use slt/slti and bne/beq in
the loop instead of keeping the final address to check against. It's
actually less optimized than the solution because it means one more
instruction every time it goes through the loop which can end up being 512
instructions more! That solution didn't get any points off but in the
future you should notice these things.
(1) Popping and pushing the stack inside the loop gets -2 because you
missed the point of using the saved registers. sw/lw registers inside the
loop also gets -2.
(2) Not saving $a0/$a1 and expecting them to have the same value after jal
call gets -2
(3) Not saving temp registers and using them as counters (sum, index) gets -2
(4) Forgetting to pop the stack and forgetting jr $ra gets -1 each.
(5) Forgetting to save $ra gets -1
(6) Using more than 4 spaces on the stack gets -1 because it means you
allocated space for result when you should notice you don't need that
variable.
(7) Forgetting to lw from the address into $a0 gets -1
(8) Incrementing the counter by 1 and then multiplying it by 4 instead of
just adding the counter by 4 inside the loop gets -1
(9) inefficient or wrong implementations of (-sum - 1) gets -1. There
were surprisingly many solutions to this. In general, go for the simple
ones. Though the solution with "nor" gets a big thumb up! xor is actually
3 instructions so don't think it's better than what we have in the
solution. Multiplying by -1 is a horrible way to do it.
(10) adding twice instead of using sll to multiply by 4 inside the loop
gets -1.
(11) using subi gets -1
Those are most of the common mistakes, there are certainly special
cases. If you have certain mistakes in your code then other mistakes were
overlooked so you don't get penalized more than once. There were only about
10 perfects on this question so don't feel bad if you didn't get a perfect.
The average/medium on the problem is about 9.
EXTRA CREDIT: (MAX PTS: 1)
Grader: Gek, Tai-Ping
See separate pdf file.