Programming Assignment 3
Due: November 5, 2000 11.59 PM
A Simple Guessing Game
Problem Statement
Your program will simulate a simple guessing game. The program has stored the value 6. The program will continually ask the user to guess a number between 0 and 9 (see sample program input/output below.) The user enters the guess from the keyboard.
If the guess is larger than 6; the program should output:
Too big.
If the guess is smaller than 6; the program should output:
Too small.
When the user finally guesses correctly, the program will output:
Correct! You took # guesses.
where # is the number of guesses it took the user.
If after 9 guesses, the user has not correctly guessed the number, the
program should output
Game over. Correct answer is 6.
You do not need to check for invalid input (alphabetical characters,
punctuation, etc). If your program encounters any non digit character,
the program should output
Invalid input.
Invalid input should still count as a guess.
You should use TRAP x20 (GETC), to read in a character from the
keyboard. See Table A.3 in Appendix A of the textbook for a listing of
all trap vectors. You can use the pseudo-op .STRINGZ explained
on page 144 of the textbook to store a string into your program.
Hints and suggestions
While you may assume that all instructions and data fit on one page of memory, make use of the various addressing modes in the LC-2. Each has its advantage. You should use more than one.
Remember, all input and output functions use ASCII characters. You are responsible for making any conversions that are necessary.
Before sitting down at the computer, give some serious thought to what this program involves. Break it into sections. You might even want to draw a simple flow chart.
Comment your code! Not only does this help you debug your program, but it will make it easier to remember what you did, should you need to look back at your code for future projects (hint, hint). It also helps the graders, making them more likely to give partial credit.
Your program should be written in LC-2 Assembly language, and tested using the LC-2 Simulator. The completed program should work using input from the keyboard and output to the monitor.
Don't forget the ASCII code x0A. It causes the cursor to go
to the next line (Newline).
Sample Input/Output
Guess a number: 5
Too small.
Guess again: 9
Too big.
Guess again: a
Invalid input.
Guess again: 6
Correct! You took 4 guesses.
Writing and testing your program
For this assignment, you will be writing LC-2 assembly code, rather than the machine code you wrote in Programming Assignments 1 and 2. Since you are now writing assembly code and using the assembler, you do not need to perform the convert process. Instead, you will assemble the text file containing your LC-2 assembly code. "The Guide to Programming and Debugging in LC-2" on the course homepage shows how to produce the .obj file needed by the LC-2 simulator. Appendix A of the course textbook lists the Assembly formats for all the LC-2 instructions.
Your code should have a comment block at the beginning of the file containing your name, your ECE login name, student number, and a brief description of the program. Your description should serve as a general summary of your program's approach to the problem and will aid in grading. It will also serve as a guideline for assigning partial credit. It is in your best interest to make all of your ideas clear through this summary and through commenting within your code.
IMPORTANT NOTE: The first line of your program must specify the memory
address of where you want your program to be placed (using the .ORIG pseudo-op).
We request you place your program at x3000.
What to turn in
You will submit your program electronically. You can find instruction on how to submit your program in a document titled "How to submit your programs" linked from the course homepage.