Code for the littler Buttons the Computer used in the Turing Machine portion of the book.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import { ButtonMachine } from '../src/buttons.js';
|
|
|
|
|
|
|
|
let code = [
|
|
|
|
['PUSH', -10], // start at -10
|
|
|
|
['PUSH', 1], // increment by 1
|
|
|
|
['ADD'],
|
|
|
|
['POKE', 1], // put it in ram, IX++
|
|
|
|
['JNZ', 1], // the previous test fails so it jumps to loop again
|
|
|
|
['STOR', 'IX'],
|
|
|
|
['POP'],
|
|
|
|
['PEEK', 1],
|
|
|
|
['JNZ', 6],
|
|
|
|
];
|
|
|
|
|
|
|
|
let machine = new ButtonMachine(code);
|
|
|
|
|
|
|
|
const ops = ButtonMachine.operations();
|
|
|
|
const registers = machine.register_names();
|
|
|
|
|
|
|
|
machine.run();
|
|
|
|
|
|
|
|
console.log("STACK TOP", machine.stack_top);
|
|
|
|
console.log("REGISTERS", registers);
|
|
|
|
console.log("STACK", machine.stack);
|
|
|
|
console.log("RAM", machine.ram);
|