🙋 The Little Man Stack Machine

Introduction

The Little Man Stack Machine (LMSM) is a backwards-compatible extension of the venerable and excellent Little Man Computer (LMC) teaching computer model. It is designed to be a teaching aid, to show people how various aspects of computing work in an easy and approachable manner:

The LMSM is simple enough that someone interested should be able to build an LMSM emulator, an assembler and a compiler from a high-level language to assembly in a short amount of time, such as within a single quarter or semester.

Like the LMC, the LMSM models a simple Von Neumann computing machine and the execution cycle is identical to the LMC. In order to better support more computational topics that the LMC did, the LMSM adds the following functionality:

System Diagram

Below is a system diagram of the LMSM:

Overall System Description

Like the LMC, the LMSM works only in terms of integers between the values -999 and 999. These integers can be interpreted as either data or as instructions, depending on the context they are used in. The LMSM follows a simple Von Neumann style Instruction Cycle: it loads an instruction from memory, bumps the program counter, executes the instruction and then repeats.

More detail on the execution cycle can be found on the Assembly & Execution page.

Registers

The LMSM has a total of five registers (two more than the LMC). The registers are as follows:

Memory

The LMSM has a total of 200 memory slots, double that of the LCM. The memory is split into two sections: "lower" and "upper" segments. Traditional LMC instructions such as ADD operate on the lower memory segment, while the new stack instructions of the LMSM operate on the upper section of memory.

The Stacks & Function Calls

A major goal of the LMSM is to provide hardware infrastructure for implementing function calls so that students can see how the function call abstraction can be implemented on top of raw registers and memory. This is a crucial concept in computer science, allowing us to build far more sophisticated pieces of software than raw assembly does.

The function invocation mechanism in the LMSM is very simple when compared with real-world computers, but it demonstrates the core concepts of using stacks to hold function-call related values and recursive function calls.

See Functions for a detailed look at function calls on the LMSM.

Firth

While the LMC is great for introducing students to assembly and how low level computation works, it does not provide enough infrastructure for easily creating a high-level programming language.

By offering a slightly more sophisticated CPU model the LMSM makes it possible to create a simple Forth-inspired language in a relatively short amount of time. This "high-level" language can then be compiled down to LSMS assembly code fairly easily.

The language includes functions, loops, conditionals and so, er, forth: the basics of higher-level programming.

See Firth for more information on this language.