diff --git a/assembler.js b/assembler.js index c765f01..874655c 100644 --- a/assembler.js +++ b/assembler.js @@ -38,8 +38,11 @@ const mnemonics2opcodes = { function decodeInstructions(line) { let lines = line.split(/\n/); // returns an array of lines - let machineCode = new Array(INITIAL_IP_ADDRESS).fill(0); - machineCode[POINTER_TO_START_OF_DISPLAY_MEM] = START_OF_DISPLAY_MEM; + //let machineCode = new Array(INITIAL_IP_ADDRESS).fill(0); + let machineCode = new Array(256).fill(0); + dbgExec(2, () => logMemory(new Uint8Array(machineCode))); + machineCode[POINTER_TO_DISPLAY] = DISPLAY_ADDR; + machineCode[POINTER_TO_KEYPAD] = KEYPAD_ADDR; let labels = {}; let constants = {}; @@ -174,8 +177,9 @@ function decodeInstructions(line) { // DECODE! const op = mnemonics2opcodes[opName][addressingMode]; - machineCode.push(op); - machineCode.push(arg_num); + machineCode[IP] = op; + machineCode[IP+1] = arg_num; + dbg(3, `IP: $${num2hex(IP)}, new code: $${num2hex(op)} $${num2hex(arg_num)}`); IP += 2; dbgGroupEnd(1, 'Input line'); @@ -198,10 +202,6 @@ function decodeInstructions(line) { } } - // Add an END at the end - machineCode.push('0'); - machineCode.push('0'); - return new Uint8Array(machineCode); }