CS 354, version A
Fall 2003
Name: A KEY
ID:___________________
Login:_____________________
Exam 1

No electronic devices may be used while taking this exam. Examples of devices not allowed are calculators, pagers, cell phones, wrist calculators/computers, laptop computers, pocket computers. Each student is allowed one 8.5 by 11 inch sheet of paper with handwritten notes. The notes may be on both sides of the paper.

Show all work, and do any/all calculations on the exam. Extra scratch paper may not be used.

Exam Score
Qtn 1 = _____ /   10
Qtn 2 = _____ /   10
Qtn 3 = _____ /   9
Qtn 4 = _____ /   6
Qtn 5 = _____ /   6
Qtn 6 = _____ /   9
Total = _____ / 50



Question 1 (10 points)

(A) In the space on the right, write a SAL program fragment equivalent to the pseudo-code on the left. Assume that i and product are already declared.

  # Pseudo-Code                                  # SAL Equivalent
  product = 1
  for i = 1 to 10 {
     product = product*i
  }

                                              move product, 1
                                              move i, 1
                                   begin_for: bgt i, 10, end_for
                                              mul product, product, i
                                              b begin_for
                                    end_for:


(B) Consider the SAL code you just wrote, and focus on the mul instruction used to implement the multiply. When assembling the above code, how many times will an assembler encounter the mul instruction?


1 (2 okay for technical reasons)


(C) When a processor executes above code, how many times will it encounter the mul instruction?


10



Question 2 (10 points) Fill in the banks so that the following program reads characters until a newline and echos them with all letters in upper case. For example, input Hi, McD! would cause output HI, MCD!

        .data
char:   .byte
char_a: .byte 'a'
char_z: .byte 'z'
char_nl: .byte '\n'
char_mask: .byte 0xdf


        .text
__start:
        get char
        beq char, char_nl, new_line
        blt char, char_a,  not_lowercase
        blt char_z, char   not_lowercase

        and char, char, char_mask
        ____________________________    # may not be necessary
        ____________________________    # may not be necessary

not_lowercase:
        put char
        b __start

new_line:
	put char_nl
	done
 

Question 3 (9 points)

(A) Translate 43.21 base six into a number in base ten. The non-integer part of your answer may be a proper fraction or a two-digit decimal.


27.36 or 27 13/36



(B) Translate 46.21 base ten into a number in base six. Your answer need only have two digits after the radix point.


114.11


(C) Assume an 8-bit memory location holds the bit pattern 10011111. What decimal value is represented if this is 8-bit sign-magnitude? What if 8-bit two's complement?


SM:  -31 
2SC: -97



Question 4 (6 points) At done, what are the values of X and Y?

        .data
X:      .word 0x3456789a
Y:      .word
mask:   .word Ox18
					Y = 0x18 = 24
        .text				X = 0x56789a34
__start:
        and Y, X, mask
        ror X, X, Y
        done

Question 5 (6 points) List the bit patterns of beta that would cause overflow when added with the bit pattern 1101 using 4-bit two's-complement addition.

      beta              [-8,+7]
    + 1101	        -3
    -------------       
      OVERFLOW!         -8    1000
                        -7    1001
                        -6    1010





Question 6 (9 points) Consider artificially-small 11-bit floating-point numbers that are stored just like 32-bit single-precision floating-point numbers, except that the fraction is 21 bits shorter. Thus, there is a 1-bit sign, an 8-bit biased-127 exponent, and a 2-bit fraction (not counting the hidden bit).

(A) (6 points) Convert -2.5 (base ten) to this format. Show your answer in binary.

-2.5 base ten = -10.1 base two = - 1.01 x 2^+1
S = 1
EEEEEEEE = +1 + 127 = 128 base ten = 10000000
FF = (1) 01 = 01
S EEEEEEEE FF = 1 10000000 01

(B) (4 points) With this format, what is the smallest positive integer that cannot be represented exactly? Why?
1 = (1).00 x 2^0       6 = (1).10 x 2^2
2 = (1).00 x 2^1       7 = (1).11 x 2^2
3 = (1).10 x 2^1       8 = (1).00 x 2^3
4 = (1).00 x 2^2       9 = (1).001*** x 2^3
5 = (1).01 x 2^2       Can't represent 9 due to too long fraction