Little Minion Computer Notes (Student Copy)
Little Minion Computer Notes (Student Copy)
Calculator
Little Minion
In-tray
Mailboxes
Out-tray
Counter
The mailboxes each have a 2-digit address, so 100 mailboxes is the limit, counting from 00 to 99.
Each mailbox contains a slip of paper with 3 digits on it, and can only ever contain a single slip of
paper at a time.
The calculator that can only display 3 digits on the screen, and has buttons for numbers 0-9 and +
and - . It also has an LED that lights up when a larger number is subtracted from a smaller number.
This LED is known as the negative flag.
The 2-digit counter has two buttons: the first button increments the counter by 1, the second
(external) button resets the counter to 00.
The input and output trays can each contain stack of slips of paper, each of which has 3-digits
on. The user can put slips of paper with 3 digits on in the input tray, to be read when the little
minion next looks at the in tray. Likewise the little minion can write 3-digit notes and put them in the
out tray, to be read by the user.
The Fetch-Execute cycle
1. The little minion starts by looking at the counter for number, which is a mailbox number.
2. The minion increments the counter, so that next time the minion comes it will be one larger.
3. The minion goes to the mailbox with the number the minion read on the counter, and reads
what is written on the slip of paper in the mailbox, i.e. 3 digits.
4. The minion takes the appropriate action depending on those digits
5. The minion then starts again…
Steps 1-3 are the fetch: the little minion is fetching an instruction. Step 4 is the execute: the little
minion does the indicated instruction.
The instructions:
The little minion will read a 3-digit message in the mailbox the minion is sent to, e.g. 5 8 4, which is
the minion's instruction. The first digit of the instruction is the operation: 5. The second and third
digits give another mailbox number: 84. The operation part is also known as an “operation code”
or “op code”, the other two numbers are an address. Op code 5 is load: the little minion goes to
the mailbox indicated by the address, copies what is on the slip of paper in the mailbox, then goes
to the calculator and enters that number. E.g. if mailbox 84 contained 1 2 3, then when the little
minion reads instruction 584, the minion goes to mailbox 84, copies down 123, then goes to the
calculator and enters 123.
Let’s define some more op codes and give the little minion a task.
ADD – op code 1
go to the mailbox address specified, read the 3-digit number at that address, then go to the
calculator and add the number to the number already on the calculator.
SUBTRACT – op code 2
go to the mailbox address specified, read the 3-digit number at that address, then go to the
calculator and subtract the number from the number already on the calculator.
Note: the mailboxes will still contain the same 3-digit messages as before, but the calculator
will have changed. If the subtracted number is larger than the value already in the calculator
(i.e. the subtraction ends with a negative value), then the negative flag is set/activated and
the value in the calculator cannot be trusted to be right.
STORE – op code 3
go to the calculator and note the 3-digit number displayed, then go to mailbox address
specified and enter that number on a new slip of paper.
Note: the calculator will still contain the same 3-digits as before, but the mailbox will have
whatever was there before discarded.
LOAD – op code 5
go to the mailbox address specified, read the 3-digit number at that address, then go to the
calculator and enter that number in.
INPUT/OUTPUT – op code 9
INPUT or READ op code 9 address 01
go to the IN tray, read the 3-digit number there, then go to the calculator and enter the
number in.
Note: The slip of paper in the IN tray with the 3-digits is removed. If there are several slips in
the IN tray, the little minion takes the first one that was put there only, the others remain for
future visits.
OUTPUT or PRINT op code 9 address 02
go to the calculator, read the 3-digit number there, then go to the OUT tray and leave a slip of
paper with that number on it.
BREAK – op code 0
The little minion stops and has a rest.
A program
When the Little Minion Computer is started, the counter is reset to Mailbox Contents
00, and the mailboxes will already contain some values, so the little
minion starts by visiting mailbox 00 and executing the instruction 00 901
there. What the minion does after that depends on the instructions! 01 306
02 901
Look at the initial mailbox contents given to the right. What will the
little minion do? What does this achieve? 03 106
04 902
• The minion first gets an input and puts it in the calculator 05 000
• Then the minion stores that in mailbox 06
• The minion gets another input (into the calculator) 06 000
• Then adds the contents of mailbox 06 to the value in the 07 000
calculator
08 000
• Next the minion takes the calculator value and copies it to the
output tray 09 000
• Finally (instruction in mailbox 05), the minion halts.
The total effect of this is to take two numbers from input and
output the addition of those two numbers.
Mailbox 06 is used there as a temporary storage for a value, since it is empty and unused by the
program. Why didn’t we use mailbox 05, the first 000 value mailbox?
• Although mailbox 05 looks empty, it is in fact the instruction 000, i.e. HALT. If we used mailbox
05 to store the temporary value, then whatever we stored would be read as an instruction once
the little minion finished with the instruction in 04.
• Change the program to have 305 in mailbox 01 and 105 in mailbox 03, then see what happens
(e.g. on inputs 300 and 301).
• So the LMC does not distinguish between data and program instructions! This is central to the
concept of stored program computing.
Exercises
Enter values in the mailboxes so that when the Little Minion starts (with counter at 00)
• The minion takes 3 inputs values and then outputs the sum of all of them
• The minion takes two input values, a and b, and outputs the difference, a - b.
• What happens if you subtract something large from something small? E.g. 350 from 100
If you subtract something large from something small then the negative flag is activated
and the value outputted is wrong.
More instructions
Data movement:
LOAD – op code 5
STORE – op code 3
Arithmetic:
ADD – op code 1
SUBTRACT – op code 2
Input/Output:
INPUT – op code 901
OUTPUT – op code 902
Machine control:
BREAK – op code 0
To get the Little Minion to do more powerful calculations, we need to have more control over the
machine and in particular the flow of the program - i.e. which instructions the minion does when.
We do this with branch instructions.
BRANCH – op code 6
set the counter to the 2-digits specified in the address.
Note: The next instruction the minion reads is the one in the mailbox address specified.
To have even greater control we allow two more complex branch instructions: conditional branch
instructions.
Mailbox Contents
• The program takes two inputs and stores them in boxes 11 and 00 901
12. 01 311
• It then subtracts.
• If the subtraction gives something positive, the program 02 901
branches to 08, where it loads the first number and outputs it. 03 312
• If the subtraction triggers the negative flag, the program does not 04 211
branch, so it loads the second number and outputs it.
05 808
• The effect is to output the smaller of the two inputted numbers.
06 512
07 609
08 511
09 902
10 000
Exercise
Enter values in the mailboxes so that when the Little Minion starts (with counter at 00)
• The minion takes 2 inputs values, a and b, and then outputs all integers between the
two inputs.
• First assume a < b. Then try and get it to work for inputs either way round.
IN
STO A
IN
ADD A
OUT
HLT
A DAT
Note that each line starts with a label or a tab, then has a mnemonic, then if the interaction needs
an address, has another tab and an address label. We give this text to a special program called a
compiler that will turn it into machine code and fill suitable mailboxes with the result. There is a
compiler in the Little Minion Simulator.
Further Exercises
1. Give assembly code for your earlier programs, e.g. the one to output all numbers between two
input values.
2. Create a Little Minion Computer program to output the Fibonacci numbers. Look up Fibonacci
numbers online if you are not familiar with them.
3. Create a Little Minion Computer program to output the first ‘n’ Fibonacci numbers. Your
program should take the input n and then output the first n elements of the sequence. I.e. 1, 1,
2, 3, 5…
4. Create a Little Minion Computer program to take two inputs a, b and compute a × b.
5. Create a Little Minion Computer program to an input a and compute a divided by 2.
6. Create a Little Minion Computer program to take two inputs a, b and compute a divided by b.
7. Create a Little Minion Computer program to take inputs until an input of 0 is received, then
output the sum of the inputs.
8. Create a Little Minion Computer program to take inputs until an input of 0 is received, then
output the smallest of the inputs.
9. Create a Little Minion Computer program to take two inputs and output the highest common
factor (look up Euclid's algorithm).
These notes are based on the description of the Little Man Computer found in the book: The
Architecture of Computer Hardware and System Software: An Information Technology Approach,
3rd edition, by Irv Englander.