2

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?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • There are a number of starting points like this I am still a big fan of the pdp11 as a starting point (there is even gnu support right now) due to the cleanliness of the instruction set...Current multi-core processors with layers of protection and other features are not a good starting point because of the volume of stuff to wade through. some are better starting points than others, but most starting points get you through basics and then move forward with more complications until you reach the present rather than sink or swim. – old_timer May 12 '20 at 14:27
  • Today there are a vast array of simulators which are a good safe starting point with more visibility than straight hardware to help through simple but fatal traps that are hard to see and avoid or get out of. – old_timer May 12 '20 at 14:29
  • Everyone learns differently and is entertained/motivated differently so there is no one right answer for you, best is a personal thing and we all have our own best or better that is for someone else bad or worst. There are so many choices out there, the best start is to try each for a bit and keep going, some may be very good but you may struggle getting the tools to work on your system for various reasons and force you to choose to keep that battle going or find another path. – old_timer May 12 '20 at 14:31

2 Answers2

3

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'.

pacukluka
  • 728
  • 4
  • 18
  • 1
    Thank you very much, and sorry, I´m really a beginner – Augusto Barreto May 12 '20 at 13:37
  • 1
    pipelined / Super-scalar / out-of-order implementations of an ISA are orthogonal to its design. You could in theory have an OoO exec LMC (using binary to encode numbers). By renaming the accumulator it could maybe find some ILP across independent instructions. LMC's 100 "mailboxes" is a tiny enough address space that you could basically treat that as a register file. It doesn't have indirect load/store instructions so you only need to decode load/store addresses as register numbers to move to/from the accumulator. – Peter Cordes May 12 '20 at 14:58
3

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.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847