📄 http:^^www.cs.wisc.edu^~cs354-2^cs354^solutions^a1hw.ans.html
字号:
Date: Tue, 05 Nov 1996 00:32:06 GMTServer: NCSA/1.5Content-type: text/htmlLast-modified: Wed, 25 Sep 1996 20:46:03 GMTContent-length: 2940<!--This file created 9/12/96 4:06 PM by Claris Home Page version 1.0b1--><HTML><HEAD> <TITLE>a1hw.ans.html</TITLE> <X-SAS-WINDOW TOP=67 BOTTOM=422 LEFT=-704 RIGHT=-174></HEAD><BODY><H2 ALIGN=CENTER><B>CS354, Fall 1996</B></H2><H2 ALIGN=CENTER><B>Homework 1, due Wednesday September 18 at the</B></H2><BLOCKQUOTE><P>(1) T/F, 10 points, 1 point each</P><BLOCKQUOTE><P>Note: The complete SAL instruction set is given inAppendix A of the textbook, page 386.</P></BLOCKQUOTE><P>(a) all variables in SAL programs are global (<B>T</B>)</P><P>(b) the SAL statement "get x" works the same for all types of "x"(<B>F</B>)</P><P>(c) the label "b" could be used for a variable in a SAL program(<B>F, it's a reserved word</B>)</P><P>(d) variables must be declared before they are used in SALprograms (<B>F, the ".data" section can come after the ".text"section of the source code</B>)</P><P>(e) when executed, the SAL statement "b (ret)" will cause a branchto the SAL statement labeled by "ret:" (<B>F, in this context, retis a variable name, not a statement label</B>)</P><P>(f) when executed, the SAL statement "j ret" will cause a branchto the SAL statement labeled by "ret:" (<B>T, here ret is a statementlabel</B>)</P><P>(g) every SAL program must have a "__start:" label in it somewhere(<B>T</B>)</P><P>(h) "done" is part of the SAL instruction set (<B>F, it's a"macro"</B>)</P><P>(i) "rem" is used to put a remark or comment in a SAL program(<B>F</B>)</P><P>(j) type declarations are made in SAL programs so that typechecking can be done by the assembler (<B>F, type defs are to reservespace only</B>)</P><P>(2) 2 points</P><P>In a single sentence, explain what "computer architecture" means.</P><DL> <DD><B>In the context of CS354, "computer architecture" is defined by the basic instruction set of the computer.</B></DL><P>3) 8 points</P><P>Translate the following C code into the equivalent SAL statements.Assume that all variables are of C type "int."</P><BLOCKQUOTE><PRE>if ((A > 0 ) || ( B == 1 )) { C = A + B * 5;} else { A++; B = ( A / B ) % C;}</PRE></BLOCKQUOTE><P>--------------------------------------------</P><BLOCKQUOTE><PRE><B> <TT><CODE>bgtz A, then # if A > 0, do then part beq B, 1, then # or if B == 1, do then part add A, A, 1 # else part ... div B, A, B rem B, B, C j cont # jump over then partthen: mul C, B, 5 # then part add C, A, C------------------------------------------------------------- ### Another solution blez A, check2then: mul C, B, 5 add C, C, A b contcheck2: beq B, 1, then add A, A, 1 div B, A, B rem B, B, C-------------------------------------------------------------cont: ...</CODE></TT></B></PRE></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -