Exam 2

22C:18, Summer 1997, 12 points

Douglas W. Jones
Name ______________________________________   Section ___________

This exam is open-book and open-notes, but closed neighbor! You have one (academic style) hour, which is defined as 50 minutes. Answer the questions in the space provided. If you need scratch paper, feel free to use the backs of the exam pages, but please transcribe your answers into the blanks provided.
  1. Fixed point numbers. In the following table, all numbers in each column share the same base, while all numbers in each row have the same value, fill in the blanks. (2.4 points)
        Base 2          Base 10    |    Base 2          Base 10          
                                   |
       1110.1011         14.6875   |
                                   |  _____._____         3.8125
       1101.0101      _____._____  |  
                                   |  _____._____         9.5625
       0111.1001      _____._____  |
    

  2. Floating point numbers: Consider a system with the following format:
                             _ _ _ _ _ _ _ _
                            |_|_|_|_|_|_|_|_|
                            |s| exp |  man  |
    

    Answer the following questions for this number system, giving answers in conventional decimal form: (2.4 points)

    1. What is the largest possible exponent? ___________

    2. What is the smallest possible exponent? ___________

    3. What is the largest possible mantissa? ___________

    4. What is the smallest positive normalized mantissa? ___________

    5. What is the largest positive number in this system? ___________

    6. What is the smallest positive number in this system? ___________
    
    
    
  3. Programming with various number representations: Write code to bridge the gap between the indicated pre and postconditions: (2.4 points)
         ; A is in R3, an 8 digit fixed point unsigned BCD number;
         ; A has 2 digits of fraction and 8 digits of integer part!
         ; B is pointed to by R8; B is a BCD integer.
         ; assume that BCDTOI and ITOBCD converts between 8 digit BCD
         ; numbers and binary integers in R3, and that they know nothing
         ; about fixed point numbers!
    
               CALL    BCDTOI    ; convert R3 to binary
    
               ____________________________
    
               ____________________________
    
               ____________________________
    
               CALL    ITOBCD    ; convert R3 back to decimal
    	     
         ; R3 now contains 10*A
    
               ____________________________
    
               ____________________________
    
               ____________________________
    
         ; R3 now contains 10*A rounded to the nearest integer
    
               ____________________________
    
               ____________________________
    
               ____________________________
    
         ; B now contains 10*A, in the format required for B
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

  4. Given our standard activation record structure, where R2 points to the activation record that holds the current set of local variables, write code to bridge the gap between the following pre and post conditions: (2.4 points)
    	; A is a common holding a global array of integers;
    	; AP is the label on a word pointing to A[0].
    	;
    	; I is a common holding an integer;
    	; IP is the label on a word pointing to I.
    	;
    	; I is known to be within bounds for indexing into A.
    	;
    	; B is the displacement from R2 of a local array of
    	; integers.  B points to location 0 of that array.
    	;
    	; J is the displacement from R2 of a local integer.
    	;
    	; J is known to be within bounds for indexing into B.
    	
               ____________________________
    
               ____________________________
    	
               ____________________________
    
               ____________________________
    	
               ____________________________
    
               ____________________________
    
    	; R3 holds the value of A[I]
    
               ____________________________
    	
               ____________________________
    
               ____________________________
    	
               ____________________________
    
               ____________________________
    
    	; B[J] holds the value of A[I]
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
  5. Procedures and functions! The following code is missing some key bits. Supply them! them (2.4 points):
         ; --------------------
         ; R2 points to AR with following format
         ;RA=    0  ; return address
         TIMEX=  4  ; extra value to add
         AR=     8  ; size of activation record
    
         TIMES:  ; horrible function to multiply two words
                 ; algorithm:  A x B = if B zero 0
                 ;                   = if B even B/2 x (2 x A)
                 ;                   = if B odd (B/2 x (2 x A)) + A
                 ; expects argument in R3, R4.
                 ; returns result in R3.
                 ; wipes out R5
    
    	     TEST    R4
    	     BZS     TIMQT     ; quit if B is zero
    
                 _________________ ; save return address
    
    	     MOVE    R5,R3     ; \
    	     MOVE    R3,R4     ;  > swap A and B
    	     MOVE    R4,R5     ; /  (R5 ends up a copy of A)
    	     SRU     R4	       ; get B/2, set C if B odd
    	     BCS     TIMODD
    	     LIS     R5,0      ; if B even, R5=0 else R5=A
         TIMODD:
    	     _________________ ; set aside R5 as extra value
    
    	     SL	     R3,1      ; get 2xA
    
    	     _________________ ; \
    
    	     _________________ ;  > recursive call
    
    	     _________________ ; /
    
    	     _________________ ; Recover extra value in R4
    
    	     ADD     R3,R3,R4  ; add it to return value
    
                 _________________ ; recover return address
    
         TIMQT:  JUMPS   R1