Augusto Barreto
Augusto Barreto

Reputation: 69

Is Little Man Computer still relevant?

I´m trying to learn how computers actually works, I found some simulator software but the seem to be very complex (I´m still a beginner). I saw Little Man Computer (LMC) which is very old. I´m afraid the way the software works is not what exactly happens nowdays.

So, is Little Man Computer still relevant for me to learn how computers work? Is there a better one?

Upvotes: 2

Views: 1495

Answers (2)

Peter Cordes
Peter Cordes

Reputation: 364458

LMC is a von Neumann architecture like real computers, but in other significant ways it was never much like real computers, and less so now (e.g. being an accumulator machine).

It's still in use as a toy architecture for teaching some basics of assembly language; SO has a tag for it with ~50 Q&As.

There are other toy ISAs like LC-3 that are simple but are binary computers with multiple registers. Accumulator machines are unnecessarily painful to program by hand in assembly compared to having a handful of registers for your "local variables". LC-3 is a 16-bit ISA with eight 16-bit registers. Instructions are 16 bits wide and have 4-bit opcodes. Unlike LMC, most toy ISAs including LC-3 are based on binary numbers, and have indirect addressing where you can use a register as the address for a load or store.

LMC doesn't have indirect memory addressing: load and store instructions must have the absolute address hard-coded into the program. So if you want to e.g. loop over an array or use a lookup table, you need to write self-modifying code that stores a new address into a "mailbox" that's going to execute as code.

Being forced to write self-modifying code to do some kinds of computation is very much unlike the situation in real modern computers. Most ISAs are Turing-complete (except with finite memory) and/or can be the target of a C compiler without self-modifying code, i.e. the instructions can be kept in read-only memory if you want.

It's useful to understand that SMC is possible, e.g. for JIT compiling, but not to learn that it's the normal way to dereference a pointer.


LMC has some of the principles of assembly language for real CPUs (executing one instruction at a time which makes some change to the architectural state).

But it specifically avoids providing any binary operations like bitwise AND, shifting, or anything like that. This makes some things that are easy in real computers difficult in LMC.

(Wikipedia): The LMC is generally used to teach students, because it models a simple von Neumann architecture computer—which has all of the basic features of a modern computer. It can be programmed in machine code (albeit in decimal rather than binary) or assembly code.

It only operates on numbers via add and sub operations, which don't depend on numbers being represented in binary. They could work just as well with a little man in a room using decimal numbers on paper, or collections of marbles. It's intentionally simplified to this point, but that makes it really annoying to program for when you know that real computers can do things like dividing by 2 very efficiently, while on LMC you need a stupid loop doing repeated subtraction, or fancy tricks with tables of powers of your divisor.

LMC has some weird limitations that other toy machines (like LC3) don't have: numbers must be positive. How create an Little Mans Computer (LMC) code that will get a number. Display 1 if the number is odd, display 0 if the number is even shows how this requires you to be careful to avoid that because it's undefined in the "ISA", and different simulators treat add or sub overflow differently.

Also it shows that testing for odd/even (trivial in binary or decimal) is a big pain in LMC where you can't exploit any place-value representation, binary or otherwise.

By contrast, most other toy ISAs (like all modern real ISAs) use 2's complement for signed numbers. IMO learning about binary integers is an important part of assembly language.


@trincot has written some other nice LMC answers, including on What happens to instructions given to the Little man in the LMC that begin with 4?


Superscalar / out-of-order implementations.

Of course, most ISAs are defined in terms of sequentially executing one instruction and then the next. Real implementations typically execute more than one in parallel (when instruction-level parallelism allows) while maintaining that illusion.

You could build a superscalar out-of-order LMC or LC-3 if you wanted; programmers don't need to know about that unless the ISA makes parallelism explicit, e.g. the Mill's or IA-64's explicit speculation, or load / branch delay slots on MIPS.

See http://www.lighterra.com/papers/modernmicroprocessors/ and also this answer on how real CPUs execute multiple instructions in parallel.

Note that self-modifying code is a problem for superscalar CPUs; e.g. real x86 CPUs flush the pipeline when you modify memory bytes that are near code that's in flight in the pipeline.

Upvotes: 3

pacukluka
pacukluka

Reputation: 735

It isnt exactly what happens nowadays but it certainly does show the basic principles.

Nowadays CPUs have multiple cores and methods of executing multiple instructions at once, and usually arent 16 bit like the little man simulator. They also can have SIMD instructions and other bells and whistles.

To understand whats happening you would like to read some theory and use the simulator to practically see what exactly happens on each step, so dont just rely on the simulator to understand how a cpu works.

It certainly is good enough to learn. In future questions you might want to link the things you are talking about instead of saying 'this little man computer one'.

Upvotes: 3

Related Questions