Assignment 3

CS/ECE 354, Fall 2009


Send e-mail questions to Tony, tjn@cs.wisc.edu
Due Friday, October 23, before 5pm.


Collaboration Policy

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.


Program Statement

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:

  1. The MAL program prompts for a first character.
  2. The program reads a first character, which is to be used as the initial exponent.
  3. The program checks for validity of the first character.
  4. If the first character was OK, then the program prompts for a second character.
  5. The program reads a second character, which is to specify how many powers of 2 the program will be calculating.
  6. The program checks for validity of the second character.
  7. Given that there were no errors made in the user input, the program enters a loop that iterates the specific number of times corresponding to the second value entered by the user. Each iteration of the loop calculates one power of 2 and enters this information (power of 2) into an array of 9 integers.
  8. Another loop prints the program's output. Each iteration is to do one line of the output. The format of each line is the same as the single line from Assignment 2.

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.

Requirements

  1. Your program must follow style guidelines as given in Style Guidelines.

    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.

  2. Name your source code program 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.
  3. Declare and use an array of 9 integers. Note that the program may not use the entire array, if the number of powers of 2 to be calculated is less than 9. This program only sets as many array elements as needed, and the first array element set is the one at the base address of the array.

    A goal of this assignment is to provide experience using load and store instructions. Without an array, no load or store instructions would be needed.
  4. This program reads in a total of exactly 2 characters, unless the first character is invalid.
  5. Organize your program such that there is only one exit point (the done instruction) in the program.
  6. Your program is to operate and appear the same as the examples given above. Use the same prompts and strings. Do not produce output other than what is shown in the examples. Also, the program runs once, and then exits. To restart the program, the user must either click run on the simulator or restart the simulator entirely.
  7. Do not implement procedures/functions/methods.

Notes

Handing 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.

Use the following command to run the 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.