Computer Sciences Dept.

CS/ECE 354 Machine Organization and Programming

Fall 2008 Section 1
Instructor Mark D. Hill
TAs Mark Liu & Somayeh Sardashti

Homework 3 // Due Friday, October 24, before 5pm.

Send e-mail questions to Somayeh Sardashti, somayeh@cs.wisc.edu

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

Program Statement

This MAL program is similar to Assignment 2, but uses an array to save the results.

Here is an ordered list of the steps that the program accomplishes:

  1. The MAL program requests and reads in exactly one digit that represents an integer.
  2. Given that there were no errors made in the user input, the program enters a loop which calculates whether or not that integer is coprime with each integer in the range 2-9. As each result is calculated, and the characters Y/N are placed into an array.

    The filled array for the user input example of 8 appears as

        0   1   2   3   4   5   6   7   8   9   index
      -----------------------------------------
      | ? | ? | N | Y | N | Y | N | Y | N | Y |
      -----------------------------------------
    

    Note that the program does not use the elements at indices 0 and 1.

    This step (a loop in your program) completes, such that the array has all its values, before step 3 begins.

  3. The program uses a loop to print out the contents of the array, using the same format as the program in Assignment 2. You will be able to reuse a lot of your code from Assignment 2.

Note that the functionality of the program is identical to that of Assignment 2. Assignment 3 is different from Assignment 2, because Assignment 3 uses an array.

Here are examples of program execution, exactly as given in Assignment 2. User input is given in boldface to distinguish it from program output.

Enter a 1-digit integer: 8
8 and 2 coprime? N 
8 and 3 coprime? Y 
8 and 4 coprime? N 
8 and 5 coprime? Y 
8 and 6 coprime? N 
8 and 7 coprime? Y 
8 and 8 coprime? N 
8 and 9 coprime? Y

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

Integer is too small

Enter a 1-digit integer: 0
Bad user input.  Quitting.
Again, integer is too small
Enter a 1-digit integer: 1
Bad user input.  Quitting.
User input contains something other than a digit character
Enter a 1-digit integer: X
Bad user input.  Quitting.
Again, user input contains something other than a digit character
Enter a 1-digit integer: a
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 array-coprime.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. After the program reads exactly one character, it processes the character. The program does not continue to read more characters waiting for the newline to be encountered.
  4. Organize your program such that there is only one exit point (the done instruction) in the program.
  5. 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. Do not add looping to repeat the program's functionality.
  6. Do not implement procedures/functions/methods.

Notes

  1. We use a simulator to run and test our assembly language programs. This simulator currently runs on the Centos 4 Linux machines used for this class (the emperor and royal machines). 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 array-coprime.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 array-coprime.s file. This program copies the specifically named file to a directory accessible by the instructor and TAs. (P.S. If you add the path /s/handin/bin within your .cshrc.local file, re-login, then you can omit /s/handin/bin/ from the command.)

 
Computer Sciences | UW Home