Exam 1: MidtermSolutions and Commentary
Part of
the homework for CS:2630, Fall 2023
|
X Mean = 5.84 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X _________X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X___ 0 . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 . 9 . 10
X Mean = 7.66 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X ___X_X_X_X___X_X_X___X_X_X_X_X_X_X_X_X_X_X_X_ 0 . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 . 9 . 10
X Mean = 12.75 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X ___________________X___________X___X_X___X_X_X_X_X___X_X_X_X_X_X_ 0 . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 . 9 . 10. 11. 12. 13. 14. 15
Please write legibly in the space provided. Illegible and verbose answers will be penalized! The expected answers are short. This exam is open book, open-notes, closed neighbor, no phones, no internet! This exam is worth 10 points so allocate 5 minutes of your time per point.
A decimal number: | -59 | 81 | -19 | 44 | -68 |
---|---|---|---|---|---|
Binary absolute value: | 00111011 | 01010001 | 00010011 | 00101100 | 01000100 |
Signed-magnitude: | 10111011 | 01010001 | 10010011 | 00101100 | 11000100 |
1's complement: | 11000100 | 01010001 | 11101100 | 00101100 | 10111011 |
2's complement: | 11000101 | 01010001 | 11101101 | 00101100 | 10111100 |
naturally biased: | 01000101 | 11010001 | 01101101 | 10101100 | 00111100 |
1/2 did perfect work, clerical errors were common, but some numbers caused far more trouble than others. 1/14 got none of the binary versions of 14, 1/10 got none of the naturally biased values. 1/8 generally had trouble with the one's and two's complement systems, for both positive and negative values.
LIL R8,MP2DATA ; char ** p = mp2data LOOP: ; for_(;;)_{________________________ LOADSCC R3,R8 ; ___char_*_s_=_p___________________ TESTR R3 BZS ENDLOOP ; ___if_(s_==_NULL)_break___________ LIL R1,PUTSTR JSRS R1,R1 ; ___putstr(_s_)____________________ ADDSI R8,4 ; ___p++____________________________ BR LOOP ENDLOOP: ; }_________________________________
a) Fill in the comments above with well formatted C code that explains the assembly code. (0.5 points)
1/24 did perfect work (not necessarily the comments given above). A similar number left this blank. 1/5 had trouble documenting the loop, 1/4 had trouble documenting the loop exit, 1/2 had trouble with what the LOADSCC did, or with the call, or with the pointer increment. Not surprisingly, pointers caused problems. Some wanted to use array notation, and extra or missing asterisks were common.
b) What addressing mode does LOADSCC use with R8? (0.5 points) __short_indexed____
1/4 got this (or register indirect, which means the same thing). 1/3 said just indexed, for partial credit. Among the remainder, unrelated addressing modes such as immediate, pc-relative or register dominated.
c) What addressing mode does the BZS instruction use? (0.5 points) __pc_relative______
Over 1/2 got this. Among the remainder, some gave unrelated addressing modes; immediate was more popular than indexed, but close to 1/10 gave answers that weren't addressing modes.
d) What is the displacement on the BR instruction? (0.5 points) ___-8______________
1/5 got this. Almost 1/2 forgot that the displacement should be negative for backward branches. 1/5 had off-by-1 errors for the magnitude (and a few gave 10, off by 2). A few students each gave magnitudes of 1, 4 and 6. Strange values such as 5, 11, 12, 14 and 20 also showed up.
. = 0 A: ASCII "bcd" B = . ALIGN 2 C: B A,B,C,D ALIGN 4 D = 'a' + 2 W A H B |
|
scratch space
1/4 did perfectly, and 3 left it blank. Only a few had difficulty with
the ASCII characters in the string "bcd", although a few added a
null terminator. 1/6 had trouble with the value of D.
1/6 has a wrong value for B.
1/10 has wrong values for A and C.
The comments added in the scratch space above are there to help with the
answers to parts b to e below.
Only 1/35 gave perfect answers. 1/14 gave nonsense answers and 1/5 left the
problem blank. This was an open-book exam, and everyone was told on the first
day of class and again during the week before the exam that they would need
their Hawk CPU manual; during the exam, it was obvious that a fair number had
not brought appropriate reference material.
Almost 1/4 had problems with the (positive) PC-relative branch displacement
for the BNS instruction, many with off-by-one errors.
1/3 had problems with the negative branch displacement on the BNR
instruction, mostly leaving the displacement positive.
Over 1/4 forgot to add an extra halfword for the ADDI and of those
who included this word, perhaps 1/10 got the wrong value for the constant -1.
Of those who forgot the halfword, many tried to stuff the constant -1 into
some part of the first halfword of the instruction.
1/10 added halfwords with strange values for the lines holding the labels
LOOP and DONE.
These frequently had values like FFF0.
Were they PC relative displacements for the preceeding conditional branches?
Were they related to the blank lines in the code? I couldn't tell.
b)
What register(s) does it use as parameters? (0.5 points)
__R3,R4_____________________
Almost 1/2 got this. Almost 1/2 added R5 as a parameter, despite
the fact that the first thing the code does is overwrite R5 with
R3. About 1/7 missed either or both R3 and R4,
despite the fact that the result of the code clearly depends on both of these.
c)
What register(s) does it alter? (0.5 points)
____R3,R4,R5___________________
1/3 got this. All you needed to do for this was look at the set of destination
registers modified by any instruction in the code.
Almost 1/2 missed R5, 1/10 missed R3
and 1/15 missed R4.
d)
What register(s) does it return? (0.5 points)
____R3_________________________
Over 1/3 got this right. To get this, you really had to look at what the
code does. It always returns with R5 as an unchanged copy of the
original R3, hardly an interesting value. If R4 was non
negative on entry, it always ends up -1 on exit, only slightly more
interesting. The big changes happen to R3.
Alomost 1/3 included R4 as a return value, for a small penalty.
Almost the same number omitted R3 despite the fact that it is the
target of the most computation in the code. 1/6 included R5.
e)
What does it do (in one line!)? (0.5 points)
_______________R3_=_R3_*_R4_(for_R4>0)___
1/10 got this. To do this, they needed to understand the consequences of the
loop in the code. 1/10 left this blank.
1/15 said R3=R3+R4 for a little credit
and 1/15 said R3=R3+R5 for less credit)
Most of the remainder earned little or no
credit, giving long sequences of code with no real attempt to explain what it
did. Those who gave loops frequently omitted loop initialization. Many focused
on what the loop did to just one of R3 or R4.
A = 0
B = 3
C = 4
D = 'c' = 6316
SUBR:
MOVE R5,R3 ; -- move p1
LIS R3,0 ; acc = 0
ADDSI R4,-1 ; p2--
BNS DONE ; if (p2 >= 0) {
LOOP: ; do {
ADD R3,R3,R5 ; acc = acc + p1
ADDI R4,R4,-1 ; p2--
BNR LOOP ; while (p2 >= 0)
DONE: ; }
JUMPS R1 ; return acc
scratch space
Address Value
000000 F 3 F 5
000002 0 0 D 3
000004 C F 1 4
000006 0 4 0 1
000008 3 5 3 3
00000A 6 4 F 4
00000C F F F F
00000E F C 0 9
000010 B 1 F 0
000012
000014