CMPE12, Spring 2012, Section 01: Lab 4: Not My Number

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

Richard Friendman, 1964 Figure 1: A good-looking assembly language programmer named Richard Friedman, 1964. Click the photo to read about his 40 years with computers.

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.


  1. Start the LC-3 editor, LC3Edit.exe. You can find it on the PCServer in F:\Class Folders\Computer Engineering\CE 12L\LC3.
  2. Copy this sample code into the LC3Edit program: echo.asm
  3. Compile the code by selecting Translate->Assemble or clicking on the "asm" button ([asm]). Save the file in your mounted home directory (X:\).
  4. 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.
    Starting Pass 1...
    Pass 1 - 0 error(s)
    Starting Pass 2...
    Pass 2 - 0 error(s)
    Figure 2: The status window for a properly-assembled program will show 0 errors for each of the two passes. echo.asm in the LC-3 editorFigure 3: Viewing echo.asm in the LC-3 editor. It has been assembled with no errors.
  5. Start the LC-3 simulator, Simulate.exe. You can find it on the PCServer in F:\Class Folders\Computer Engineering\CE 12L\LC3.
  6. 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. Opening an object in the simulator using the toolbarFigure 4: Use this toolbar button to open an object in the simulator
  7. 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. Running an object in the simulator using the toolbarFigure 5: Use this toolbar button to run an object in the simulator Running an object in the simulator using the toolbarFigure 6: The sample file (echo.asm) has been run in the simulator.
  8. 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 overfunctions (next to the Run button) your program to see each line of code being executed one at a time. See Figure 7.
  9. 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. Using jump-to to restart the programFigure 7: Jump to the starting address (defined by .orig -- usually 0x3000 -- in the program), and set the PC to that value, to run the program again.

Lab 4: That's Not My Number!



For this lab, you will accept user input in the form of a one-digit number, and you will print out all the numbers but the one you entered, because you hate that number... all the way from 1 (one) to 9 (nine), omitting the number entered.

What's required

A lab write-up, and lab4.asm


Your program should behave as follows:

  1. Display a greeting.
  2. Display a prompt. What's your favorite number?
  3. User is expected to enter one character (using GETC).
  4. Make sense of the user's input:
    • If the character is a newline (\n), exit immediately. Use the ASCII table to find the line-feed (LF) character.
    • If the character is not a number (between 0-9), display an error message and go to 1.
    • If it's a number (1-9), that's the number that you hate!
    • If it's 0, print an error message and go to 1.
  5. Display all numbers from 1 to 9, but skip n, where nis the user's requested number (at most 9).
  6. Go to 1 (so we can do this as often as we like).


  1. For the generation and output, 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.
  2. Modify the commentsin the code to include your name, e-mail address, lab number, and date at the top of the file.
  3. 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.
  4. See Section 1.2.1 in the Lab Manual for commenting style.

Example output

Yo!  This is my first LC-3 program.

What's your favorite digit, yo? 


Really? I hate that number!

1 2 4 5 6 7 8 9

Yo!  This is my first LC-3 program.

What's your favorite digit, yo? 


That's not even a real number, yo.

Yo!  This is my first LC-3 program.

What's your favorite digit, yo? 

----- 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) 40 points total

    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) 10 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 50 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)?


  • echo.asm, application/octet-stream, 1,069 bytes
  •, application/x-zip-compressed, 513,038 bytes
  •, application/x-zip-compressed, 665,360 bytes