ASSIGNMENT 1

advertisement
ASSIGNMENT 1
Errors, hints, and other issues arising after this assignment is published
will be listed under What's New.
It is your responsibility to inspect that list periodically.
Note: any assembly/machine language program you write for this course must adhere to
the MIPS sheet, which is available in the "Content" page and which will be provided as
part of the Midterm and final exam. You may not use any instruction or system call not
listed on that sheet. And since not every instruction on the sheet was covered in class,
consult appendix-A in the text for details on each instruction on it.
Question 1
Write a MIPS subprogram largest that takes three positive integers in $a0, $a1 and $a2
and outputs the largest of the three in $v0. Then write a MIPS program, using this
subprogram, that reads three positive integers and determines which of these numbers is
the largest. After a prompt, the integers are read one per line and the program then
outputs the largest integer along with a caption. This MIPS program is a test bed for
running the subprogram.
Here is a sample run showing the input and output specifications:
Enter the three integers(lengths)pressing ENTER after each:
3
4
5
The largest is: 5
Some additional specifications are:





Assume that the entry is valid, i.e. each is an integer greater than zero and less
than +2147483647.
The input should not be validated. We have assumed that the entry is valid as
above.
The three integers are read on three separate lines. This means you need to issue
three "read int" syscalls.
Once the output is generated, the program ends. Whether or not you output a new
line character after the message is up to you, i.e. it is optional.
Assume that for any arithmetic operation there is no overflow that is the result of
any operation is a valid integer (greater than -2147483648 and less than
+2147483647)

In the construction of your subprograms, you must ensure that the subprogram
may be used by any calling program with any register usage, without looking at
the specific code.
The program must adhere to the above specifications exactly, since any deviation from
them, for example the above layout, will not receive full credit even if the output content
is correct.
Question 2
Write a MIPS program that reads three positive integers representing the lengths of the
three sides of a triangle and determines if these three sides make up a right
angle triangle. Thus, a triangle is represented by the triplet (a,b,c) where a, b and c are
the lengths of the triangle sides. After a prompt, the integers are read one per line and
then the program outputs a caption to indicate whether or not the 3 integers could
represent a right angle triangle.
It should be noted that for a right angle triangle:
The square of the length of the longest side = the sum of squares of the lengths of
the other two sides.
The three numbers can be entered in any order, therefore your program should be
able to determine the triangles with sides (3,4,5) or (5,3,4) or (10,6,8) are
right angle triangles, while the triangles (5,3,7) or (3,3,9) are not.
Input and output format
Here is a sample run:
Enter the three integers(lengths)pressing ENTER after each:
3
4
5
is a right angle triangle
Here is another sample run:
Enter the three integers (lengths)pressing ENTER after each:
5
3
7
is not a right angle triangle
Some other I/O specifications are given below:





Assume that the entry is valid, i.e. each is an integer greater than zero and less
than +2147483647.
The input should not be validated. We have assumed that the entry is valid as
above.
The three integers are read on three separate lines. This means you need to issue
three "read int" syscalls.
Once the output is generated, the program ends. Whether or not you output a new
line character after the message is up to you, i.e. it is optional.
Assume that for any arithmetic operation there is no overflow that is the result of
any operation is a valid integer (greater than -2147483648 and less than
+2147483647)
The program must adhere to the above output and input specifications exactly, since any
program that deviates from them, for example the above layout, will not receive full
credit even if the output content is correct.
Program Structure
You must write and use the following function subprograms in your solution:
Subprogram largest: a MIPS subprogram that takes three positive integers in $a0, $a1
and $a3 as input and outputs the largest of the three integers in $v0. The positive integers
are all assumed to be valid.
Subprogram decision: a MIPS subprogram that takes as input three positive integers in
$a0, $a1 and $a2 as well as the largest of these three integers in $a3. So in total there are
4 input integers. For example, the following integers could be valid inputs (3, 4, 5, 5) or
(10, 11, 7, 11) note that in both cases the last integer is the largest of the first 3 integers,
as required. The program then outputs the result in $v0, where the result can take on
values either 1 or 0, depending on the square of the largest being equal to the sum of the
squares of the other two integers( in which case it is 1) or not equal (in which case it is 0).
Suppose z is the largest and a and b are the other two. If z2 = a2 + b2 then the output
would be 1 and if z2 is not equal to a2 + b2 then the output would be 0. Then for the above
example input (3, 4, 5, 5) we would have z = 5 and a = 3 and b = 4 and the output would
be 1.
Subprogram prt: takes as input $a0 which is either 0 or 1 and outputs the caption “is a
right angle triangle” when the input is 1 and the caption “is not a right angle triangle”
when the input is 0.
As an additional specification, in the construction of your subprograms, you must ensure
that the subprogram may be used by any calling program no matter what the register
usage is in the main program, without the programmer looking at the specific code of the
subprogram.
The program must adhere to the above subprogram specifications exactly, since any
program that deviates from them will not receive full credit even if the output is correct.
Note that you will be able to use much of the work you did in question 1 in the
construction of the solution to question 2.
What to Submit



The file a1q1.s containing your program for question 1 along with brief in-line
comments. Correctness marking will be done by running the following command
on red: spim -file a1q1.s and supplying a test case.
The file a1q2.s containing your program for question 2 along with brief in-line
comments. Correctness marking will be done by running the following command
on red: spim -file a1q1.s and supplying a test case.
The file a1.html containing the following sections (all in HTML format):
1. Title section as explained in the TYPE site. The main elements are the
course/term/assignment info and the author.txt file and link.
2. Comments re your a1q1.s program. A very brief explanation of your
implementation and whether the program worked or not.
3. Comments re your a1q2.s program. A very brief explanation of your
implementation and whether the program worked or not.
How to Submit?
Once implementation, testing, and report writing are complete, you are ready to submit
electronically. If you are working off campus, transfer all files a1q1.s, a1q2.s,
a1.html and author.txt to any directory in your Prism account (i.e. on the
red.cs.yorku.ca server). Then at the Unix prompt, issue the command:
submit 2021 a1 a1q1.s a1q2.s a1.html author.txt
This will electronically submit your assignment. The command can be issued in prism or
through a remote telnet connection; i.e. the entire process can be done remotely by first
ftping the files and then telneting to issue the command.
If you discovered an error after submitting (but before the due date/time of this
assignment), simply re-issue the above command and the old files will be overwritten.
The man page can be consulted if need be, but you should have no problem submitting the
report as indicated above regardless of whether you are working here or off campus.
Note
No other form of submission is accepted. Reports
received by email, on paper, or uploaded in any way
other than via submit, will not be looked at.
Download