From 3dc85ae126e2ed1fb31c33c010679ff7cc626959 Mon Sep 17 00:00:00 2001 From: darkzense Date: Sat, 18 Nov 2023 19:25:02 -0600 Subject: [PATCH] clear the stack data in every execution --- system/cpu/execution_unit.ts | 3 ++- system/instructions/stack.ts | 6 ++++-- system/memory/data.ts | 14 +++++++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/system/cpu/execution_unit.ts b/system/cpu/execution_unit.ts index 1fbf001..bd808c1 100644 --- a/system/cpu/execution_unit.ts +++ b/system/cpu/execution_unit.ts @@ -1,5 +1,5 @@ import cpu from "./components.js"; -import { processInfo } from "../memory/data.js"; +import { clearStackData, processInfo } from "../memory/data.js"; import { decodeInstruction } from "../assembler.js"; import { instructionSet } from "./arch.js"; import { Instruction, Executable } from "./interface.js"; @@ -57,6 +57,7 @@ function resetRegisters(): void { } resetSpOffset(); + clearStackData(); } function execute(instruction: Instruction): void { diff --git a/system/instructions/stack.ts b/system/instructions/stack.ts index 2af6e0d..b9ce53d 100644 --- a/system/instructions/stack.ts +++ b/system/instructions/stack.ts @@ -40,7 +40,9 @@ export class Pop implements Executable { const topOfStack = getDataByAddress("stack-data", cpu.stackPointer)!; if (!topOfStack.value) { - throw new ReferenceError("There is no data at the address of the stack pointer."); + throw new ReferenceError( + "There is no data at the address of the stack pointer.", + ); } let nextStackPointer = cpu.stackPointer.parseHex(); @@ -56,7 +58,7 @@ export class Pop implements Executable { cpu.MAR = hexOperand; const actualData = getDataByAddress("main-data", hexOperand)!; // cpu.controlUnit = "IR(5-16)out, MARin, READ"; - + cpu.MDR = (+topOfStack.value).asHex16(); cpu.controlUnit = "SPout, MDRin, WRITE"; actualData.value = topOfStack.value; diff --git a/system/memory/data.ts b/system/memory/data.ts index a054844..0c01b8a 100644 --- a/system/memory/data.ts +++ b/system/memory/data.ts @@ -70,4 +70,16 @@ function getDataByVariable(tbodyId: string, variable: string) { return getDataCell(tbodyId, VAR_COLUMN, variable); } -export { getDataByAddress, getDataByVariable, processInfo }; +function clearStackData() { + const stackTbody = ( + document.getElementById("stack-data") + ); + + for (let row of stackTbody.rows) { + const inputCells = row.getElementsByTagName("input"); + inputCells[1].value = ""; // Variable + inputCells[2].value = ""; // Value + } +} + +export { getDataByAddress, getDataByVariable, clearStackData, processInfo };