Allow an infinite CYCLE_LIMIT
This commit is contained in:
parent
0d050aa968
commit
daf3793f90
|
|
@ -14,5 +14,5 @@ let machineCode = assembler.assemble(inputFile_str);
|
|||
// printMemory.printTable(machineCode);
|
||||
// console.groupEnd('Machine code output');
|
||||
|
||||
//computer.debugProgram(machineCode);
|
||||
computer.displayProgram(machineCode);
|
||||
computer.debugProgram(machineCode);
|
||||
//computer.displayProgram(machineCode);
|
||||
20
simulator.js
20
simulator.js
|
|
@ -175,21 +175,24 @@ function stepCPU() {
|
|||
}
|
||||
|
||||
exports.debugProgram = (code) => {
|
||||
CPU.loadMemory(code);
|
||||
const initialMemory = JSON.parse(JSON.stringify(CPU.memory)); // Hack to make a copy-by-value -- https://stackoverflow.com/questions/18829099/copy-a-variables-value-into-another
|
||||
console.log();
|
||||
let time = new Date();
|
||||
console.log( `┌─────────────────────┐`);
|
||||
// Running at 11:48:15 AM
|
||||
console.log( `│ Running at ${time.toLocaleTimeString('en-GB')} │` );
|
||||
console.log( `└─────────────────────┘`);
|
||||
logCPUState();
|
||||
|
||||
CPU.loadMemory(code);
|
||||
const initialMemory = JSON.parse(JSON.stringify(CPU.memory)); // Hack to make a copy-by-value -- https://stackoverflow.com/questions/18829099/copy-a-variables-value-into-another
|
||||
logCPUState();
|
||||
CPU.running = true;
|
||||
for (let i = 0; i < CYCLE_LIMIT; i++) { // FIXME: temporary limit as a lazy way to halt infinite loops
|
||||
let step = 0;
|
||||
while (true) {
|
||||
step = step + 1;
|
||||
// FIXME: temporary limit as a lazy way to halt infinite loops:
|
||||
if (CYCLE_LIMIT && (step > CYCLE_LIMIT)) { break; }
|
||||
if (!CPU.running) break;
|
||||
if (CPU.IP >= CPU.memory.length) break;
|
||||
stepCPU();
|
||||
console.group('Display')
|
||||
display.printDisplay(CPU.memory);
|
||||
console.log();
|
||||
|
|
@ -201,7 +204,12 @@ exports.displayProgram = async (code) => {
|
|||
CPU.loadMemory(code);
|
||||
const initialMemory = JSON.parse(JSON.stringify(CPU.memory)); // Hack to make a copy-by-value -- https://stackoverflow.com/questions/18829099/copy-a-variables-value-into-another
|
||||
CPU.running = true;
|
||||
for (let i = 0; i < CYCLE_LIMIT; i++) { // FIXME: temporary limit as a lazy way to halt infinite loops
|
||||
|
||||
let step = 0;
|
||||
while (true) {
|
||||
step = step + 1;
|
||||
// FIXME: temporary limit as a lazy way to halt infinite loops:
|
||||
if (CYCLE_LIMIT && (step > CYCLE_LIMIT)) { break; }
|
||||
if (!CPU.running) break;
|
||||
if (CPU.IP >= CPU.memory.length) break;
|
||||
stepCPU();
|
||||
|
|
|
|||
Loading…
Reference in New Issue