Toy Machine Simulator

     Program:                         Output:
              

                    Accumulator:  

    

Guess a number!

This page includes a sample program demonstrating a simple guess a number game. Click run and then enter a number, look in the output box and you'll see your guess and one of three numbers following it:

Notes: This is known to work in FireFox, and does NOT work in Chrome up to v69. To implement this game a RAND instruction was added to the simulator (see Syntax section).

Syntax reminder

     get       get a number from keyboard into accumulator
     print     print contents of accumulator
     load Val  load accumulator with Val (Val unchanged)
     store M   store contents of accumulator into memory location called M (accumulator unchanged)
     add Val   add Val to contents of accumulator (Val unchanged)
     sub Val   subtract Val from contents of accumulator (Val unchanged)
     goto L    go to instruction labeled L
     ifpos L   go to instruction labeled L if accumulator is >= zero
     ifzero L  go to instruction labeled L if accumulator is zero
     stop      stop running
     rand      put random number between 0 and 100 in accumulator
   M Num       before program runs, set this memory location (called M) to numeric value Num
If Val is a name like Sum, it refers to a labeled memory location. If Val is a number like 17, that value is used directly. So add Sum means to add the contents of the memory location named Sum to the accumulator value (leaving Sum's contents unchanged), while add 1 means to add 1 to the accumulator value.

If you want to see how the simulator works, Tools / Web Developer / Page Source in Firefox, Customize / Tools / View source in Chrome, or Developer / View Source in Safari.

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.