two-bit/machine.txt

51 lines
1.2 KiB
Plaintext

00 Add ram[register] and ram[register + 1] and store in ram[register + 2]
01 Load ram[register] into register
10 Jump to ram[register + 1] if ram[register] > 0
11 Increment register
Using a 4-bit word size and 16 nibbles of ram:
Program:
Increment Count to 10, then stop
Clock speed is 1Hz
0x0 0x8
0x1 0q03
0x2 0q30
0x3 0q33
0x4 0q23
0x5 0q20
0x6 0x0
0x7 0x0
0x8 0x0
0x9 0x1
0xA 0x0
0xB 0x6
0xC 0x0
0xD 0x1
0xE 0x5
0xF 0x0
let counterMachine
counterMachine = require('./counter-machine').default()
function step() {
counterMachine.tick()
logMachineState()
}
function logMachineState() {
const programCounter = counterMachine.programCounter().value()
const instructionCounter = counterMachine.instructionCounter().value()
const nextInstruction = counterMachine.ram.read(programCounter).subword(instructionCounter.toNumber() * 2, 2)
console.log("Sum", counterMachine.ram.read(wordFromNumber(0xA)).toString())
console.log("ProgramCounter", programCounter.toString())
console.log("InstructionCounter", instructionCounter.toString())
console.log("Register", counterMachine.addressRegister.value().toString())
console.log("Next instructioq20", nextInstruction.toString())
}