CS 203 - Lab 13 - Fall 2001


Lafayette College > Department of Computer Science > CS 203 > Labs > Lab #13

Summary

For this lab you will write a program in IJVM assembly language that uses many methods.

Instructions

Write an IJVM program that plays a game of 3-5-7 Nim. 3-5-7 Nim is a two player game played with three rows of sticks initially containing 3, 5, and 7 sticks respectively. The two players take turns taking 1, 2, or 3 sticks from one of the rows. The player who takes the last stick wins. Your program should allow two human players to play the game.

Assemble, test, and run your program using the IJVM assembler and simulator from Lab #12.

Hints

You can model your code after my C++ version (Java programmers: don't worry -- the only strange things you will see are statements like cout << "foo" << endl; in place of System.out.println("foo");). You can compile and run that code with the commands

g++ -o nim357.x nim357.cc
./nim357.x

Remember that each method takes a dummy OBJREF as its first parameter. Push a zero onto the stack before pushing any other parameters before invoking a method, and remember to include the dummy value in your count of parameters. If you do not do these things, the simulator will not run your methods properly.

Every method must return an integer. To write the assembly code for a high-level language method with a void return type, push an arbitrary value onto the stack before the method returns and have the invoking method immediately perform a POP after invoking the method.

Write and test your program one method at a time, just like you would a program in a high-level language (right?). For example, the following code could test your printRow method.

 BIPUSH 0
 SPRINT "How many sticks would you like to print?\n"
 IREAD
 INVOKEVIRTUAL printRow
 POP
 HALT

#your printRow code would go here

Assignment (due Monday, December 3rd at 11:59pm)

Submit your code by attaching it to an e-mail. To send multiple files, attach them all individually to a single e-mail (no tar or pkzip archives, please).