-
The Little Man Computer (LMC) provides a simplified model of a computer, making it an easy-to-understand teaching tool for computer science and programming students.
-
Through working with the LMC, students gain a deeper understanding of computer architecture and the basics of pipelining, which are fundamental concepts in computer science.
-
The hands-on approach to programming with the LMC provides practical experience that can be applied in real-world computer systems design and optimization.
We are third-semester Computer Science students at the Pontifical Catholic University of Paraná (PUCPR). This project was a challenge proposed by Professor Frank de Alcantara in the subject Performance in Cyber-Physical Systems.
Codes for Little Man Computers are a set of simple instructions that simulate the instructions of a real computer. The LMC has an accumulator, that keeps one value for operations.
This code takes one input and counts from it to 0.
INP
loop OUT
STA count
SUB one
STA count
BRP loop
HLT
one DAT 1
count DAT
This code adds the inputed numbers
INP
STA number
INP
ADD number
OUT
HLT
number DAT
Labels can be used to increase the complexity of the code, to apply conditions or loops. To create a label, type any name followed by ":" and the first command that should be excecuted when jumped to the label.
#Label named "label1"
label1 OUT
HLT
#Label named "label2"
label2 HLT
#Label named "anyname"
anyname INP
HLT
To branch to a certain label use jump commands.
Command: INP
OPCODE: 901
Will take the next user input and add it to the accumulator. If there are no more inputs, the value added to the accumulator will be 0.
# User input: 1 | 2 | 3
INP
# User input: 1 | 2
# Accumulator: 3
Command: OUT
OPCODE: 902
Will add to the output list the accumulator value
# Output: 2 | 3
# Accumulator: 1
OUT
# Output: 1 | 2 | 3
Command: ADD [ pos ]
OPCODE: 1xx
Will add the value located at the specified position to the accumulator.
# Accumulator: 2
# Value at postion 3: 5
ADD 3
# Accumulator: 7
Command: SUB [ pos ]
OPCODE: 2xx
Will subtract the value located at the specified position to the accumulator.
# Accumulator: 7
# Value at postion 3: 5
SUB 3
# Accumulator: 2
Command: LDA [ pos ]
OPCODE: 5xx
Will load the value inside a RAM Slot to the accumulator.
# Value at position 3: 5
LDA 3
# Accumulator: 5
Command: STA [ pos ]
OPCODE: 3xx
Will store the current accumulator value inside the specified RAM position.
# Accumulator: 2
STA 3
# Value at position 3: 2
Command: LDA [ pos ]
OPCODE: 5xx
Will load the value inside a RAM Slot to the accumulator.
# Value at position 3: 5
LDA 3
# Accumulator: 5
Command: [ name ] DAT (optional: [ value ])
OPCODE: None
Will name a RAM Slot. This command is not executed when the code is running, only before, when loading the code to the RAM. It is possible to pass a initial value. This command should be added AFTER the end of the code.
x DAT
y DAT 12
# On the first free slot after the commands: RAM slot named x, value: 000
# On the second free slot after the commands: RAM slot named y, value: 12
LDA x
STA y
ADD z
SUB name
x DAT
y DAT
z DAT 1
name DAT 3
There are three types of jumps. All jumps will go to the specified label if the conditions are met.
Command: BRA [ Label ]
OPCODE: 6xx
Will always branch to the specified label
BRA exit
exit HLT
Command: BRP [ Label ]
OPCODE: 8xx
Will only branch to the specified label if the accumulator value is positive.
# Accumulator value: 1
BRP exit
exit HLT
Command: BRZ [ Label ]
OPCODE: 7xx
Will only branch to the specified label if the accumulator value is positive.
# Accumulator value: 0
BRZ exit
exit HLT
Command: HLT
OPCODE: 000
Will halt the execution of the code.