SAL Programming and Number Systems
5% Assigned: 1/26/2005 Due: 2/9/2005 at 4:00 PM
Announcements
Any clarifications or corrections to the assignment
will be stated here.
Send email questions for this assignment to Jayaram at
.
2/2/05 To output in hex, you must display a digit at a time starting with the MOST significant digit since character output is left to right. Doing this takes a bit of thought since you do not have arrays or string objects. Hint: consider implementing the "subtract powers of" algorithm for base 16 like done in lecture for base 2.
2/2/05 A1 hand-in directories are now open.
2/4/05 SAL allows you to mix .word and .byte types in calculations. The cvt (i.e. convert) instruction is for integer to float and float to integer conversions only, which aren't used in A1.
2/7/05 Printing the output in hexadecimal is the hardest part of this assignment. If you are unable to figure this out, show the hex output in least significant to most significant digit order for partial credit on this part of the program.
1: Multiple Choice Questions 10 points
I strongly recommend that you first do these multiple-choice problems
without using the simulator, a calculator, or referring to your notes. This is good practice
for the exam and can help you gauge how well you know the course material. After determining your
answer, then check your work.
Which one of the following is not a step in the CPU's fetch/execute cycle?
A. store results
B. load address
C. load operands
D. decode instruction
E. update program counter
Consider the following SAL code fragment:
add x1, x1, x4
move x2, x1
sub x3, x3, x1
How many times is memory accessed when this SAL code
fragment is executed? Count each memory access and don't count changes to the program counter.
A. 4
B. 8
C. 10
D. 11
E. 12
Consider the following SAL code fragment:
__start: move x1, 1
label_1: bgt x1, 3, label_4
move x2, x1
label_2: blez x2, label_3
put x2
sub x2, x2, 1
b label_2
label_3: put newline #assume newline stores a '\n' character
add x1, x1, 1
b label_1
label_4: done
Which one of the following shows what is displayed by this code fragment?
A. 1
12
123
B. 1
21
321
C. 1
21
321
4321
D. 121
321
432
E. none of the above
The value 101011 base 2 is equivalent to:
A. 211.1 base 3
B. 25.1 base 8
C. 21.75 base 10
D. 15.7 base 16
E. all of the above
Which one of the following statements is false?:
A. The decimal point is called the radix point in general.
B. A single magnitude may be represented by many different numbers.
C. The accuracy of a computation is same as the precision of the computing
machine used.
D. Accuracy quantifies the difference between the measured or computed value and
the actual or true value.
E. The precision of a computing machine is fixed by the maximum number of
significant digits that can be represented and computed by that machine.
2: Written Questions 25 points
I strongly recommend that you first do these written
problems without using the simulator, a calculator, or referring to your notes. This is good practice
for the exam and can help you gauge how well you know the course material. After determining your
answer, then check your work.
To indicate a repeating fraction in your text file answers for the
questions in this part of the assignment follow the fraction with ... as in 1.23...
which means 1.2323232323 and so on.
(9 points)
Write the SAL equivalent of the following Java code fragment:
switch (c1) {
case 'A':
case 'a': i1 = 11; break;
case 'b': i1 = 22; break;
default: i1 = 33;
}
System.out.print(i1);
(12 points)
Convert numbers from the given radix to fill in the following table.
(4 points)
Give a base 5 representation for the value 123.3 base 4.
3: Programming Work 65 points
Write a SAL program that reads in three non-negative integers that are
entered by the program user. The first is a decimal integer in the range from 2 to 16 inclusive. It is used to specify
the base of the second and third integers, which represent the dimensions (width, length) of a surface. The program uses
these integers to calculate the area of that surface, which is displayed in bases 10 and 16.
Note that we are completely ignoring units in this program. We'll assume
that the units for the width and length integers are the same so that the area calculation is valid.
Here's a sample execution of the program (user input in bold):
This program prints the area of a surface.
Enter the integers' base (in decimal): 2
Enter the integer length: 100
Enter the integer width: 100
The area in decimal is 16 units.
The area in hexadecimal is 0x10 units.
Here's another sample execution of the program (user input in bold):
This program prints the area of a surface.
Enter the integers' base (in decimal): 10
Enter the integer length: 12
Enter the integer width: 4
The area in decimal is 48 units.
The area in hexadecimal is 0x30 units.
Before submitting your programming work, make sure that you have followed
the Standards for Grading Programs. Especially make sure you've documented your
program and have organized it into procedures.
Regarding Errors and Input: As specified in the
grading standards for programs, your programs must handle invalid input in a reasonable manner. For this
assignment, if invalid input is entered for the base specified, display a clear error message and
ask the user to re-input the value. You do not need to worry about the problem of integer overflow.
For digits values 10 - 15 you only need to have your programs handle lowercase (a-f) though a better
progrm would be able to accept both uppercase and lowercase.
WARNING: b, j, m, M
are predefined and will cause headaches if you use them as labels. As a rule of thumb I suggests that
you use names that are at least 2 characters long, e.g., c1 or i1.
What to Submit
You are to turn in the
following by the due date and time. Refer to the assignments
page for information about how to submit your written and programming work. Also refer to
the late policy if necessary.
Electronically
submit the following:
your work for parts I and II in the file named A1.probs and include the following at the top of this file:
NAME: your name
LOGIN: your CS login name
LECTURE: your lecture number (the one in which you are enrolled)
HELPERS: names of anyone that provided help
(others you didn't work with that helped)
COLLABS: names of any collaborators
(current 354 students you jointly worked with on your solution)
your source code as the file named A1.s making sure that you have followed the Standards for Grading Programs.