Learning Objectives
- To learn the basics of assembly language programming
- To understand how a program is processed by the central processing unit (CPU)
Learning Outcomes
All must copy the example LMC adding program. With lots of help come up with working solutions for problems 1 and 2. Taken screenshots of the code and a test result. (Grade D/E)
Most should copy the example LMC adding program. Come up with working solutions for problems 1 and 2 with not much help. Taken screenshots of the code and a test result. (Grade B/C)
Some could copy the example LMC adding program. Come up with working solutions for problems 1, 2 and 3 mostly independently. Taken screenshots of the code and a test result. (Grade A*/A)
Keywords
Words to learn: assembly, language, programming
Starter
In the last lesson you were introduced to the Little Man Computer (LMC). The LMC is a simulation of a very basic small computer. Programs in the little man computer are written in assembly language.
Assembly language is a simple language which directly represents the binary code that a CPU actually works with.
Let’s start with a table showing you some of the basic assembly language instructions that the Little Man Computer’s processor can understand:
Instruction | Mnemonic | What does it do? |
Load Accumulator | LDA | Transfers a number from RAM to the accumulator |
Store Accumulator | STA | Transfers a number from the accumulator to RAM |
Add | ADD | Adds the contents of the accumulator to the contents of a RAM address |
Subtract | SUB | Subtracts the contents of the accumulator from the contents of a RAM address |
Input | INP | Input a value and store in the accumulator |
Output | OUT | Display the contents of the accumulator |
End | HLT | Stops the processor |
So let’s make our first program. We are going to create the following program:
Ask the user for a number Store the number in RAM address 90 Ask the user for another number Store the number in RAM address 91 Load the accumulator with the contents of RAM address 90 Add the accumulator with the contents of RAM address 91 Output the answer Stop
So, this in assembly language becomes:
INP STA 90 INP STA 91 LDA 90 ADD 91 OUT HLT
Try copying this into the Little Man Computer (click here to open it) and see if it works!
Main – Challenges
Create a Little Man Computer (LMC) program for each of the problems below. For each problem take a screenshot of your finished code and show the results of a test run to make sure it works!
Problem 1
Ask the user for three numbers. Display them in reverse order.
Inputs | Outputs |
7,8,9 | 9,8,7 |
8,16,32 | 32,16,8 |
Problem 2
Ask the user for three numbers. Add them up and display the answer.
Inputs | Outputs |
7,8,9 | 24 |
8,16,32 | 56 |
Problem 3
Ask for two numbers. Display the first number minus the second number. Display the second number minus the first number.
Input | Output |
7,3 | 4,-4 |
5,12 | -7,7 |
Plenary
Come up with a problem of your own and challenge the person sat next to you to come up with a Little Man Computer program.