Little Man Computer

I had never seen this mini-assembler-based educational computer before.

I couldn’t find a good online emulator, so I wrote one: Little Man Computer Emulator.

Enter the program on the left, click “Assemble”, enter some inputs if your program needs them, and then step through the execution.

It’s probably got some bugs since it was a quick hack, but it worked on the examples I tried it on.

Here’s some example programs.

The last two are the most interesting: LMC doesn’t have indirect addressing – the only load/store instructions are LDA xx and STA xx where xx is a fixed address. To work around that, the code modifies itself, writing the appropriate LDA or STA instruction.

And here’s code that sorts input. It reads N, then a sequence of N numbers from the input and sorts them.

Sort input.

This code has a subroutine, which requires the branch instruction of the subroutine to be overwritten with a branch instruction to the correct return address before calling. The code depends on integer addition wrapping modulo 1000 – my implementation of the LMC does this, but this code may need adapting to work on other versions of the machine, as the spec leaves the overflow behavior of addition and subtraction unspecified.

Paul Hankin Written by:

Programming since 1981, professionally since 2000. I’ve a PhD in programming language semantics but these days I prefer programming in Go, C, and Python. I’ve worked mostly on games and large-scale server software.