Lab 4: Count Dracula's Halloween Adventure
Due date
Due Monday, July 20, by 8:00am
Lab Objective
Assembly language programming is both useful and great fun! Refer to Figure 1 for a picture of a good-looking assembly language programmer!
- Assembly language translates directly into machine code and can be fine-tuned for performance and space concerns.
- Assembly language programmers are few and far between.
- Even in industry you may use assembly language when working with embedded devices.
- The first compiler was written in assembly language!
- You can impress your friends with your arcane knowledge!
What's assumed
For this lab, we assume that you've read chapters 5 and 7 in the textbook and attended lectures. That is, you should know about the LC-3 architecture and instruction set architecture. You should be familiar with LC-3 instructions. You should have a basic understanding of the assembler directives .orig, .fill, and .stringz. You should know what a symbolic label is and how to use it.
If you didn't bring your textbook to class, you can read about LC-3 in Appendix A online. This appendix includes the instruction set architecture (all the commands you can use).
Lab tutors: Go over these topics
Your lab tutor will cover the following topics in the first 40 minutes of lab.
- Everything in the "what's assumed" section above.
- Step through the warm-up procedure below.
- Show how to use the LC-3Edit and Simulate environments.
Warm-up: The LC-3 Simulator
For the next three lab assignments, you will use LC3Edit as your assembler and Simulate as your simulator. In this warm-up, you will launch both and become acquainted with assembler directives, symbolic labels, and some assembly instructions.
What's required
Familiarize yourself with the editor and simulator which you'll be using for the next three weeks.
Procedure
- Start the LC-3 editor, LC3Edit.exe. You can find it on the PCServer in
F:\Class Folders\Computer Engineering\CE 12L\LC3.
- Copy this sample code into the LC3Edit program: echo.asm
- Compile the code by selecting Translate->Assemble or clicking on the "asm" button (
). Save the file in your mounted home directory (X:\).
- Check for errors. If there were problems assembling, correct the errors now. A properly-assembled file will generate the message in Figure 2.
A program with errors will list the errors.
Figure 3 shows echo.asm assembled.
- Start the LC-3 simulator, Simulate.exe. You can find it on the PCServer in
F:\Class Folders\Computer Engineering\CE 12L\LC3.
- In the simulator, open your assembled object (
.obj) file. You can open it with the File->Load Program dialog, or with the toolbar button as shown in Figure 4.
- Now, you are ready to run the program. You can use the Run Program button in the toolbar to run your program all the way through. (See Figure 5.)
The screenshot in Figure 6 shows the program having been run once through.
- You can rerun your program by selecting a new starting address. If you just hit Run without resetting the starting address, the simulator will yell at you! Reset the starting address by setting the "Jump to" field to x3000, and set the program counter (PC) to that address by pushing the button with the blue arrow. Recall that x3000 is the starting address of the program (the first line in the assembly language file is
.orig x3000). Also, you can use the step into and step over functions (next to the Run button) your program to see each line of code being executed one at a time. See Figure 7.
- Every time you make changes to the assembly code, you must re-assemble it, re-load it in the simulator, and run it, verifying that it works as expected.
Lab 4: Count Dracula's Halloween Adventure
You go to a Halloween party where you encounter Count Dracula from Sesame Street (see Figure 8). As you may know, Count Dracula likes to count things; his counting goes something like this.
1 nose!
2 noses!
3 noses! Ha ha ha.
For this lab, you will accept user input in the form of a one-digit number, and you will print out the number of items that Count Dracula counted... all the way from 1 (one) to the number entered.
What's required
A lab write-up, and lab4.asm
Procedure
Your program should behave as follows:
- Display a greeting.
- Display a prompt. How many items did the Count count?
- User is expected to enter one character (using
GETC).
- Make sense of the user's input:
- If the character is a newline (\n), exit immediately.
- If the character is not a number (between 0-9), display an error message and go to 1.
- If it's a number, that's how many items the Count must count.
- However, if it's zero, that makes no sense (zero items?), so go to 1.
- Display 1 to n items that Count Dracula counted, where n is the user's requested number (at most 9).
- Go to 1 (so we can do this as often as we like).
Considerations
- You may choose the item that Count Dracula counts. Will he count noses? Shoe laces? Candies?
- At the first iteration (one item counted), make sure the item is singular -- one nose rather than one noses.
- At the last iteration (the nth item counted), Count Dracula should laugh: Ha ha ha.
- For the generation and output of the Count's counting, we expect you to use a loop with an incrementing counter. There are other ways to accomplish the program behavior, but one of the purposes of this lab is to make sure you understand looping.
- Modify the comments in the code to include your name, e-mail address, lab number, and date at the top of the file.
- Include your register assignments (which register is being used for what), your basic algorithm in a list or pseudocode, and anything else that may help us to read your assembly file.
- See Section 1.2.1 in the Lab Manual for commenting style.
Extra credit
For extra credit (1 point), use a nested loop to have Count Dracula laugh an increasing number of times for each item he counts. This is instead of the laugh at the very end of his counting. Extra credit will not be given if a nested ha-generating loop is not used.
1 nose! Ha.
2 noses! Ha ha.
3 noses! Ha ha ha.
4 noses! Ha ha ha ha.
Example output
Welcome to the Halloween party! This is my first LC-3 program.
How many homework assignments does Count Dracula see?
3
1 homework assignment!
2 homework assignments!
3 homework assignments! Ha ha ha.
Welcome to the Halloween party! This is my first LC-3 program.
How many homework assignments does Count Dracula see?
0
That makes no sense. Of course you have homework!
Welcome to the Halloween party! This is my first LC-3 program.
How many homework assignments does Count Dracula see?
----- Halting the processor -----
Grading template
This is a suggested grading rubrik. 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.
Coding requirements
- Assemble with no errors, initialize appropriate registers
- Display a greeting and prompt
- Accept character input from the user
- Properly discard non-numeric input, properly handle the 0 case, and halt at newline
- Display the counting as expected (in a loop with a incrementing counter)
- Does your code do what you think it does? (Miscellaneous errors)
15 points total
Extra credit:
- (1 pt) Increasing laughter with a nested loop
Comments requirements
- Nice block comment at the top
- Clear comment on register usage, and clear comments all along
- Code is indented and aligned nicely
- Does your code do what you think it does? (Commenting/algorithmic errors)
5 points total
Lab write-up requirements
Let's face it. Your assembly language (.asm) file will be ugly. So ugly, in fact, that we want you to tell us about it.
In the lab write-up, we will be looking for the following things. The lab report is worth 12 points. We do not break down the point values; instead, we will assess the lab report as a whole while looking for the following content in the report.
- The algorithm you are using to write your program, in simple, layperson's terms, or in C-like pseudocode
- What works, what doesn't
- Example output
Additionally, please answer the following questions.
- What is an addressing mode?
- What are the five LC-3 addressing mode? Give an example of each one.
- What is a TRAP instruction? Give two examples.
- Which register is used as a place to put a return value for TRAP instructions? Why is it always that register (and not a register of your choosing)?
|