Exam 1

22C:18, Fall 1996

Monday June 30, 1997

Douglas W. Jones
NAME: ______________________________________________________

This exam is open book, open notes, open mind but closed neighbor. This exam is worth 12 points, for 50 minutes of work! Each point is therefore worth just over 4 minutes of your time!

  1. (2 points or 8 minutes) Fill in the following table, where all values in each row are numerically equal and the values in each column are all in the same number base. All numbers are unsigned and represented in conventional pencil-and-paper form. The top row is worked for you!
            base2       base8       base10      base16
    
            10110         26          22          16
    
            10011      ________    ________    ________
    
           ________       30       ________    ________
    
           ________    ________       30       ________
    
           ________    ________    ________       17   
    
  2. (2 points or 8 minutes) Convert the following conventional signed decimal numbers into each of the indicated 6-bit binary signed number systems. Again, the top row is worked for you:
           natural      signed       one's       two's
           decimal    magnituede  complement  complement
    
             -5         100101      111010      111011
    
              5        ________    ________    ________
    
            -20        ________    ________    ________
    
             20        ________    ________    ________
    
            -27        ________    ________    ________
    
    
    
    
    
  3. (2 points or 8 minutes) Consider the following brief (and useless) assembly language program, written in the SMAL assembly language. Show the values this program places into the Hawk memory, in the spaces provided to the right, using question marks for unknowns. Memory addresses are given in hexadecimal; give the contents of each word of memory in hexadecimal. The result of assembling the first two lines of the program are given:
            . = 0               ||  Address  Value
                W     #1234567  ||
            ; --solved to here--||  000000:  01234567
                B     #89       ||
                H     #ABCD     ||  000004: ________________
                ALIGN 4         ||
                W     "AB"      ||  000008: ________________
                ASCII "AB"      ||
            LAB:                ||  00000C: ________________
                ALIGN 4         ||
                W     LAB       ||  000010: ________________
                END             ||
                                ||  000014: ________________
    
    

  4. (3 points or 12 minutes) 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.
                LIL  R1,#012345 ||  000000:   E101
            ; --solved to here--||  000002:   2345
            LABEL:              ||
                MOVE  R2,R1     ||  000004: ________
                ADDSR R1,R0,8   ||
                ADDSI R1,-1     ||  000006: ________
                BZR   LABEL     ||
                LEA R2,R2,#DCBB ||  000008: ________
                                ||
            Only if you have    ||  00000A: ________
            time, what values   ||
            are in R1 and R2?   ||  00000C: ________
                                ||
            R1 = ______________ ||  00000E: ________
                                ||
            R2 = ______________ ||  000010: ________
    
    
    
    
    
    
    

  5. (3 points or 12 minutes) 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!
    	    TITLE	AOTOI ROUTINE
        ;       convert an octal number in an ASCII string
        ;       to a 32 bit unsigned binary integer
        ; -------------------
    	    INT	AOTOI
        AOTOI:  ; function called with return address in R1
        	    ; does not use R2, destroys R4, R5
        	    ; on entry, R3 points to the string holding the number
        	    ; on exit, R3 is the integer value of the string
        	    ; the string terminator is any non octal digit
    	    MOVE    R4,R3
    	    CLR     R3
        AOTOIL:
                LOAD    R5,R4    ; get a character
    	    EXTB    R5,R5,R4 ; extract it
    	    ; convert the ASCII character in R5 to binary
    	    ; and check to see if it is a legal octal digit
    	    ; if not, branch to AOTOIQ
    
    	    ____________________________________
    
    	    ____________________________________
    
    	    ____________________________________
    
    	    ____________________________________
    
    	    ____________________________________
    
    	    ; Now, we know R5 is a digit, in binary
    	    ; so compute R3 = R3*8 + R5
    
    	    ____________________________________
    
    	    ____________________________________
    
    	    ____________________________________
    
    	    ____________________________________
    
    	    ADDSI   R4,1     ; setup to get next byte
    	    BR      AOTOIL   ;   go iterate
        AOTOIQ:
    	    JMPS    R1       ; return
    	    END