Exam 1 Solutions

22C:18, Spring 1996, 12 points

Douglas W. Jones
  1. Conversion of unsigned numbers between number bases: The complete table is given here. Errors students made were generally matters of simple carelessness:
        Base 2           Base 8           Base 10           Base 16
    
       11101011           353               235               DB
        101010             52                42               2A
       1010111            127                87               57
        111111            177               127               7F
      100100111           447               295              127
    

  2. Two's complement numbers: The complete table is presented here. Some people had serious problems with when to complement and when not to (as discussed in class during the pre-exam review).
        Decimal    -25        20       -12         22       -14 
    
        Binary    100111    010100    110100     010110    110010
    

  3. Assembly pseudo operations: The result of assembling the following M68000 code fragment into memory is given. assuming that the initial value of the location counter is 00100000 (hexadecimal). Show your results as consecutive 32 bit longwords expressed in hexadecimal, showing unknown values as ?. Problems here were mostly conceptual! (3 points)
        A:  EQU  $1        Location    Value      Comment
    
        ;   comment        00100000:  00000001  DC.L A
            DC.L A         00100004:  00100010  DC.L B
            DC.L B         00100008:  00100013  DC.L C
            DC.L C         0010000C:  41424300  DC.B 'ABC',0
            DC.B 'ABC',0   00100010:  ????????  DS.B 3; DS.B A
        B:  DS.B 3
        C:  DS.B A
    

  4. M68000 instruction format: The result of assembling the following M68000 code fragment into memory is given as consecutive 16 bit binary words. Problems here were a mixture of the conceptual and the careless (putting fields in the wrong order, for example).
         MOVE.L  (SP),$1234(A3)    Location       Value
         ADDQ.W  #7,SP                      .   .  .  .  .
         CMPA.W  -(A3),A0             00:   0010111101010111
                                      02:   0001001000110100
                                      04:   0101111001001111
                                      06:   1011000011100011
    

  5. M68000 Programming: The gap between precondition and postcondition can be bridged as follows. All kinds of problems cropped up here. Perhaps the best general description of most of the problems is that students tried to use instructions or addressing modes they didn't really understand.
          ; Precondition:  A0 points to a record in memory.
          ; X and Y are symbolic names for fields in the record.
          ; Field X is a word; field Y is an array of 20
          ; long words (array indices go from 0 to 19).
    
                  MOVE.W  X(A0),D0      ; get A0^.X (the subscript)
                  ASL.L   #2,D0         ; multiply by array entry size
                  MOVE.L  Y(A0,D0.W),D0 ; get A0^.Y[ subscript ]
    
          ; Postcondition:  D0 holds A0^.Y[X] (or A0->Y[X] in C)