CS 354
Spring 1997
Sections 1 and 2
Solution
Quiz #2 for Friday Feb. 14
5 questions, 25 points total
Answers not yet verified!

1. (5 points)
a. Express 23.2 (base 5) in base 2, base 8, and base 16.


b. (version a) Express 162 (base 7) in base 10 and base 9.

b. (version b) Express 124 (base 6) in base 10 and base 9.

b. (version c) Express 122 (base 6) in base 10 and base 9.

2. (8 points) Fill in the following table.

                                                        (decimal)
                         ?-bit representation       value represented
--------------------------------------------------------------------------
largest positive         8-bit: 01111111       |  8-bit:  127
2's complement           7-bit: 0111111        |  7-bit:   63
integer                  9-bit: 011111111      |  9-bit:  255
--------------------------------------------------------------------------
largest negative         8-bit: 10000000       |  8-bit:  -128
2's complement           7-bit: 1000000        |  7-bit:   -64
integer                  9-bit: 100000000      |  9-bit:  -256
--------------------------------------------------------------------------
largest unsigned         8-bit: 11111111       |  8-bit:  255
integer                  7-bit: 1111111        |  7-bit:  127
                         9-bit: 111111111      |  9-bit:  511
--------------------------------------------------------------------------
largest negative         8-bit: 11111111       |  8-bit: -127
sign magnitude           7-bit: 1111111        |  8-bit:  -63
integer                  9-bit: 111111111      |  8-bit: -255
--------------------------------------------------------------------------

3. (4 points) (version a) What decimal value is represented by the IEEE single precision representation (given in hexadecimal) 0xc4802000?

(version b) What decimal value is represented by the IEEE single precision representation (given in hexadecimal) 0xc4040000? (version c) What decimal value is represented by the IEEE single precision representation (given in hexadecimal) 0xc2810000?

4. (4 points) The following SAL program should call a procedure which prints out all the integers between 0 and 100 that are evenly divisible by 3. Some key instructions are omitted from the program. Show what instructions (and labels if necessary) to add, and where to add them to make this program work correctly.

  .data
int:           .word  0     # for loop induction variable
end_value:     .word  100
result:        .word
rtn_addr:      .word        # return address from print
msg1:          .asciiz  "Evenly divisible by 3: \n"
newline:       .byte    '\n'

  .text
__start:  puts msg1

          la   rtn_addr, rtn1

          b    print

rtn1:     done


print:    move int, 1

for:      ble  int, end_value, endfor   # should be: bge

          rem  result, int, 3
                              # add:   bnz result, skip
          put  result         # should be:  put int

          put  newline

          add  int, int, 1    # add label  skip to this line

          b    for

endfor:   b    (rtn_addr)

5. (4 points) (version a)What does the following SAL program print out?


.data
str1:  .word  0x4e49433f
str2:  .asciiz "goodbye\n"
sum:   .word
.text
__start: add  sum, str1, 6
         puts str1
         puts str2
         done


5. (4 points) (version b) What does the following SAL program print out?


.data
str1:  .word  0x676f6f6b
str2:  .asciiz "bye\n"
sum:   .word
.text
__start: sub  sum, str1, 7
         puts str1
         puts str2
         done




5. (4 points) (version c) What does the following SAL program print out?

.data
str1:  .word  0x676f6f5a
str2:  .asciiz "bye\n"
sum:   .word
.text
__start: add  sum, str1, 10
         puts str1
         puts str2
         done