Lab 6: Choose your own LC-3 adventure
Due date
Due Monday, August 3 by 8:00am
Lab objective
This is your last assignment in LC-3.
The purpose of this assignment is to familiarize you with several new concepts. These include memory management, address manipulation, and stack management. Most importantly, though, you should enjoy writing the program and have fun!
This program is a simple choose-your-own-adventure story. The story is entirely up to you. The choices are entirely up to you.
The game works like this. The program tells a little bit of story to the player, and presents the player with two (or more) choices. The story is modified a little bit to accomodate the player's choice. The program continues telling the story until the next branch, when the player must again decide what to do.
The program must allow the player to back up in their choices, in the case that the player made the wrong selection, or wants to explore a different option. Use a stack to keep track of the player's choices.
Lab tutors: Go over these topics
Your lab tutor will cover the following topics in the first 40 minutes of lab.
- Explain the differences between these four groups of instructions.
- Group 1: LD, LDR, LEA, LDI
- Group 2: ST, STR, STI
- Group 3: JSR, JSRR
- Group 4: JMP, BR
- What is a pointer?
- What is a node as defined by this assignment?
Lab 6: Choose your own LC-3 adventure
Your game is entirely your own. Will the player be eaten by a grue? Only time can tell.
What's required
A lab write-up, and lab6.asm
Procedure
Your program should behave as follows:
- Display a greeting.
- Display some piece of the story, and a menu with two (or more) choices. An extra choice is "go back," which takes the player back one step in the game.
Of course, the "go back" choice doesn't make sense in the first step.
- Display a prompt, and allow user input.
User is expected to enter only a single character corresponding to the choice.
See Figure 2 for an example.
- Check if the game is over (if the user has won or lost). You know that the game is over when there are no more decisions that the user can make.
- Continue playing until the user has won or lost. Display a "you win" or "you lose" message accordingly.
Additional requirements
Let's get down to the nitty-gritty.
- You must work stuff out on paper. Your tutor will not help you with your code if you do not have an algorithm, decision diagram, and other notes worked out on paper before you start programming. This lab will become very complicated very fast, and you must keep track of things on paper rather than just in your head (plus, your tutor will be unable to debug your code without your flow charts and notes). Refer to Figure 3 for an example flow diagram.
- The game must allow the user at least four choices.
- You must use procedures and procedure calls for this lab. If you are unclear about
JSR and RET, ask your tutor. In particular, you must implement procedure calls for at least the following functions.
- Push: to push an element or a set of elements onto the stack
- Pop: to remove an element or a set of elements from the stack
- You must use pointers for this lab. Consider how you will be storing each decision you present to the user. Each decision has a set of data associated with it (we'll call this object a node). A node consists of at least the following things.
- Pointer to the text for the decision
- Pointer to choice one text
- Pointer to choice two text
- Player's decision (to be filled in during play)
- Pointer to choice one node (0 if there isn't one)
- Pointer to choice two node (0 if there isn't one)
You will need to keep track of the address of the node (push it on the stack) so that the player can re-trace his or her steps during play.
- I'll bet your strings are super long. Use pointers to strings to avoid the 9-bit PC offset error message. You may run into other problems -- strings have a maximum length for the LC-3 assembler, so if your assembler crashes when you assemble your code, check your string lengths.
- For the "go back" function, you must remember the previous state of the entire system. This is why you would need to remember the address of the parent node: it is in case you advance to the next one and need to go back. What if the player is almost at the end of the game, and chooses "go back" for every choice?
- Decision made: push node pointer onto stack (follow choice pointer)
- Go back: pop parent node pointer off the stack
The decision nodes may be hard-coded before play begins.
Example output
Welcome to the Bee Chaser!
You are walking through the forest in Santa Cruz when a Bee attacks you!
A Bee is chasing you. Run away?
1. Yes
2. No
> 1
You run with all your might, but the Bee is in hot pursuit!
The Bee chases you. Run faster?
1. Yes
2. No
3. Go back
> 2
The Bee kills you. You die. :-(
Play again?
1. Yes
2. No
> 2
----- Halting the processor -----
Grading template
This is a suggested grading rubrik. Your tutor may or may not use this rubric to grade by, but it is a good general guideline before submitting your code to check off these points.
Coding requirements
- (2 pt) Display greetings and prompts (understandable interface)
- (4 pt) Accept user input (characters)
- (6 pt) Game is interesting and allows at least four user choices
- (4 pt) Uses procedures and procedure calls at least for push and pop
- (8 pt) Nodes are stored as indicated: choice and description text; player's decision; choice pointers
- (12 pt) "Go back" function works as intended, using the parent node pointer with the stack
- (4 pt) Comment requirements as last week, and miscellaneous errors
40 points total
Lab report requirements
In the lab report, we will be looking for the following things. The lab report is worth 12 points. We do not break down the point values; instead, we will assess the lab report as a whole while looking for the following content in the report.
- Explain the differences between these four groups of instructions.
- Group 1: LD, LDR, LEA, LDI
- Group 2: ST, STR, STI
- Group 3: JSR, JSRR
- Group 4: JMP, BR
|