Department of Electrical and Computer Engineering
University of Texas at Austin
EE 379K, Fall 2000
Y. N. Patt, Instructor
TAs: Kathy Buchheit, Laura Funderburg, Chandresh Jain, Onur Mutlu, Danny Nold, Kameswar Subramanian, Francis Tseng, Brian Ward

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.

• If you are working from Windows, submit your program by clicking on the Submit-ITC program. This will bring up a window where you fill in your ECE login name, the last four digits of your social security number, the unique number of the discussion section in which you would like your programs returned to you, the name of the file you are submitting, and the program number. To enter the file name, you should click on the find button and locate your file. The program number for this assignment is 3.
• If you are working from Unix,  submit your program using the submit-itc script. The program number for this assignment is 3.

• submit-itc 1234 myprog.asm 3
where 1234 is the last four digits of your social security number, myprog.asm is the name of your text file, and 3 is the program number.
Good luck.