|
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Lab 5: TF2 Team RosterDue dateExtended: Due Tuesday, July 28 by 8:00am Lab ObjectiveYour Team Fortress 2 video game match went well; so well, in fact, that your team roster is getting unwieldy for the sticky-notes hung on your wall next to your flamethrower poster (see Figure 1). You think it would be really neat to program a kind of database for your team roster. In assembly. Because it's cool. One of the harder -- but more useful -- pieces of code you will write will be I/O routines. That is, how do you accept input, parse it in the proper context, and display it in the way you need? Integer and string I/O is a major part of this lab. We may reuse this program next week and add features to make it more complicated, so be warned!
Lab tutors: Go over these topicsYour lab tutor will cover the following topics in the first 40 minutes of lab.
Lab 5: TF2 Team RosterYour task is to program in LC-3 assembly language a roster for your Team Fortress 2 video gaming team. Each team member's entry has the following properties.
You should use a menu system to help yourself navigate the roster program. There are two reasons for this: The first is that it's easy. The second is that next week, we might reuse your roster program and add features to make it more complicated; it would be helpful to have a menuing system already in place. What's required
A checkoff, ProcedureAside from being user-friendly, your program must behave as follows. The following fields must be input and output.
Figure 2: The nine Team Fortress 2 classes are (left to right) (top): Soldier, Scout, Medic (center): Demoman, Heavy, Engineer (bottom): Sniper, Spy, Pyro What you will need
You'll need some tools to make all this stuff work. Remember how the only real arithmetic instruction we have is You will need a menu system. You will need to read base-10 user input. A sample algorithm is provided in Figure 3. You will need to display base-10 user input. You will need to display base-16 user input. You will need to multiply and divide using only LC-3 instructions. This will be covered by your lab tutor, and you can also refer to the algorithm in Figure 4. You will need to read a string and store it internally. Example outputTF2 Roster Program MAIN MENU 1. Enter a player 2. Exit > 1 ENTERING PLAYER 1. Enter player's name, class, and score 2. Back to main menu > 1 ENTER PLAYER NAME > fire|BT ENTER PLAYER POSITION CODE 1: Scout 2: Soldier 3: Pyro 4: Demoman 5: Heavy 6: Engineer 7: Medic 8: Sniper 9: Spy > 7 fire|BT (1) played Medic ENTER SCORE LAST MATCH > 98 YOUR PLAYER ID: 0x1 Name: fire|BT Class: Medic Score: 98 MAIN MENU 1. Enter a player 2. Exit > 1 ENTERING PLAYER 1. Enter player's name, class, and score 2. Back to main menu > 1 ENTER PLAYER NAME > heds|BT ENTER PLAYER POSITION CODE 1: Scout 2: Soldier 3: Pyro 4: Demoman 5: Heavy 6: Engineer 7: Medic 8: Sniper 9: Spy > 2 heds|BT (2) played Soldier ENTER SCORE LAST MATCH > 142 YOUR PLAYER ID: 0x2 Name: heds|BT Class: Soldier Score: 142 MAIN MENU 1. Enter a player 2. Exit > 2 ----- Halting the processor -----
An algorithm to read in base-10 input
Figure 3: An algorithm to read in base-10 input
1. Read a value from the keyboard. 2. Is this a newline? If not, continue. If so, go to 8. 3. Is this a minus sign ('-')? If so, the number to follow is negative. Handle this case. If not, continue. Hint: You can use a flag to indicate the input is negative, then two's-complimefy the input at the very end. 4. This is an ASCII value. Convert from ASCII to a number. 5. Add the result into an accumulation register. Consideration: This register must be initialized prior to accepting user input. 6. The accumulation register needs to be multiplied by 10 (the number base of the value coming in). This way, if the user inputs 34, that's really 3x10 + 4. Consideration: The LC-3 does not have a multiply instruction. 7. Go to 1. 8. The last value entered indicated the end of user input. The accumulation register now holds the value of the input. 9. Check for any flags set during the course of user input and perform actions accordingly.
An algorithm to divide using only addition
Figure 4: An algorithm to divide using only addition
We will compute n/d = q remainder r Where:
Synopsis: For n/d, subtract the divisor d from the dividend n a total of q times. The result of the final subtraction is the remainder r. 1. Ensure both numbers are positive. Convert them to positive numbers if necessary; if either is negative, remember this fact with a flag.
2. Subtract the divisor d from the dividend n. We will call the result the partial remainder. Keep track of how many times this step has been executed; the total number is q, the quotient.
3. Check: is the partial remainder 0? If so, go to 7. If not, continue. 4. Check: is the partial remainder negative? If so, go to 6. If not, continue. 5. Go to 2. Use the previous partial remainder as the new dividend (i.e., 102 is thew new n in the example). 6. The partial remainder was negative: You subtracted too far. Undo one of the subtractions by adding back the divisor d. This is the remainder r of the operation.
7. The quotient q is the number of times step 2 was executed. That is, the number of times the divisor was subtracted from the dividend.
Grading templateThis is a suggested grading rubric. 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.
Don't forget the lab write-upYour lab report is still worth 12 points, yo. Document everything you do. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||