Assembly Language Programming

Course Index 
Dr. Margush's page 

Programming Assignment

Pick one of the following: HILO / CALC01

Binary Hi/Lo

You will write a program to play the HILO guessing game. Input and output will be through the serial port. Configure communications for 4800 baud, N-8-1. No error checking needs to be done. Assume a 1MHz internal clock on the ATMega16.

When the program is reset, it should dieplay a message on the terminal.

Welcome to the fabulous game of HILO. 
I am thinking of a number. You try to guess.
Do you want to play in binary (B) or hexadecimal (H)?
You have to enter everything in binary.
Enter your name to begin: 

The player will have to press either B or H before the 4th line is displayed. Do not echo this character. Accept upper or lower case and transmit a bell if any other key is pressed.

At the name prompt, the player enters their name, terminated by a carriage return. You need to echo these keypresses back to the terminal, store the name in memory, and use it in your game play. You will also use a timer to get a random number. The timer should be started when the program starts, and read when the player enters their name. This should be a relatively unpredictable value. Your secret number is a 16-bit value.

Prompt for the first guess something like this:

Guess the secret number, Dave: 

The player will then type something like 100111011010 (and press enter). You should echo this back to the terminal (or the player will be very confused).

You will decide if it is above or below the secret number and provide feedback. Your program will output messages such as these during game play:

That is too high, Dave. Enter something smaller:
That is too low, Dave. Enter something bigger:
Good guess, Dave. You got it in 3 tries!
Do you want to play again, Dave? (0 for yes, 1 for no):
Game over, Dave. 

The player may enter binary values of 1 through 16 digits. If they enter too many, just ignore some of them. All illegal keypresses should cause the bell character to be transmitted, but otherwise ignored. Be sure to count tries so the player knows how well they did.

It is your responsibility to design useful functions and use them appropriately. Function arguments may be passed in registers rather than the stack. Functions should be documented. Functions should illustrate good reusability and modularity. Consider functions such as:

outputstringfromflash(addr);
outputstringfromram(addr);
sendbyte(b);
readbyte();
initializeusart(baudrateparam,parity,databits,stopbits);
initializecounter();
getsecretnumber();
readnumber(base);

CALC01 (alternate project)

Design an RPN calculator that uses serial communication to evaluate expressions. You need to perform 32-bit arithmetic internally. Input can be in binary or hex. The mode should be selected when the program begins. Expressions such as

10 110 100101 1111111111 + + - 1011 +
or
4c5 60 + 3C 2F16FfFF - +

will be entered at a terminal. The AVR program will evaluate them as they are received using the stack to perform all computations. I would suggest writing some macros, and possibly using a data stack for this program. 

The program begins by displaying a message on the terminal screen:

Welcome to CALC01, your friendly RPN binary calculator.
Type H for hexadecimal mode, B for Binary mode:
I see you like Binary.
What is your name:

The user will simply press H or B (ignore all other keypresses, but echo the legal input). You will store the calculant's name, and use it in communications. Your program must use phrases such as:

Please enter an RPN expression, Dave: 
Do you know what RPN is, Dave?
Dave, I can only process + and - for the operations.
Your expression evaluates to (binary or hexadecimal value here)
Thanks Dave. You may disconnect the serial cable now.

The calculant may enter binary numbers or hexadecimal numbers of any size; you should throw away extra digits if they are found (it does not matter which ones). Illegal characters should result in a message (immediately displayed). You will be processing these expressions as each character is input... you will never store the entire string. Be sure to echo input. Display the output without unnecessary leading zeros. You can use a sentinel expression such as 0 to end the program. Note that the calculant will press enter when finished entering the expression. Be careful of illegal stack operations!

Use the same communication parameters as specified above. You have to follow the same rules regarding appropriate function design and usage. You should also consider appropriate use of macros. In addition to some of the functions suggested above, functions such as

add();
subtract();
pushdoubleword(w);
isstackempty();
initializestack();
poptwowords();
getnumber(base);
outputnumber(base);

may prove useful.

Return to Dr. Margush's page