Exam 1: MidtermSolutions and Commentary
Part of
the homework for 22C:60, Fall 2004
|
X X X MEAN = 8.06 X MEDIAN = 8.3 X X X X X X X X X X X X X X X X X X X X X X X 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 = 26.07 X X MEDIAN = 26.1 X X X X X X X X X X X X X X X X X X X X X X X X X X X ________X_____X_X_X_X_X_X_X_X_X_X_X_X_X_____ 14. 16. 18. 20. 22. 24. 26. 28. 30. 32. 34 (roughly) F D C B A
base 2 base 10 base 16 101100 44 2C 011101 ___29___ ___1D___ _100011_ 35 ___23___ _110101_ ___53___ 35
All but 8 did perfectly here.
natural signed one's two's decimal magnituede complement complement 111111 -31 -0 -1 100101 -5 -26 -27 110110 __-22___ ___-9___ __-10___ 011110 ___30___ ___30___ ___30___ 100010 ___-2___ __-29___ __-30___
Half the class did perfectly here, only 5 had more than 3 mistakes. The most common errors were in the interpretation of 011110, which is a positive number under all the given number systems. There were also a considerable number of problems with 100010.
The mistake on the exam (heading column 1 with "natural decimal") does not seem to have caused problems. (The heading should have read "bit pattern".)
. = 0 || Address Value W #76543210 || ; --solved to here-- || 000000: 76543210 A: B #98 || ALIGN 4 || 000004: _??????98_______ B: H #DCBA || ALIGN 4 || 000008: _????DCBA_______ C: B #34 || ALIGN 4 || 00000C: _??????34_______ D: ASCII "ABCD" || ALIGN 4 || 000010: _44434241_______ B A,B,C,D || END || 000014: _100C0804_______
Only 4 students got this perfect. Many students did not follow the instructions to fill in unknown digits with question marks. Many gave no indication of unknowns (-0.4); more used leading zero digits (-0.2). One of the most common errors was to forget that this machine stores the lowest byte first, leading to the reversal of the byte order in "ABCD". The other equally common error was to fail to make sense of the 4 labels A, B, C and D used on the last line.
LIL R1,#010000 || 000000: E101 ; --solved to here-- || 000002: 0000 LABEL: || STORES R0,R1 || 000004: __F0A1__ ADDSI R1,1 || CMP R1,R2 || 000006: __11C1__ BLEU LABEL || || 000008: __2012__ || || 00000A: __07FC__ || || 00000C: ________
5 did perfect work here, The most common error was a minor one, use of an odd source to look up the CMP opcode. The second major source of problems was with the BLEU instruction, where many students forgot to negate the branch displacement or counted starting from the wrong place.
Extra Credit: What does this do?
This code clears memory from the start of RAM up to the address held in R2.
Only one did well here, and 3 more earned over half credit. For less than half credit, a large number gave long-winded instruction by instruction descriptions of how it does this, without ever distilling their answers down to descriptions of what gets done. Over half the class got no credit because they had significant numbers of details wrong while also not reaching any conclusion about what is being done. Few left this blank!
; STRTOI convert an ASCII string from decimal ; to a 32 bit unsigned binary integer ; ------------------- STRTOI: ; function called with return address in R1 ; on entry, R3 points to the start of the string ; _________________________________ ; on exit, R3 points to the character after the last digit ; on exit, R4 holds the binary value of the number ; on exit, R5 holds the character after the last digit ; _________________________________ LIS R4,0 ; R4 = 0 STRTOIL: ; while (TRUE) { LOADS R5,R3 EXTB R5,R5,R3 ; R5 = *(char *)R3 CMPI R5,'0' ; if ((R5 < '0') BLT STRTOIX _______________________ ; exit; CMPI R5,'9' ; || (R5 > '9')) BGT STRTOIX _______________________ ; exit; ADDI R5,R5,-'0' ; R5 = R5 - '0'; SL R4,1 ADDSL R4,R4,1 ; R4 = R4 * 10; (really) ADD R4,R4,R5 ; R4 = R4 + R5 ADDSI R3,1 _______________________ ; R3++; BR STRTOIL ; } STRTOIX: JUMPS R1 ; return
8 did excellent work here. The hardest part of the problem had to do with the return value in R5; 15 suggested that this held the last digit (-0.2) and 18 had useless answers (-0.4). 6 used the wrong conditional branch instructions or branched to the wrong labels (-0.2 each error), and as many indicated that, on entry, R3 holds the string, as opposed to being a pointer to the string (-0.2). This distinction is important!