CS 216, Lab. 2
Lab date given on course wb page, due Monday
Assignment: math2.a and
(math6.a or math7.a)
math2.a asks you to calculate 5 * X^2 - 3 . [X-squared]
Do
this just like you did easy.a last week, using mipsmark and submit!
math6.a
The problem is to find a point on a line, given by the equation: y = slope*x + intercept
for for some value
x, calculate and print the corresponding y value that is (nearly) on
the line.
Since we are doing integer arithmetic, slope will be given as two
numbers, dy and dx, see figure. You will need to
multiply before dividing,
and the answer will be only approximate, simply ignore any remainder.
math7.a
Too much algebra? Try this:
Suppose you want to take a trip. You know how far it is, and what your
average speed is likely to be. So, how many hours and minutes should
the trip take?
You can divide the distance by speed, giving hours. But suppose it
would 2.39 hours, it's not clear how many minutes .39 is, and anyway we
want to use a div instruction, which only gives us the hours.
However you calculate, never multiply after dividing.
## Question:
## Given a distance and a speed (per hour),
## Find the time required to take a trip.
## Answer in in hours and minutes
## Ignore fractions of a minute.
##
Note: The distance can be either km or miles, and speed
correspondingly in km/h or MPH, depending on what country you are in.
the calculation is the same.
Suggested solution
- Divide distance by speed, giving number of hours, and a remainder
of distance left to travel.
- multiply this distance by 60, and again divide by speed (which
would now be interpreted as distance per minute -- 1/60 hour)
- Ignore any remainder, since it represents less than a minute's
travel.
Before the lab period, get the files math2.a and math6.a or math7.a and type in
your solution to the problem between the lines marked start cut and
end cut. It is a requirement of this course that your program include
adequate comments and contain your name. In the weeks to
come, you will follow these procedures with other programming problems.
Please put your name and account code on the
line after start cut. Preferred style: Line up instructions
and comments
#------------- start cut ---------------
# Student: (your name) Account:
# (start of your solution to the programming problem)
#------------- end cut -----------------
It is important to run mipsmark, and "hand in" your commented
source code with submit
Instructions
In the lab, the goals are:
- To get your program working. You may have syntax errors and logic
errors to correct.
- Show me that you wrote a good program by running the mipsmark
tests, and submitting the commented source code.
Step by step
In these instructions, things you click on with the mouse
are shown bold, things you type in are shown in "tty"
font. Some alternate instructions are provided for use away from
the lab, were you may not have the same desktop or utilities as in
Bishop's labs.
Steps 1, 3 and 4 are done in a terminal window of linux.ubishops.ca
They assume you have edited .bashrc
- Check your program for syntax errors with spim in a terminal window
- [---]> spim math2.a
you will either see error messages, or output from program.
- Check your program for (possible syntax errors and) logic by running it using QtSpim
(or Mars if you prefer) note
the lower case!
- [---]> qtspim math2.a &
(one way to open it in x2go)
- In the QtSpim window that appears,
step through the program, and watch the
registers to see what is happening, look for output in the console
window
- OR mars & , wait for the window, then
use the mouse to load your file.
Then proceed to step through your program.
- mipsmark math2.a Tests your program.
In case of trouble, check for
- exact file name (see above)
- The two lines labeled ------ start cut ------- and -------
end cut --------- are present, and you put the required code between
them.
- look at the log file written by mipsmark, it shows you
mipsmark's error messages
cat mark.log
cat means concatenate, and copies one or more files to the
screen
- If you find "answer not found" this means that you printed a wrong answer!
Go back to qtspim!
- If case 0 is OK, but a later case, say case 1, fails,
showcase math2.a 1
will give you a file math2_1.a,
which will show you the expected answer and the test data. Go back to qtspim
with this file. (Once this case works, you need to change the original file! -- Will it still pass case 0?)
- Once your program passes mipsmark (all tests OK), submit it:
- Type: submit cs216 math2.a
You have finished lab 2 when you have tested and submitted both
problems. You do not have to hand in anything, as mipsmark makes a
record of your tests, and submit sends me a copy of your source
files. Should you wish to make corrections, you can use submit
again, which will replace your original file.
Well, you are finished when
you have submitted BOTH math2.a and one one of math6.a or math7.a
(mipsmark & submit)
Working remotely (ignore this if you are in the lab)
Some days it may be snowing so hard you may not want to come to the
lab, or so cold that your car won't start. You can work remotely from
home, even with a windows machine, providing you have software that
allows secure connections. You will need to use 2 internet protocols, ssh (secure shell, which gives you a
single "terminal" for linux commands, and sftp (secure file transfer protocol)
or scp (secure copy) for transferring
files between machines. You type these commands in a terminal in
Mac-OS. Usable programs for Windows are to be found on Bishop's
lab computers, they are putty and winscp
- Start ssh (putty) for a terminal window "on linux.ubishops.ca"
- Windows: Click on an icon in file manager or the desktop , or
click the start button, select run, and type in putty.
You want the SSH protocol, and host linux.ubishops.ca
Mac or Linux: in a terminal window, type ssh username@linux.ubishops.ca
- Type your password. You won't see anything on the screen. Type carefully!
- Use scp or sftp to
transfer
your
file (instructions below), or winSCP if available.
- open a terminal, linux or mac
- (Windows - not available, use winscp)
- cd to the directory in which your file is located, if
necessary.
- type: scp myfile.a youracct@linux.ubishops.ca:.
(.
for
current, ie home, directory, or else name of a subdirectory)
... and give password when prompted, OR
- type: sftp youracct@linux.ubishops.ca
this
opens
a connection (in the lab, you may always shorten linux.ubishops.ca
to linux)
- you must now give your password for the linux lab.
- type: put math6.a this
sends
the file to linux
- type: dir
to see that it is there. Notice if the file name is still in lower case.
- type help
to get a list of sftp commands
- type: bye to quit
sftp
- (type: exit to close the window)
- Switch back to ssh (putty). Type these terminal commands:
- spim math6.a, just as if you were in the lab, until you get
the correct results.
- Contine with mipsmark andsubmit, as above
- exit ends your ssh session
Prepared by Lin Jensen ,
see also
Course notes . E-mail: ljensen
at ubishops.ca