Binary LMC - Little Man Computer Simulator

LMC assembly code:
  or CTRL+S
Pause after:
Share a link to your program in memory:

Above is a Little Man Computer (LMC) simulator. The original LMC uses denary instructions, but I created this one to use binary instead to more closely model what happens in a CPU. It has a 5bit address bus and an 8bit data bus. All instructions are 8bits with direct addressing as the only addressing mode. Memory is limited to 32 x 8bit slots for 32bytes total memory.

Binary LMC instruction set

Opcode Mnemonic Description
001xxxxx STA Store value from accumulator to memory address xxxxx
010xxxxx LDA Load value from memory address xxxxx into accumulator
011xxxxx ADD Add contents of memory address xxxxx to accumulator
100xxxxx SUB Subtract contents of memory address xxxxx from accumulator
101xxxxx BRA Branch to memory address xxxxx, unconditionally
110xxxxx BRZ Branch to memory address xxxxx if accumulator is zero
111xxxxx BRP Branch to memory address xxxxx if accumulator is positive (or zero)
00001xxx INP Input from user into accumulator (xxx not used)
00010xxx OUT Output value of accumulator to the output box (xxx not used)
00000xxx HLT Terminates execution of the program
- DAT A memory location that contains data (an integer from -128 to 127)

The instruction set is the same as for the denary LMC - programs written in LMC assembly should work fine. Lines of assembly start with an optional label, then have one of the 11 mnemonics, then an optional value (which could be a denary integer or the name of a label defined on another line). Example program:

        INP         # user inputs a value
        STA   a     # which is stored into 'a'
        INP         # user inputs another value
        ADD   a     # which has 'a' added to it
        OUT         # and is then output
        HLT         # program terminates
    a   DAT         # ... location to store 'a'
    # Not used in this program...
    b   DAT   34    # put '34' in memory labelled 'b'

Data is 8bit signed integers in 2s-complement, between -128 and +127.

You may like other cool free things I've made.