Little Man Computer - Simulator Applet

Squaring input:


INP
STA :input
STA :count
sqr: LDA :accum
ADD :input
STA :accum
LDA :count
SUB :one
STA :count
BRZ :end
BRA :sqr
input:
accum: 
count:
one: 1
end: LDA :accum
OUT
HLT

@Riven, you should put an option to choose what kind of syntax highlighting in the ‘code’ tag and then add LMC syntax highlighting option! :slight_smile:

No.

Riven,

Working with the simulator the other day I noticed a small error. Under ‘Print Instructionset’ you have STA and LDA reversed, ie they are correctly compiled to 3xx (STA) and 5xx (LDA), but listed the wrong way round in the print string.

Could you fix it and upload a new .jar file?

John.

Also there’s no Program Counter field. This is necessary to help kids see how the computer can perform a branch instruction by copying whatever is at location xx into the Program Counter.

The Program Counter is the memory cell with the red border.

[quote=“johnkershaw,post:45,topic:37277”]
look at this code:

LDA :var // load 55 into register
OUT // show 55 to the user
BRP :end // branch if positive (we'll branch in this case)
OUT // show 55 to the user (never happens)
end: HLT // quit program
var: 55

and compile it

hit [step]:
[x] memory cell 00 is the current program counter (red), memory cell 05 is refered to as a source (green), register now holds 55

hit [step]:
[x] user is prompted with ‘55’

hit [step]:
[x] BRP is executed… memory cell 03 is the current program counter (red), the potential jump to memory cell 04 is refered to (green), register holds 55, so branching occurs
[x] what else is there to display to the students - there is nothing more to show :persecutioncomplex:

hit [step]:
[x] program halted due to earlier conditional jump (never reaches 2nd OUT)

What I’m trying to convey to the kids is that there’s a no-thinking link between the branch statement and where execution then moves to.

For example, tomorrow afternoon I’m going to have them ‘run’ a paper-based LMC. I’ll draw 100 boxes on the board (maybe less!) and write some compiled instructions in there. They get the hang of looking fetching whichever instruction is ‘pointed to’ by the Program Counter, looking it up in the ‘Decode’ list of mnemonics/instructions, then performing the required task (looking in the ‘IN’ mailbox and writing it’s contents into the accumulator, putting stuff from the accumulator into the ‘OUT’ mailbox, etc…) and after each instruction executes they add one to the number in the program counter box (also on the board), having started it at zero.

Then we come to branching. They hit a statement that says ‘804’ (ignoring labels for now). Looking in the ‘decode’ table they find 8xx, where ‘8’ means copy the ‘04’ into the program counter, then carry on with the next fetch/execute cycle as normal, only now execution has ‘jumped’ to memory location 04. The computer doesn’t need to think, or even know/care that’s there’s been a ‘jump’, only the programmer knows. I’m trying to convey the utter dumbness of the computer, that any cleverness ONLY comes from the programmer. For me, that’s what LMC is all about, pulling back the curtain on the ‘magic box’ and discovering it’s just a clockwork machine that moves numbers around according to a small set of instructions which it follows slavishly.

Think of the red cell as the current PC and the green cell as the potential next PC, if not current+1. Adding a textfield solely to hold the last two digits of the current cell and also the address of the green cell is a bit redundant: three visualisations of one number! Last but not least, there is not really any room in the UI for another textfield.

I think the concept of the PC and how branching works is so trivial, that you can get that well in their heads during the board-demo, after which the LMC app will show them the same information in two (more) ways.

This applet is a simulator, not quite a way to teach new concepts. It’s more a tool to apply what you learned, in the easiest way possible.

By the way; I think it’s best if you’d start off with a 10x1 or 1x10 ‘grid’ on the board, as memory is conceptually one dimensional, so it’s no use to visualize it in two dimensions during the introduction, especially as you want to emphasize the simplicity of the computer: doing a 2D lookup is not trivial in hardware.

Using just 00-09 for starters is a great idea, and is just enough for a few short examples (IN/OUT, add, double, etc).