Skip to content

Commit 20e4dc3

Browse files
committed
memory initialization
1 parent 1d3532f commit 20e4dc3

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

demo/pipelined/pipeline-visualizer.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,27 @@ document.addEventListener("DOMContentLoaded", function () {
972972
}
973973
});
974974

975+
function initializeMemory() {
976+
// If pipelineData doesn't exist yet, wait for it to load
977+
if (typeof pipelineData === "undefined" || !pipelineData.cycles || pipelineData.cycles.length === 0) {
978+
setTimeout(initializeMemory, 100);
979+
return;
980+
}
981+
982+
// Set initial memory values for all cycles
983+
for (let i = 0; i < pipelineData.cycles.length; i++) {
984+
// Set memory[0] = 10 for Fibonacci n value
985+
pipelineData.cycles[i]["mem_0"] = 10;
986+
}
987+
988+
// Update display to show initial memory values
989+
if (currentCycle === 0) {
990+
updateMemory(pipelineData.cycles[0]);
991+
}
992+
}
975993
// Initialize
976994
drawPipelinedCPU();
977995
updateDisplay();
996+
initializeMemory();
997+
978998
});

pipelined/visualization/pipeline-visualizer.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,11 @@ document.addEventListener("DOMContentLoaded", function () {
787787
const regValue =
788788
cycleData[regName] !== undefined ? cycleData[regName] : 0;
789789

790-
const writtenThisCycle =
791-
cycleData.reg_write && cycleData.reg_write_rd === i && i !== 0; // x0 can't change
790+
const writtenThisCycle =
791+
cycleData.mem_wb_reg_write === true && // using wb here
792+
cycleData.mem_wb_rd !== undefined && // Use WB stage destination
793+
cycleData.mem_wb_rd === i &&
794+
i !== 0;
792795

793796
const markedAsChanged = cycleData[`${regName}_changed`] === true;
794797

@@ -969,7 +972,27 @@ document.addEventListener("DOMContentLoaded", function () {
969972
}
970973
});
971974

975+
function initializeMemory() {
976+
// If pipelineData doesn't exist yet, wait for it to load
977+
if (typeof pipelineData === "undefined" || !pipelineData.cycles || pipelineData.cycles.length === 0) {
978+
setTimeout(initializeMemory, 100);
979+
return;
980+
}
981+
982+
// Set initial memory values for all cycles
983+
for (let i = 0; i < pipelineData.cycles.length; i++) {
984+
// Set memory[0] = 10 for Fibonacci n value
985+
pipelineData.cycles[i]["mem_0"] = 10;
986+
}
987+
988+
// Update display to show initial memory values
989+
if (currentCycle === 0) {
990+
updateMemory(pipelineData.cycles[0]);
991+
}
992+
}
972993
// Initialize
973994
drawPipelinedCPU();
974995
updateDisplay();
996+
initializeMemory();
997+
975998
});

0 commit comments

Comments
 (0)