Computing Systems And Assembly Language
             
             
             
             
 

Lab 5: TF2 Team Roster

Due date

Extended: Due Tuesday, July 28 by 8:00am

Lab Objective

Your 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!

Team Fortress 2 Flamethrower
Figure 1: The Hottest in Home Incendiary Devices (click to enlarge)

Lab tutors: Go over these topics

Your lab tutor will cover the following topics in the first 40 minutes of lab.

  • What is a procedure?
    ---> Answer
  • How do you store the user's input data?
    ---> Answer
  • How to use integer division (and remainders) to print out a number, one character at a time
  • How to use multiplication to read in a number, one character at a time
  • How read in and store a string, one character at a time

Lab 5: TF2 Team Roster

Your 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.

  • ID: The ID is used for unique identification of the player.
  • Name: The name of the player and any clan tags.
  • Class: Which class does the team member play?
  • Score: The player's score in the previous match.
You will store each attribute of the player's data and then output it. Nothing needs to be stored for an extended period of time -- once it's output, you can forget about it. However, the ID should increment for each new entry.

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, lab5.asm, and a lab write-up

Procedure

Aside from being user-friendly, your program must behave as follows. The following fields must be input and output.

  • ID: The ID is used for unique identification of the player.
    • Input: The user will not enter this value; your roster program assigns a unique number to each entry. You may use a counter that just increments with each new entry.
    • Output: Integer in hexadecimal (base 16)
  • Name: The name is a string up to 64 characters long.
    • Input: Read them in as characters until newline. The newline is the termination character. Internally, store the string as a null-terminated value. You do not need to check that the string is short enough; you may assume no name will be longer than 63 characters.
    • Ouput: Since it's a null-terminated string, you can just PUTS it.
  • Class: Which class does the team member play? Refer to Figure 2 for class selection. (1: scout; 2: soldier; 3: pyro; 4: demoman; 5: heavy; 6: engineer; 7: medic; 8: sniper; 9: spy)
    • Input: A one-digit number. Make sure it's entered as a number (integer), and not a character, because someday you may want to have more than 9 possible classes. Check that the number the user entered makes sense in this context (it's between 1 and 9).
    • Output: As output, you will translate the number into a string (so 1 is output as "scout", 2 means "soldier," and so on).
  • Score: The player's score in the previous match is input as a number (integer).
    • Input: For the purposes of this assignment, assume the score is always positive or zero (no negative scores).
    • Output: Integer in base 10.
    The nine different Team Fortress 2 classes
    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 ADD? Positional number systems typically want us to subtract, multiply, and divide.

    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 output

    TF2 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

    1. Read a value from the keyboard.
    E.g., '3'

    2. Is this a newline? If not, continue. If so, go to 8.
    E.g., A newline may indicate the end of user input.

    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.
    E.g., '3' -> 3 (the conversion is on the ASCII table; '3' is 0x33.)

    5. Add the result into an accumulation register. Consideration: This register must be initialized prior to accepting user input.
    E.g., R3 = x0003

    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.
    E.g., R3 = x001E (why? That's x0003 times x000A, or 3 times 10)

    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.

    Figure 3: An algorithm to read in base-10 input
    An algorithm to divide using only addition

    We will compute n/d = q remainder r

    Where:

    • n is the dividend,
    • d is the divisor,
    • q is the quotient,
    • r is the remainder.

    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.
    E.g., 113/11

    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.
    E.g., 113 - 11 = 102

    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.
    E.g., 113 - 11 - 11 - ... - 11 = -8 + 11 = 3 is the remainder

    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.
    E.g., 11 was subtracted from 113 10 times. (Actually, 11 but then we added back once).

    Figure 4: An algorithm to divide using only addition

    Grading template

    This 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.

    • Integer input in base 10
    • Error checking
    • Integer output in base 16
    • String input
    • String output
    • Gracefulness of menuing system
    • Use of procedure calls
    • Fields make sense
    • Discretionary

      Total: 30 points

    Don't forget the lab write-up

    Your lab report is still worth 12 points, yo. Document everything you do.

  • impact-silly