From 91ff26fdeab2e5c0426c92794cd5277fa53825c9 Mon Sep 17 00:00:00 2001 From: n loewen Date: Wed, 2 Aug 2023 10:38:58 +0100 Subject: [PATCH] Move display memory and add a pointer to display memory --- assembler.js | 6 +++++- display.js | 5 ++++- simulator.js | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/assembler.js b/assembler.js index 29e227c..7f6f86e 100644 --- a/assembler.js +++ b/assembler.js @@ -5,7 +5,8 @@ const printMemory = require('./print-memory.js'); // 3 = always print // 4 = silent const DEBUG = 4; -const INITIAL_IP_ADDRESS = 32; +const INITIAL_IP_ADDRESS = 48; +const START_OF_DISPLAY_MEM = 0; const mnemonicsWithOptionalArgs = ['end', 'cfc', 'chp']; const mnemonics2opcodes = { @@ -22,7 +23,10 @@ const mnemonics2opcodes = { function decodeInstructions(str) { let lines = str.split(/\n/); // returns an array of lines + let machineCode = new Array(INITIAL_IP_ADDRESS).fill(0); + machineCode[0] = START_OF_DISPLAY_MEM; + let labels = {}; let IP = INITIAL_IP_ADDRESS; for (let i = 0; i < lines.length; i++) { diff --git a/display.js b/display.js index 0da75e7..0373ac3 100644 --- a/display.js +++ b/display.js @@ -1,5 +1,8 @@ +const START_OF_DISPLAY_MEM = 0; + exports.printDisplay = (mem) => { - for (let i = 0; i < 16; i += 4) { + const disp = START_OF_DISPLAY_MEM; + for (let i = disp; i < disp + 16; i += 4) { console.log(`${pad(mem[i])} ${pad(mem[i+1])} ${pad(mem[i+2])} ${pad(mem[i+3])}`); } } diff --git a/simulator.js b/simulator.js index 4401a2c..868a12c 100644 --- a/simulator.js +++ b/simulator.js @@ -3,7 +3,7 @@ // - instructions are two bytes long: // one byte for the opcode, one for the argument -const INITIAL_IP_ADDRESS = 32; +const INITIAL_IP_ADDRESS = 48; const CYCLE_LIMIT = 128; // max number of times to step the CPU, to stop endless loops const display = require('./display.js');