http:^^www.cs.wisc.edu^~cs354-2^cs354^solutions^q1.k.html
来自「This data set contains WWW-pages collect」· HTML 代码 · 共 112 行
HTML
112 行
Date: Tue, 05 Nov 1996 00:32:04 GMTServer: NCSA/1.5Content-type: text/htmlLast-modified: Fri, 13 Sep 1996 16:05:29 GMTContent-length: 2671<html><head><title>CS 354 - Quiz #1</title></head><body><table border=0 width=100% align=center><tr><td width=25%><td width=50% align=center><td width=25%><tr><tr><td><b>CS 354<br>Fall 1996 <br>Section 2 </b><td><td align=right><b>Karen's Solution</b><tr><td><td align=center><b>Quiz #1 for Friday September 13</b><br>3 questions, 25 points total<td></table><p><b>1. (7 points) </b> Your computer is running the following SAL program.<code><pre> .datamsg1: .asciiz "program started\n"msg2: .asciiz "program ending\n"aa: .word 0bb: .word 6cc: .word .text__start: puts msg1 bge aa, bb, print_sum add cc, cc, aa add aa, aa, 1print_sum: put cc puts msg2 done</pre></code>Just after the CPU fetches the instruction at label <code>print_sum</code>, 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?<ul>If the PC never changes (gets updated), then the CPU endlessly fetches and executes the instruction <code>put cc</code>. In this case, <code>cc</code> has the value 0, so the program endlessly prints zeros.</ul><p><b>2. (8 points) </b> The following SAL code contains a single error that causes it to execute incorrectly.<code><pre> .dataproc1_ra: .wordmsg: .asciiz "program running. . ."int1: .wordint2: .wordint3: .word .text__start: puts msg move int1, 3 move int2, 20 la proc1_ra, rara: b proc1 doneproc1: move int1, 3 move int2, 20 mul int3, int2, int1 b proc1_ra</pre></code><p>Give an brief (1 sentence) explanation of what goes wrong with this code.<ul>The return from the procedure branches to <code>proc1_ra</code> (into the data section).</ul><p>Show how to fix the code by adding to or modifying it.<ul>Modify the instruction <code>b proc1_ra</code> to be<br><code> b (proc1_ra)</code></ul><p><b>3. (10 points) </b> Write a SAL code fragment that sums and then prints out the result of the integers in the range <code>start <= integer <= end</code>. All variables are of type integer, and variables <code>start</code> and <code>end</code> are assumed to be assigned values before this code fragment is run.<ul>Here is just one possible solution:<br><code><pre> move sum, 0 move integer, startfor: bgt integer, end, done_for add sum, sum, integer add integer, integer, 1 b fordone_for: put sum</pre></code></ul>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?