For this assignment, you may work in pairs (2 people). All students (whether working in a pair or not) must individually turn in the assignment by individually running the handin program. Therefore, 2 copies of the assignment will be turned in for those working as a pair. The grader will choose to grade only one copy of a pair's work, and assign the same score to both students.
If working in a pair, the names of BOTH students must appear at the top of the turned in assignment.
This MAL program is an extension and variation on Assignment 2, to incorporate more aspects of the C program implemented in Assignment 1. (The next assignment will re-implement the C program, in MIPS assembly language, using a fixed set of conventions for function implementation.) This program uses an array to hold calculated powers of 2. This program reads in exactly 2 characters, unless the first character is invalid. The characters are expected to be single digit characters '0' to '9' (inclusive). The program uses these values to set an initial exponent, and to identify how many powers are to be calculated.
Here is an ordered list of the steps that correspond to the program's code:
Here are examples of program execution. User input is given in boldface to distinguish it from program output.
Acceptable program input
Enter an initial exponent (0-9): 2 Enter how many powers to calculate (0-9): 4 2^2 = 4 2^3 = 8 2^4 = 16 2^5 = 32
Again, acceptable program input
Enter an initial exponent (0-9): 0 Enter how many powers to calculate (0-9): 3 2^0 = 1 2^1 = 2 2^2 = 4
Again, acceptable program input
Enter an initial exponent (0-9): 9 Enter how many powers to calculate (0-9): 2 2^9 = 512 2^10 = 1024
Again, acceptable program input
Enter an initial exponent (0-9): 9 Enter how many powers to calculate (0-9): 9 2^9 = 512 2^10 = 1024 2^11 = 2048 2^12 = 4096 2^13 = 8192 2^14 = 16384 2^15 = 32768 2^16 = 65536 2^17 = 131072
Again, acceptable program input, but notice that there are no powers of 2 to calculate or print, as the user enters the valid value of 0 for the number of powers to calculate
Enter an initial exponent (0-9): 7 Enter how many powers to calculate (0-9): 0
First character is not a digit
Enter an initial exponent (0-9): N Bad user input. Quitting.
Second character is not a digit
Enter an initial exponent (0-9): 4 Enter how many powers to calculate (0-9): x Bad user input. Quitting.
Also include a comment at the top of the source code with your name (and your partner's name, if working in a pair).
See Guidelines for Programs to see an indication of point allocation used in program grading.
po2.s,
and place the entire program into this file.
This file is what will be turned in.
It must have exactly this name to make the lab-supported handin program work.
A suffix of .s is the convention
used in Unix operating systems to
indicate an assembly language source code file.
done instruction) in the program.
Your MAL source code must be in a file named
po2.s.
Turn in your program by running the lab-supported handin program.
/s/handin/bin/handin -c cs354-1 -a a3 -d .
while your current working directory is
the one containing the po2.s file.
This program copies the specifically named file to
a directory accessible by the instructor and TAs.