Date: Tue, 05 Nov 1996 00:32:04 GMT Server: NCSA/1.5 Content-type: text/html Last-modified: Fri, 13 Sep 1996 16:05:29 GMT Content-length: 2671
CS 354
Fall 1996 Section 2 | Karen's Solution | |
Quiz #1 for Friday September 13
3 questions, 25 points total |
1. (7 points) Your computer is running the following SAL program.
Just after the CPU fetches the instruction at label
.data
msg1: .asciiz "program started\n"
msg2: .asciiz "program ending\n"
aa: .word 0
bb: .word 6
cc: .word
.text
__start: puts msg1
bge aa, bb, print_sum
add cc, cc, aa
add aa, aa, 1
print_sum: put cc
puts msg2
done
print_sum
, the computer breaks. The circuitry in the PC update hardware fails such that the PC is never updated again. What happens to the execution of the SAL program?
put cc
. In this case, cc
has the value 0, so the program endlessly prints zeros.
2. (8 points) The following SAL code contains a single error that causes it to execute incorrectly.
.data
proc1_ra: .word
msg: .asciiz "program running. . ."
int1: .word
int2: .word
int3: .word
.text
__start: puts msg
move int1, 3
move int2, 20
la proc1_ra, ra
ra: b proc1
done
proc1: move int1, 3
move int2, 20
mul int3, int2, int1
b proc1_ra
Give an brief (1 sentence) explanation of what goes wrong with this code.
proc1_ra
(into the data section).
Show how to fix the code by adding to or modifying it.
b proc1_ra
to be
b (proc1_ra)
3. (10 points) Write a SAL code fragment that sums and then prints out the result of the integers in the range start <= integer <= end
. All variables are of type integer, and variables start
and end
are assumed to be assigned values before this code fragment is run.
move sum, 0
move integer, start
for: bgt integer, end, done_for
add sum, sum, integer
add integer, integer, 1
b for
done_for: put sum