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 - Quiz #1
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.

  .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
Just after the CPU fetches the instruction at label 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?

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.

Show how to fix the code by adding to or modifying it.

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.