Little Man Computer User Guide

Peter Higginson's LMC implementation - Help Page from Peter Higginson's LMC implementation

I have also created a GitHub repository dedicated to LMC examples.

Glossary

Knowing the definition of the following words is required to fully understand the User Guide.

Word / Phrase Definition
Accumulator Stores the result of the last operation or calculation.
Program Counter Stores the memory location of the next operation to be executed.

Basic Instructions

The following is a list of the basic instructions that can be performed on LMC.

Instruction Description
HLT Signifies the end of the program.
INP Waits for numeric input and stores it in the accumulator.
OUT Outputs the contents of the accumulator.
ADD Adds the contents of the given memory address to the accumulator.
SUB Subtracts the contents of the given memory address from the accumulator.
STA Stores the contents of the accumulator to the given memory address.
LDA Loads the contents of the given memory address to the accumulator.
DAT Stores the given value in the memory address of the instruction.

Example (basic_calc)

Using the knowledge you've gained above, you should be able to build a simple calculator program like the one below:

    INP    # Waits for input and stores it in the accumulator
    STA 99 # Stores the contents of the accumulator to the memory address: 99 
    INP    # Waits for input and stores it in the accumulator
    ADD 99 # Add the contents of memory address: 99 to the accumulator
    OUT    # Outputs the contents of the accumulator
    HLT    # Signify the end of the program

Labels

In larger programs, you may be storing lots of data, so using raw memory locations all over the place probably isn't the best of ideas. Labels solve this problem, and make you code neater at the same time.

Labels represents a memory address, and can be defined anywhere in your program.

Representing an instruction (labels_basic)

Here we are using a label to represent the memory location of an instruction.

START INP    # Waits for input and stores it in the accumulator
      STA 99 # Stores the contents of the accumulator to the memory address: 99 
      INP    # Waits for input and stores it in the accumulator
      ADD 99 # Add the contents of memory address: 99 to the accumulator
      OUT    # Outputs the contents of the accumulator
      HLT    # Signify the end of the program

Representing a memory location for data (labels_advanced)

Here we are using a label to represent the memory location of data.

START INP     # Waits for input and stores it in the accumulator
      STA NUM # Stores the contents of the accumulator to the memory address of the label: NUM
      INP     # Waits for input and stores it in the accumulator
      ADD NUM # Add the contents of memory address of the label: NUM to the accumulator
      OUT     # Outputs the contents of the accumulator
      HLT     # Signify the end of the program
NUM   DAT 1   # Defines the label: NUM as containing data, and sets it to a preset of 1

Where next?

Eager to continue learning Little Man Computer? Check out my extended User Guide.