📄 http:^^www.cs.wisc.edu^~cs354-2^cs354^homeworks^karensp3.html
字号:
Date: Tue, 05 Nov 1996 20:51:50 GMTServer: NCSA/1.5Content-type: text/htmlLast-modified: Wed, 02 Oct 1996 15:00:17 GMTContent-length: 3368<!--This file created 9/29/96 4:43 PM by Claris Home Page version 1.0b1--><HTML><HEAD> <TITLE>JT-P3.html</TITLE> <X-SAS-WINDOW TOP=-8 BOTTOM=347 LEFT=-697 RIGHT=-167></HEAD><BODY><H2 ALIGN=CENTER>CS354, Fall 1996</H2><H2 ALIGN=CENTER>Program 3, due Monday October 7, before 5pm.</H2><BLOCKQUOTE><P><B>Purpose: </B>To learn how to display the MIPS RISCinternal representation of characters, integers and floating pointnumbers, to practice using the logical and shift instructions in SAL.</P><P><B>Program description:</B> Write a SAL program that:</P><P>(a) reads four characters and stores them in a 32-bit word, then printsout the word in hexadecimal,</P><P>(b) next reads a floating point number, then prints out the bitpatterns for the fields S, E and F,</P><P>(c) and finally reads an integer, then prints out the 32 bit 2'scomplement form of the integer.</P><P><B>Sample run:</B></P><code>Enter 4 characters: <b>Char</b><br>0x43686172<br>Enter floating point value: <b>17.15</b><br>0 10000011 00010010011001100110011<br>Enter integer: <b>130</b><br>0000 0000 0000 0000 0000 0000 1000 0010</code><P><B>Algorithm:</B></P><P>(a) Use <code>getc ch</code> to read the four characters,where <code>ch</code> is of type <code>.byte</code>, and shift each into a 32-bit word as you read them. Write a printprocedure that accepts the word as input, prints the "0x," and thenprints out eight hexadecimal digits.</P><P>(b) Use <code>get f</code> to read the floating point number,where <code>f</code> is oftype <code>.float</code>. Copy the floating point number to aninteger variable, andthen print the three fields of the floating point numberwith one space between the fields.</P><P>Note: the <code>get</code> instruction, when used on a variable of type<code>.float</code>, automatically stores the variable in IEEE singleprecision FPS format.</P><P>(c) Use <code>get i</code> to read the integer, where <code>i</code>is of type <code>.word</code>,then print the 32 bits of <code>i</code> with one space between groups offour bits.</P><P><B>Specific requirements for your program:</B></P><P>(1) You may assume that you will receive no bad data.Assume the user types in four characters followed by areturn (you need to read the return and discard it).Assume the user enters a valid floating point number followed by a return.Assume the user next enters a valid integer followed by a return.</P><P>(2)Write and use a procedure that prints a subset of the bits of a 32-bit wordgiven parameters that specify which bits.Use this procedure for parts (b) and (c) of the program.An implementation example of this procedure might be if the 32-bit wordcontained the value<br>00000000000011000111111110000110<br>and the subrange of bits to print out was 7..4, then the procedure wouldprint the value<br>1000<br>Note that implied in this implementation example is a little endiannumbering of bits.</P><P><B>Handing in your program:</B> Turn in your program(the SAL source code) by running the script</P><code>handin3 program3.s</code><br><P>just once, where <code>program3.s</code> is the name of the file containingyour SAL source code. No printouts will be turned in. The TA/Graderwill run your program several times using different test data.</P></BLOCKQUOTE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -