Assignment 2

CS/ECE 354, Fall 2009


Send e-mail questions to Somayeh Sardashti, somayeh@cs.wisc.edu
Due Monday, Oct. 12, 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

Write a MAL program that does a very small part of what the C program in assignment 1 did. The MAL program requests and reads in exactly one character, which represents the integer value (from assignment 1). The program calculates this integer value cubed, and then prints the calculated value.

Note that no array is used. Legal values for the single character read by the program are the digit characters '0' to '9'. Zero cubed is defined to be the integer value 1.

Here are examples of program execution. User input is given in boldface to distinguish it from program output.

Acceptable program input

Enter a value 0-9: 2
2^3 = 8

Again, acceptable program input

Enter a value 0-9: 8
8^3 = 512

Again, acceptable program input

Enter a value 0-9: 0
0^3 = 1

The following examples illustrate what the program does with bad input.

Character is not a digit

Enter a value 0-9: X
Bad user input.  Quitting.

Again, character is not a digit

Enter a value 0-9: -
Bad user input.  Quitting.

Again, character is not a digit

Enter a value 0-9: k
Bad user input.  Quitting.

Requirements

  1. Your program must follow style guidelines for assembly language programs 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 cube.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. The program reads exactly one character.
  4. For this program, the only I/O instructions permitted are getc, putc, and puts.
  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 prompt 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. Do not use an array.

Notes

  1. The program's input will be an ASCII character. Your program will need to work with the two's complement integer represented by that ASCII character. So, convert it! If you don't know how to do this, then go back and re-read the On Your Own reading on character representations. This reading also contains links to tables that show ASCII representation.
  2. We use a simulator to run and test our assembly language programs. This simulator currently runs on the machines used for this class. You will need to be sitting at or remotely logged in to one of these machines in order to use the simulator. See the simulator guide for brief instructions on how to invoke the simulator.

    It will take some time for you to get used to the simulator. Allocate extra time for this, and start well before the assignment is due. The user interface will allow you to set breakpoints and single step through your code. It will also show you the contents of registers for your program.

    Note that the ability to use this simulator across the network (not sitting in front of an instructional Unix machine) is not guaranteed. An X-server must be available.

Handing In the Program

Your MAL source code must be in a file named cube.s. Turn in your program by running the lab-supported handin program.

Here is an exact command to use. Use the command

  /s/handin/bin/handin -c cs354-1 -a a2 -d .

while your current working directory is the one containing the cube.s file. This program copies the specifically named file to a directory accessible by the instructor and TAs.