|
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.
23.2 (base 5) = 2 x 5**1 + 3 x 5**0 + 2 x 5**-1
= 10 + 3 + 2/5
= 13.4 (base 10)
13 (base 10) is 1101 (base 2)
.4 x 2 = 0.8 (msb = 0)
.8 x 2 = 1.6
.6 x 2 = 1.2
.2 x 2 = 0.4
.4 x 2 (it repeats from here)
so, .4 (base 10) is .0110 (base 2), where all 4 bits repeat.
base 2 answer: 1101.0110, where the 4 bits right of the binary pt. repeat
base 8 answer: 15.3146, where the 4 digits right of the radix pt. repeat
base 16 answer: d.6, where the 1 digit right of the radix pt. repeats
162 (base 7) = 1 x 7**2 + 6 x 7**1 + 2 x 7**0 = 49 + 42 + 2 = 93 (base 10) 93/9 = 10, remainder = 3 (lsb) 10/9 = 1, = 1 1/9 = 0, = 1 so, 162 (base 7) is 113 (base 9)
124 (base 6) = 1 x 6**2 + 2 x 6**1 + 4 x 6**0 = 36 + 12 + 4 = 52 (base 10) 52/9 = 5, remainder = 7 (lsb) 5/9 = 0, = 5 so, 124 (base 6) is 57 (base 9)
122 (base 6) = 1 x 6**2 + 2 x 6**1 + 2 x 6**0 = 36 + 12 + 2 = 50 (base 10) 50/9 = 5, remainder = 5 (lsb) 5/9 = 0, = 5 so, 122 (base 6) is 55 (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?
0x c 4 8 0 2 0 0 0 1100 0100 1000 0000 0010 0000 0000 0000 S EXP MANT. 1 10001001 000 0000 0010 0000 0000 0000 This is 1.0000000001 (base 2) x 2**10 (base 10). Moving the binary point 10 places to the right gives 10000000001. x 2**0 This is 1024 + 1 = 1025. Don't forget that it's negative: -1025(version b) What decimal value is represented by the IEEE single precision representation (given in hexadecimal) 0xc4040000?
0x c 4 0 4 0 0 0 0 1100 0100 0000 0100 0000 0000 0000 0000 S EXP MANT. 1 10001000 000 0100 0000 0000 0000 0000 This is 1.00001 (base 2) x 2**9 (base 10). Moving the binary point 9 places to the right gives 1000010000. x 2**0 This is 512 + 16 = 528. Don't forget that it's negative: -528(version c) What decimal value is represented by the IEEE single precision representation (given in hexadecimal) 0xc2810000?
0x c 2 8 1 0 0 0 0 1100 0010 1000 0001 0000 0000 0000 0000 S EXP MANT. 1 10000101 000 0001 0000 0000 0000 0000 This is 1.0000001 (base 2) x 2**6 (base 10). Moving the binary point 6 places to the right gives 1000000.1 x 2**0 This is 64 + .5 = 64.5 Don't forget that it's negative: -64.5
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
NIC?goodbye
goodbye
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
gookbye
bye
.data
str1: .word 0x676f6f5a
str2: .asciiz "bye\n"
sum: .word
.text
__start: add sum, str1, 10
puts str1
puts str2
done
gooZbye
bye