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.
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.
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.
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.
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.
get_point
gets the 3 coordinates for a point.
The function
get_point calls get_integer three separate times
to get the x, y, and z coordinates for a point.
Passed to the function will be the address of
an array of three integers.
This function fills the array.
The first integer within the array will hold the x coordinate,
the second integer within the array will hold the y coordinate,
and
the third integer within the array will hold the z coordinate.
get_integer
reads user input to get an integer.
The function
get_integer
receives no parameters.
It presumes that it is reading in a base 10 integer.
The function returns the value of the integer (in $v0) entered by the
user.
perpendicular is a function that determines if the two
lines are perpendicular or not.
The function receives three parameters, each parameter is
the address of an array containing one of the point's coordinates.
direction
twice.
direction
is a function that calculates the direction numbers for a line.
It receives seven parameters, six of which are the coordinates for the
two points that define a line.
The seventh parameter will be the address of an array of three integers.
The array holds the direction numbers for a line.
This function fills the array.
MALtester program as described in Program #2
to check.)
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.)