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.

graph of a possible line

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

  1. Divide distance by speed, giving number of hours, and a remainder of distance left to travel.
  2. multiply this distance by 60, and again divide by speed (which would now be interpreted as distance per minute -- 1/60 hour)
  3. 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:

  1. To get your program working. You may have syntax errors and logic errors to correct.
  2. 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
  1. Check your program for syntax errors with spim in a terminal window
    1. [---]> spim math2.a
          you will either see error messages, or output from program.
  2. Check your program for (possible syntax errors and) logic by running it using QtSpim (or Mars if you prefer) note the lower case!
    1. [---]> qtspim math2.a & (one way to open it in x2go)
    2. 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
    3. OR mars & , wait for the window, then use the mouse to load your file. Then proceed to step through your program.
  3. mipsmark math2.a    Tests your program. In case of trouble, check for
  4. Once your program passes mipsmark (all tests OK), submit it:
    1. 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
  1. Start ssh (putty) for a terminal window "on linux.ubishops.ca"
    1. 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
    2. Type your password. You won't see anything on the screen. Type carefully!
  2. Use scp or sftp to transfer your file (instructions below), or winSCP if available.
    1. open a terminal, linux or mac
    2. (Windows  - not available, use winscp)
    3. cd to the directory in which your file is located, if necessary.
    4. 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
    5. type: sftp youracct@linux.ubishops.ca       this opens a connection  (in the lab, you may always shorten linux.ubishops.ca to linux)
    6. you must now give your password for the linux lab.
    7. type: put math6.a             this sends the file to linux
    8. type: dir         to see that it is there. Notice if the file name is still in lower case.
    9. type  help                  to get a list of sftp commands
    10. type: bye          to quit sftp
    11. (type: exit to close the window)
  3. Switch back to ssh (putty). Type these terminal commands:
  4. spim math6.a, just as if you were in the lab, until you get the correct results.
  5. Contine with mipsmark andsubmit, as above
  6. exit       ends your ssh session

Prepared by Lin Jensen ,
see also Course notes . E-mail: ljensen at ubishops.ca