Date: Tue, 05 Nov 1996 20:51:50 GMT Server: NCSA/1.5 Content-type: text/html Last-modified: Wed, 02 Oct 1996 15:00:17 GMT Content-length: 3368
Purpose: To learn how to display the MIPS RISC internal representation of characters, integers and floating point numbers, to practice using the logical and shift instructions in SAL.
Program description: Write a SAL program that:
(a) reads four characters and stores them in a 32-bit word, then prints out the word in hexadecimal,
(b) next reads a floating point number, then prints out the bit patterns for the fields S, E and F,
(c) and finally reads an integer, then prints out the 32 bit 2's complement form of the integer.
Sample run:
Enter 4 characters: Char
0x43686172
Enter floating point value: 17.15
0 10000011 00010010011001100110011
Enter integer: 130
0000 0000 0000 0000 0000 0000 1000 0010Algorithm:
(a) Use
getc ch
to read the four characters, wherech
is of type.byte
, and shift each into a 32-bit word as you read them. Write a print procedure that accepts the word as input, prints the "0x," and then prints out eight hexadecimal digits.(b) Use
get f
to read the floating point number, wheref
is of type.float
. Copy the floating point number to an integer variable, and then print the three fields of the floating point number with one space between the fields.Note: the
get
instruction, when used on a variable of type.float
, automatically stores the variable in IEEE single precision FPS format.(c) Use
get i
to read the integer, wherei
is of type.word
, then print the 32 bits ofi
with one space between groups of four bits.Specific requirements for your program:
(1) You may assume that you will receive no bad data. Assume the user types in four characters followed by a return (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.
(2) Write and use a procedure that prints a subset of the bits of a 32-bit word given 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 word contained the value
00000000000011000111111110000110
and the subrange of bits to print out was 7..4, then the procedure would print the value
1000
Note that implied in this implementation example is a little endian numbering of bits.Handing in your program: Turn in your program (the SAL source code) by running the script
handin3 program3.s
just once, where
program3.s
is the name of the file containing your SAL source code. No printouts will be turned in. The TA/Grader will run your program several times using different test data.