Midterm I Solutions and Comments

Part of materials for 22C:40, Fall 2003
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Grade Distribution

                                 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

Exam Questions and Solutions

Note: There were two versions of the exam. These are mixed here!

  1. Fill in the following table; values in each row should be numerically equal and values in each column should all be in the same base. All numbers are unsigned. The top row is worked for you! (2 points)
            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.

  2. Convert the following signed decimal numbers into each of the indicated 6-bit signed binary number systems. The top rows are worked for you. (2 points)
           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.

  3. Translate the following brief useless SMAL code to a sequence of words loaded in memory. The spaces to the right are labeled with a word addresses; fill in the hexadecimal value that goes in that word; use question marks for unknown digits. The result of assembling the first lines are given. (2 points)
            . = 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.

  4. Hand assemble the Hawk program fragment shown below, giving the result as a sequence of halfwords given in hexadecimal. Again, the results are given for the first line. (2 points)
                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.

  5. Complete the following SMAL Hawk program. When complete, it should have a function that conforms to the comments, and this function should be somewhat familiar! (2 points)
        ;       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