Midterm I Solutions and Comments
Part of
materials for 22C:40, Fall 2003
|
X Mean = 6.96 X X Median = 6.7 X X X X X X X X X X X X X X X X X X X X X X X 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
Note: There were two versions of the exam. These are mixed here!
base 2 base 10 base 16 10110 22 16 11001 ___25___** ___19___ _11111__ 31 ___1F___ 101010__** ___42___ 2A
This was an easy problem, 42 had perfect scores, and only 3 had more than one error. Most of the errors were clustered on the two blanks above marked with asterisks. That is, binary to decimal conversion caused a few problems, and so did hexidecimal to binary conversion.
natural signed one's two's decimal magnituede complement complement -7 100111 111000 111001 7 000111 000111 000111 -19 _110011_ _101100_* _101101_* 19 _010011_ _010011_* _010011_* -26 _111010_* _100101_ _100110_
Again, this was a relatively easy problem; 37 made no errors, and only 6 made more than one error. The parts marked with asterisks above attracted more than the usual number of errors. Several people negated the positive number unnecessarily, several had difficulty negating it, and several had problems with the larger magnitude of the final value.
. = 0 || Address Value W #76543210 || ; --solved to here--|| 000000: 76543210 H #AB89 || ALIGN 4 || 000004: ____????AB89____ H "BA" || ASCII "BA" || 000008: ____41424241____ B #34 || X: B Y || 00000C: ____????0734____ ALIGN 4 || W X || 000010: ____0000000D____ Y = 7 || END || 000014: ________________
This problem was difficult. 22 earned less than half credit here, and 8 earned less than 1/4 credit. On the other hand, 8 earned more than 3/4 credit, and one had a perfect answer. The hardest issues were byte order (the Hawk machine stores the least significant byte first) and the value of the label X. ASCII conversion and questions of location counter management caused almost as much trouble. Another thing that many students had trouble with was following directions! The question asked for 32-bit words, not 16-bit halfwords, and many insisted ion giving the latter.
LIL R1,#012345 || 000000: E101 ; --solved to here--|| 000002: 2345 LABEL: || MOVE R2,R1 || 000004: __F2F1__ LEA R3,R2,-8 || ADDSI R5,-1 || 000006: __F372__ BR LABEL || 08: FFF8 <-- sorry about this || 00000A: __15CF__ || || 00000C: __00FB__ || || 00000E: ________
This problem was difficult, with ony 6 correct answers. On the other hand, only 8 students got half credit or less, and 33 got more than 3/4 credit. The biggest problems were with the offset on the BR instruction, where many students had off-by-one errors and over 15 had more serious errors, and the representation of -8 on the LEA instruction, where at least 20 students did not understand that this was a full 16-bit constant, and many students had trouble negating it.
; STRTOI convert an ASCII string from decimal ; to a 32 bit unsigned binary integer ; ------------------- STRTOI: ; function called with return address in R1 ; does not use R2, destroys R4, R5 ; on entry, R3 points to the string s ; on exit, R3 is the integer value of the string ; the string terminator is any non decimal digit MOVE R4,R3 ; move s to R4 CLR R3 ; int value = 0; STRTOIL: ; while (true) { LOAD R5,R4 EXTB R5,R5,R4 ; int digit = *s; ; convert the ASCII character in digit to binary and ; check to see if it is legal; if illegal, exit loop ADDI R5,R5,-'0' ; digit = digit - 0; BLT_____STRTOIQ_____________________ CMPI R5,9 BGT_____STRTOIQ_____________________ ; Now, we know digit is legal, and in binary ; so incorporate it into the value of the number SL R3,1 ADDSL R3,R3,1 ; value = value * 10; (really!) ADD_____R3,R3,R5____________________ ; Now, the digit is converted, so advance to ; the next byte of the string s. ADDSI___R4,1________________________ BR STRTOIL STRTOIQ: ; } (end of loop) JMPS R1 ; return value
This was the hardest problem on the exam. Close to 1/3 of the class wrote random machine instructions into the blanks. Those were severely penalized! You wouldn't answer a question on an English exam with randomly chosen words, would you? Half the class got the BGT instruction, and most understood that this must be a branch instruciton. While only one got the other branch instruction correct, 1/4 of the class understood that this must be a branch instruction. 1/5 got the ADD instruction right, and only a few more understood that something like an add was needed here. 2/5 got the ADDSI instruction