Tue Oct 4 20:01:46 EDT 2005

Toy Machine Simulator

(You must have Javascript enabled.) Type your program in the left window. Labels must start in the first column and operators like "get" or "add" must start anywhere but the first column. The simulator does not distinguish upper case from lower case, but is otherwise not robust, so be sure to spell instructions correctly and format code carefully.

Push RUN to run your program. A dialog box will appear when a "get" is executed, and output will appear in the right window. The simulator will stop if you Cancel a "get" or don't enter anything.

          Accumulator:

    

Syntax reminder

get      get a number from keyboard into accumulator
print    print contents of accumulator
load M   load accumulator with contents of location M (M unchanged)
store M  store contents of accumulator into location M (accumulator unchanged)
add M    add contents of location M to contents of accumulator (M unchanged)
sub M    subtract contents of location M from contents of accumulator (M unchanged)
goto L   go to instruction labeled L
ifpos L  go to instruction labeled L if accumulator is greater than zero
ifzero L go to instruction labeled L if accumulator is zero
stop     stop running
init V   initialize this memory location to value V (once, before program runs)
If M is a number like 17, that value is used directly; if M is a name like M, it refers to a labeled instruction. So add N means to add the contents of location N to the accumulator value (leaving N's contents unchanged), while add 1 means to add 1 to the accumulator value.

Single-stepping

You can also try a single-step version of the simulator, which does one instruction at a time so you can see what happens more easily.

If you want to see how the simulator works, View / Page Source in Firefox or View / Source in Internet Explorer.

This version has a limit of 1000 instructions by default, to make it easier to prevent infinite loops. The single-step version has no limit.