diff --git a/cpu.js b/cpu.js index 832f580..e5e5c2b 100644 --- a/cpu.js +++ b/cpu.js @@ -321,12 +321,6 @@ function startCPU(code) { * @param {Boolean} [debug] - Print machine status and the line of code being executed **/ async function stepCPU(debugInfo, debug = false, prettyPrintDisplay = false) { - if (CYCLE_LIMIT) { // Temporary limit as a lazy way to halt infinite loops - if (CPU.cycleCounter > CYCLE_LIMIT) { - console.warn('HALTING - reached cycle limit'); - CPU.running = false; - } - } if (CPU.IP >= CPU.memory.length) { console.error('HALTING - IP greater than memory size'); CPU.running = false; @@ -347,6 +341,12 @@ async function stepCPU(debugInfo, debug = false, prettyPrintDisplay = false) { CPU.cycleCounter += 1; } logCPUState(debugInfo, debug, prettyPrintDisplay); + if (CYCLE_LIMIT) { // Temporary limit as a lazy way to halt infinite loops + if (CPU.cycleCounter >= CYCLE_LIMIT) { + console.warn(' HALTING - reached cycle limit'); + CPU.running = false; + } + } if (!CPU.running) process.exit(); }