| CS 354, version A Fall 2004 | ANSWER KEY | |
| 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 Q1 = _____ / 8 Q2 = _____ / 10 Q3 = _____ / 8 Q4 = _____ / 10 Q5 = _____ / 10 Q6 = _____ / 10 Total = _____ / 56 |
Question 1 (8 points)
Part A
Assume that we have a 1-bit unsigned integer representation.
List each possible representation, and give the
decimal value or values represented for each bit pattern.
representation decimal integer value
-------------- ---------------------
0 0
1 1
Part B
Same question as in Part A, but with a 1-bit two's complement
representation.
representation decimal integer value
-------------- ---------------------
0 0
1 -1
Question 2 (10 points)
Part A
Identify the six steps of the instruction fetch and execute cycle
in their proper order:
Of the 6 steps, only step 2, PC update, can be placed at a different position. It could be placed at any position within the 6.
Question 3 (8 points)
A 354 student has written this SAL code fragment:
.data
loop_count: .word 0
sum: .word 0
end_value: .word
.text
move sum, 0
for_loop: move loop_count, 1
bgt loop_count, end_value, end_for
add sum, sum, loop_count
add loop_count, loop_count, 1
b for_loop
end_for:
This code fragment is supposed to
sum all integers from 1 up to and including the value in the
variable
end_value.
Assume that the value of variable end_value is
set to a positive integer value in an earlier part of the program
that is not within this code fragment.
The code remains in an infinite loop, since the initialization
of the loop induction variable (loop_count) is
within the loop.
The code will likely cause an overflow exception when the value
of sum overflows.
.data
loop_count: .word 0
sum: .word 0
end_value: .word
.text
move sum, 0
move loop_count, 1 # label removed from this instruction
for_loop: bgt loop_count, end_value, end_for
add sum, sum, loop_count
add loop_count, loop_count, 1
b for_loop
end_for:
Question 4 (10 points)
Part A
Give the decimal value 20.3 in base 4.
Show any repeating digits by placing a bar over those digits that repeat.
Q R
20/4 5 0
5/4 1 1
1/4 0 1
So, 20 (base 10) is 110 (base 4)
.3 x 4 1.2 1
.2 x 4 0.8 0
.8 x 4 3.2 3
.2 x 4 (repeats)
__
So, .3 (base 10) is .103 (base 4); only the last two digits repeat
Full answer:
__
20.3 (base 10) is 110.103 (base 4)
Part B
Give the octal value 60.2 in decimal.
Show any repeating digits by placing a bar over those digits that repeat.
6 x 8^1 + 0 x 8^0 + 2 x 8^(-1)
48 + 0 + .25
48.25
Question 5 (10 points)
Give the IEEE single precision floating point representation
(in hexadecimal) for the decimal value
-24.25.
24 (decimal) is 11000 (binary) .25 (decimal) is .01 (binary) 11000.01 Move the radix point to put this in normalized form. 1.100001 X 2^4 | ----> the mantissa portion of the answer The exponent is 4. 4 + 127 = 131 131 in 8-bit, unsigned representation is 10000011 In binary, putting the pieces together: S E F 1 10000011 10000100000000000000000 Respacing, and then translating to hexadecimal: 1100 0001 1100 0010 0000 0000 0000 0000 0x c 1 c 2 0 0 0 0
Question 6 (10 points)
Part A
Write a SAL code fragment along with all variable declarations
necessary
for a SAL procedure named incr_aa that increments
an integer variable
named aa.
Part B
Write a SAL code fragment that uses
.data
incr_aa_ra: .word
aa: .word
.text
incr_aa: add aa, aa, 1
b (incr_aa_ra)
incr_aa
to increment a variable named xx.
.data
xx: .word
.text
move aa, xx
la incr_aa_rtn, rtn
b incr_aa
rtn: move xx, aa