Exam 1: MidtermExam 1: Solutions and Commentary
Part of
the homework for CS:2630, Fall 2023
|
Mean = 4.39 Median = 3.9 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
Mean = 9.35 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
Mean = 20.32 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_ 8 . 9 . 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24
Mean = 33.52 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__ . 10. 12. 14. 16. 18. 20. 22. 24. 26. 28. 30. 32. 34. 36. 38. 40. 42. 44. 46 ? DD ? CC ? BB ? AA | Approximate midterm grades
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.
During the exam, it was obvious that a number of students did not bring much in the way of notes. On the first day of class, students were advised to bring, at the very least, the lab manual to exams, and preferably also the textbook.
A decimal number: | -63 | 23 | -97 | 17 | -80 |
---|---|---|---|---|---|
Binary absolute value: | 00111111 | 00010111 | 01100001 | 00010001 | 01010000 |
Signed-magnitude: | 10111111 | 00010111 | 11100001 | 00010001 | 11010000 |
1's complement: | 11000000 | 00010111 | 10011110 | 00010001 | 10101111 |
2's complement: | 11000001 | 00010111 | 10011111 | 00010001 | 10110000 |
naturally biased: | 01000001 | 10010111 | 00011111 | 10010001 | 00110000 |
18 did prfect work here, and a comparable number did well except for careless errors.
Half the class was very confused about naturally biased numbers. For 8 bits, the bias is 128 (28/2), and either adding or subtracting this bias just flips the top bit of the 8-bit number from the 2's complement value.
About 1/3 of the class had problems with one's complement numbers.
About 1/3 of the class (not necessarily the same third) had difficulty with positive numbers, and proceeded to negate the positive numbers when told to show those numbers in the one's complement or two's complement representations. This is evidence of confusion between the name of the number system and the name of the negation operator in that system.
Finally note that one example was worked for each column of the table (shown in bold face above). This worked example was supposed to help people check their answers.
LOOP: ; _for_(;;)_{_________________ MOVE R3,R10 LIS R4,1 LIL R1,PUTDECU JSRS R1,R1 ; ____putdecu(_trib,_1_);_____ ADDSI R8,1 ; CMPI R8,15 BGE QUIT ; ____if_(++count_>=_15)_break;_ LIS R3,',' LIL R1,PUTCHAR JSRS R1,R1 ; ____putchar(_','_);_________ ADD R3,R10,R11 ADD R3,R3,R12 ; ____temp_=_trib_+_trib1_+_trib2; MOVE R10,R11 ; trib = trib1 MOVE R11,R12 ; trib1 = trib2 MOVE R12,R3 ; trib2 = temp BR LOOP ; QUIT: ; _}__________________________
a) Fill in the comments above with well formatted C code to explain the assembly code. (0.5 points)
About 1/8 of the class left this problem blank.
By far the biggest problem was "well formatted C code." Hardly anyone made any effort to indent their code to make it clear which parts were a loop body.
Many failed to name the variables. The registers used for most of the variables were given in the comments on the three move instructions. Creative naming was only required for the variable in R8, named count above.
b) What addressing mode is used to save and restore R8? (0.5 points) _immediate?________
This question was an error, since R8 was not saved or restored in this code. It was onl manipulated in two lines, and in each line, only two modes were used, immediate and regiter mode.
About 1/3 of the class said immediate for full credit. A few said register, but another 1/3 said indexed addressing, which is never used with R8 in this code!
c) What addressing mode is used in the BR instruction? (0.5 points) _PC_relative_______
At least 1/3 of the class got this right. The most popular wrong answer was short-indexed addressing, but a comparable number gave answers that were not addresing modes.
d) What is the displacement on the BGE instruction? (0.5 points) _10________________
Perhaps 1/10 of the class got this. More gave 9, off by 1 for partial credit. For some reason, 15 was a popular answer, but many gave no number or left the question blank.
. = 0 D: B A,B,C,D C = 'b' ALIGN 2 B: ASCII "ad" ALIGN 4 A = . - D W C H A |
|
Only a few did perfect work, while 1/6 of the class left the problem blank and 1/4 earned no credit for their answers. A number gave the bytes in row zero in the wrong order, many had trouble with align, and many put explicit zeros in uninitialized bytes -- the SMAL assembler definitely does not do that.
SUBR: STORES R1,R2 ADDSI R2,4 TESTR R3 BNE SUBQT ADDSI R3,-1 ADDSI R4,1 JSR R1,SUBR SUBQT: ADDSI R2,-4 LOADS PC,R2 | scratch space |
|
Only 1 did perfect work, while 1/5 of the class left the problem blank. Clerical errors were common, and many had difficulty with the displacement on the BNE instruction. At least 1/6 forgot the displacement halfword on the JSR instruction. Another popular error was to add a final halfword to fill out the table.
b) What register(s) does it expect parameters in? (0.5 points) __R3__R4_________________
This problem was fairly easy, although a few gae nonsense answers such as R1 or R2, answers that suggest a failure to understand the standard calling sequence on the Hawk. Some just listed R3.
c) What register(s) does it alter? (0.5 points) __R3__R4__R1__________________
The most popular answer omitted R1 for a small penalty. The code definitely modifies R1 when it does a recursive call. Some mentioned R2, a register that is carefully restored to its original value before return.
d) What register(s) does it return? (0.5 points) __R3__R4______________________
Over 1/5 earned no credit. A significant number omitted R3 after concluding (incorrectly) that the code returns a sum in R4. A surprising number suggested that R2 is a return value, suggesting again a significant misunderstanding of the standard calling sequence on the Hawk.
e) What does it do (in one line!)? (0.5 points) __if_(R3==0)_{_R3--;_R4++_}______________
Over 1/3 earned no credit. The code contained an error. Many read the code and did not notice the error. Had the code been correct, the answer would have been R4 = R4 + R3; R3 = 0; Many gave the first half of this answer for a small penalty.
One category of confused answers included discussion of loops. The code is recursive, but it contains no loop.