University of Wisconsin Computer Sciences Header Map (repeated with 
textual links if page includes departmental footer) Useful Resources Research at UW-Madison CS Dept UW-Madison CS Undergraduate Program UW-Madison CS Graduate Program UW-Madison CS People Useful Information Current Seminars in the CS Department Search Our Site UW-Madison CS Computer Systems Laboratory UW-Madison Computer Sciences Department Home Page UW-Madison Home Page

Program 3

CS/ECE 354, Fall 2003


Send e-mail questions to Eric Robinson, erobinso@cs.wisc.edu
Due Wednesday, November 5 before 5pm


Purpose

This program is intended to provide practice implementing nested procedures in MAL. It is important to follow all MIPS conventions as specified in P3 Conventions when writing your program and each of the procedures.

Program Statement

Write a MAL program that decides if two lines are perpendicular to each other.

Each line is described by two points. Each point is described by an ordered triple (x, y, z). We will restrict this program such that all coordinates are integers, and require that the lines share one of the points in common.

The following gives a simple test for determining if two lines are perpendicular.

Start with three points: P1 is(x1,y1,z1), P2 is(x2,y2,z2), and P3 is(x3,y3,z3). The first line, L1, is defined by points P1 and P2. The second line,L2, is defined by points P2 and P3.

Define a set of direction numbers for each line. For L1,
a1 = x2 - x1, b1 = y2 - y1, and c1 = z2 - z1
and for L2,
a2 = x3 - x2, b2 = y3 - y2, and c2 = z3 - z2

Then, two lines (L1 and L2) are perpendicular if L1 direction numbers (a1, b1, c1) and L2 direction numbers (a2, b2, c2) satisfy the equation
(a1 * a2) + (b1 * b2) + (c1 * c2) = 0.

See all sample runs. The user input is shown in bold. All other display is generated by the program.

Sample program run 1


This program determines if two lines are perpendicular.
Enter coordinates for P1
Enter x: 0
Enter y: 20
Enter z: 0
Enter coordinates for P2
Enter x: 0
Enter y: 0
Enter z: 0
Enter coordinates for P3
Enter x: 3
Enter y: 0
Enter z: 0
The two lines are perpendicular.

Sample program run 2


This program determines if two lines are perpendicular.
Enter coordinates for P1
Enter x: 2
Enter y: 6
Enter z: -1
Enter coordinates for P2
Enter x: 3
Enter y: 3
Enter z: 3
Enter coordinates for P3
Enter x: -18
Enter y: 4
Enter z: 5
The two lines are NOT perpendicular.

Sample program run 3


This program determines if two lines are perpendicular.
Enter coordinates for P1
Enter x: -2
Enter y: 4
Enter z: 1
Enter coordinates for P2
Enter x: 1
Enter y: 1
Enter z: 1
Enter coordinates for P3
Enter x: 3
Enter y: 3
Enter z: 1
The two lines are perpendicular.

Requirements

  1. Your program must follow the input/output format shown in the sample runs.
  2. Write the program such that it runs once, and then exits. Do not incorporate a loop to execute the program more than once.
  3. Comment your program appropriately. Each register used in a procedure should be described in the header for that procedure.
  4. Follow all register useage conventions as given in P3 Conventions.
  5. For this program, an integer consists of optional (zero or more) space or tab characters, followed by an optional '-' (the dash character, used as a minus sign), followed by one or more of the digit characters '0'-'9', and is terminated by the newline character (0x0a). There may not be white space characters (tab, space or newline characters) in the middle of the digits. Any input that does not meet this criteria is considered bad. Note that leading zeros must be handled correctly, since they are included (by this definition) as good input.
  6. The program will have and use 4 procedures/functions.
  7. Make sure that all instructions in the program are part of the MAL instruction set. (Use the MALtester program as described in Program #2 to check.)

Hints

  1. You should continue to learn and use sim as the simulator. The user interface to sim is graphical and it gives much more information than simp. Note: sim and simp are scripts that run the same simulator; the difference is the user interface presented. The user interface that goes with sim shows register values, and it easily allows single stepping through code. For detailed information, read the document listed under Handouts and labeled Simulator graphical interface manual (postscript) on the cs354 home page.
  2. The simulator implements the MAL I/O instructions like procedures or functions within the operating system. The conventions for register usage are not followed as well as we would like. Assume that any I/O instruction has the potential to overwrite the contents of any of registers $2-$7 ($v0, $v1, $a0-$a3).

Handing In the Program

Turn in your MAL program by running the script:


  handinP3 program3.s

where program3.s is an example name of the file containing the source code. The handinP script submits your program for you. No printout will be turned in. (We assume that you have put /p/course/cs354-common/public/bin in your path by now.)