Date: Tue, 05 Nov 1996 00:32:00 GMT
Server: NCSA/1.5
Content-type: text/html
Last-modified: Wed, 04 Sep 1996 16:03:10 GMT
Content-length: 5101
Assignment 2
Assignment 2
- Program Due Monday, September 30, before 5pm.
- Homework Due Wednesday, October 2, at the beginning of class.
Program
Purpose
This program is intended to provide understanding in the area of data representation.
Program Statement
For a user entering data to a program, any base could be used for either input or output. We often assume that the base is ten, but it would not have to be. Write a SAL program where the user enters 3 base ten integers. The first one will be the base to use for input, the second one will be the base to use for output, and the third will be the integer. The program prints out the user-entered integer in the user-entered base. Write the code such that the user-entered base will be in the range 1 < base <= 10.
Sample program run:
Enter the input base: 4
Enter base for printing the integer: 6
Enter the integer: 23
The integer in base 6 is 15
Another sample program run:
Enter the input base: 3
Enter base for printing the integer: 10
Enter the integer: 1022
The integer in base 10 is 35
Requirements
- Use procedures (functions) as defined in chapter 2 of the text. There should be one procedure that reads in a user-entered integer, and another that displays an integer in any base.
- All input and output (except for the use of
puts
for displaying strings) is to be done using character oriented input and output. That means that the operand for put
and get
instructions may only be of type character (declared as .byte
). The easiest way to enforce this requirement is to use the SAL putc
and getc
instructions instead of put
and get
.
- If an error in user input is detected, have the program print out an error message and exit. Note that since the program will be doing input and output character by character, there are many user input errors that can be detected. Errors that should be handled include checking that the user-entered bases are in the correct range and detecting user-entered characters that could not be part of an integer.
- Write the program such that it runs once, and then exits. Do not incorporate a loop to execute the program more than once.
- Comment your SAL program appropriately.
Handing In the Program
Turn in your program (the SAL source code)
only once by running the script
handin2 program2.s
where program2.s
is the name of the file containing the SAL program.
The handin2
script submits your program for you.
No printout will be turned in.
Homework
-
(3 points) Give a base 4 representation of the base 6 value 25.4. Show your work.
- (6 points) Fill in the missing entries in the following table. Use six bits for the binary representations. If the value required does not fit, write `overflow' for the answer.
--------------------------------------------------------------------------
| Decimal | Sign Magnitude | One's Complement | Two's Complement |
==========================================================================
| 23 | | | |
--------------------------------------------------------------------------
| | 101100 | | |
--------------------------------------------------------------------------
| | | 111100 | |
--------------------------------------------------------------------------
| | | | 100000 |
--------------------------------------------------------------------------
- (4 points) Show all work in giving the IEEE single precision floating point representation for the decimal value -22.85. Truncate the repeating fraction at its least significant end. Express the result in hexadecimal.
- (4 points) What decimal value is represented by the IEEE single precision floating point representation (given in hexadecimal) 0xc3834000?
- (3 points) The SAL
puts
instruction is used to print out the string that starts at label string1
. The contents of memory (given in hexadecimal) are given by
(address) (contents)
------
string | 66 |
------
| 75 |
------
| 6e |
------
| 20 |
------
string1 | 73 |
------
| 74 |
------
| 75 |
------
| 66 |
------
| 66 |
------
| 21 |
------
| 00 |
------
| 42 |
------
| 59 |
------
| 45 |
------
What is printed by the puts
instruction?