Computer Science 237
Computer Organization

Williams College
Fall 2005


Lab 3: Palm Assembly Programming
Due: Monday, October 3, 2005 at 11:00 AM

Our lab meetings this week are less formal. I will be in TCL 312 during the regular lab meeting times to help you get started. You are strongly encouraged but not required to attend.


This week's lab is the same as last week's - to finish the quarto game - but this time you are to write the assembly language version of win.c, called win.s. Ideally, you should be able to assign a register to each of your local variables from the win method in win.c, and translate the code directly. In practice, it can be difficult because nearly every mistake in assembly language leads to subtle side-effects that are often difficult to detect.

After you have submitted your win.c from last week for grading, you may ask to see my version of win.c to get ideas about how to improve it before starting in on the assembly language version. My version allows a relatively straightforward conversion to assembly.

Here is an approach to finishing this lab:

  1. Begin by untarring the quarto2.tar.gz from the CS237 shared directory:
        /usr/cs-local/share/cs237/labs/quarto2.tar.gz
    

    The file you should be modifying here is win.s. As with last week's lab, the provided Makefile will assemble and compile and otherwise package up the program so you can install and run quarto2.prc on the Palm emulator.

  2. You might see if you can write a win function that returns true all of the time. Remember that true is any non-zero value. When you make this program you will not be able to move any pieces because the game is stuck in the win state.
  3. Next, see if you can win if there is a piece in row 1 and column 2. You will have to call get with the parameters in the correct order (push them on the stack) and return a true value if the piece returned (a byte in D0 after your call to bsr get) is appropriate. You should be able to play until some piece ends up in the appropriate square.
  4. Now, highlight that same piece before returning a win. Same procedure for calling highlight, except you don't have to worry about a return value (although it will clobber anything you have in D0).

    Remember that you must pop off two words for get and highlight, even though you've pushed on bytes.

  5. Now, for a big step. Detect any win in a row. Carefully assign each local variable to a register. Try to avoid registers D0, D1, and D2. Hand translate the code into assembly language, making sure you write comments (C code, perhaps?) to the right of the appropriate statements. If you can get this to work, you're probably within striking distance.
  6. Complete the conversion. Remember that bitwise ands and ors turn into assembly AND and OR instructions, while logical ands and ors turn into flow control (comparisons and branches). Remember, also, that division should not be necessary in this program. Instead, you should be able to use bit-masks to perform the appropriate operations.
  7. When you are finished, please turn in win.s:
        turnin -c 237 win.s
    

    This can be done from either the FreeBSD systems or the CSLab Macs.