Exam 1: MidtermSolutions and Comments
Part of
the homework for 22C:60, Summer 2005
|
Median = 5.8
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
Rough Scores: D C B A
Bit Pattern x 101010 111010 110010 010111 010011 Unsigned decimal ___42___ ___58___ 50 ___23___ ___19___ 1's complement of x _010101_ 000101 _001101_ _101000_ _101100_ 2's complement of x 010110 _000110_ _001110_ _101001_ _101101_ x as a 1's comp num __-21___ ___-5___ __-13___ ___23___ 19 x as a 2's comp num __-22___ ___-6___ __-14___ 23 ___19___
5 did perfectly here, an equal number had extreme problems with the interpretation of x as a one's or two's complement number, getting all the answers in the final two rows wrong.
. = 0 || Address 3 2 1 0
W #01234567 || |----|----|----|----|
; --solved to here-- || 000000: | 01 | 23 | 45 | 67 |
A: B A, B, C, D || |----|----|----|----|
ALIGN 2 || 000004: | 10 | 0C | 08 | 04 |
B: W 0 || |----|----|----|----|
. = B || 000008: | 00 | 00 | FF | FF |
H -1 || |----|----|----|----|
ALIGN 4 || 00000C: | 33 | 32 | 31 | 30 |
C: ASCII "0123" || |----|----|----|----|
ALIGN 4 || 000010: | | | 35 | 34 |
D: B "4", "5" || |----|----|----|----|
END || 000014: | | | | |
|----|----|----|----|
At least 6 earned no credit here. Common errors included failing to notice that A, B, C and D are labels, failing to notice the effect of the .=B line, failing to correctly interpret the ALIGN directives, and failing to properly convert ASCII to hex.
|| 000100: E301
LIL R3,#1FFFC || 000102: FFFC
; --solved to here-- ||
LIL R4,#0FFFF || 000104: __E400__
LP: ||
STORES R3,R3 || 000106: __FFFF__
ADDSI R3,-4 ||
CMP R3,R4 || 000108: __F3A3__
BGT LP ||
|| 00010A: __13CC__
||
|| 00010C: __2034__
||
|| 00011E: __0EFC__
Extra Credit: What does this probgram fragment do (the answer is very short)? (1 point max)
__it sets each word in RAM to hold its address _________________
At least 4 did perfect work here. One earned no credit at all, and the remainder made mistakes that varied from the careless to the odd.
SUBTITLE TIMES - multiply
RA = 0 ; activation record structure
I = 4
J = 8
ARSIZE = 12
; -------------------
TIMES: ; on entry, R3 and R4 are i and j, unsigned integers
; on exit R3 is i * j
STORES R1,R2
_STORE R3,R2,I_________
_STORE R4,R2,J_________
STORE R4,R2,J
TESTR R4
BZR MULDO ; if (j == 0) {
_LIS R3,0____________
JUMPS R1 ; return 0
MULDO: ; }
SL R3,1
_SR R4,1____________
ADDI R2,R2,ARSIZE
_JSR R1,TIMES________
ADDI R2,R2,-ARSIZE ; R3 = times( i << 1, j >> 1 )
LOADCC R4,R2,J
TBIT R4,0
BCR MULQT ; if (odd(j)) {
_LOAD R4,R2,I_________
ADD R3,R3,R4 ; R3 = R3 + i
MULQT: ; }
_LOADS R1,R2___________
; return R3
_JUMPS R1______________
Only one student earned no credit here, many earned half credit and a few earned 3/4 credit. Careless errors were common, but some student seemed intent on using instructions from some other algorithm, as if this might have been code from the book. It was not.