logging - Fix memory printing function so that it works for arrays that start or end on odd address numbers
This commit is contained in:
parent
902b218547
commit
dea1a445f6
|
|
@ -41,6 +41,7 @@ For extended commentary, see [issues](issues.md).
|
|||
|
||||
## Closed
|
||||
|
||||
- 2023-08-26 - [fix] (logging) - 'undefined operand' situation is caused by assembling to an initial IP of $1C, which is an odd number
|
||||
- (assembler) Pass asm line thru to cpu to print when debugging
|
||||
|
||||
|
||||
|
|
|
|||
26
logging.js
26
logging.js
|
|
@ -6,26 +6,28 @@
|
|||
* @param {number} [end] - An end-index, in decimal
|
||||
**/
|
||||
const logMemory = (mem, start=0, end=mem.length) => {
|
||||
mem = mem.slice(start, end);
|
||||
console.log(`┌────────┬────────┬─────────┐`);
|
||||
console.log(`│ addr │ opcode │ operand │`);
|
||||
console.log(`├────────┼────────┼─────────┤`);
|
||||
let top1 = `┌─────────┬────────┬─────────┐`;
|
||||
let top2 = `│ addrs │ opcode │ operand │`;
|
||||
let top3 = `├─────────┼────────┼─────────┤`;
|
||||
let blnk = `│ │ │ │`;
|
||||
let bot1 = `└─────────┴────────┴─────────┘`;
|
||||
console.log(`${top1}\n${top2}\n${top3}`);
|
||||
for (let i = start; i < mem.length; i +=2) {
|
||||
let operand = mem[i+1];
|
||||
if (typeof operand === 'undefined') {
|
||||
console.warn(' operand undefined');
|
||||
operand = -1;
|
||||
console.log(` ${num2hex(i)} ${num2hex(i+1)} │ ${num2hex(mem[i])} │ │`);
|
||||
} else {
|
||||
console.log(`│ ${num2hex(i)} ${num2hex(i+1)} │ ${num2hex(mem[i])} │ ${num2hex(operand)} │`);
|
||||
}
|
||||
console.log(`│ ${num2hex(i)} │ ${num2hex(mem[i])} │ ${num2hex(operand)} │`);
|
||||
|
||||
// Add a blank row every 4 lines:
|
||||
if (((i + 2) % 8) === 0) {
|
||||
if ((i < (mem.length - 2))) {
|
||||
console.log(`│ │ │ │`);
|
||||
}
|
||||
let rowNum = i - start + 2; // Not actually the row number...
|
||||
if ((rowNum % 8 === 0)
|
||||
&& (i < (mem.length - 2))) {
|
||||
console.log(blnk);
|
||||
}
|
||||
}
|
||||
console.log(`└────────┴────────┴─────────┘`);
|
||||
console.log(bot1);
|
||||
}
|
||||
|
||||
const logRunningHeader = () => {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ const fs = require('fs');
|
|||
const assembler = require('./assembler.js');
|
||||
const { logMemory, num2hex, num2bin } = require('./logging.js');
|
||||
const { machine } = require('os');
|
||||
const machineConfig = require('./machine.config.js');
|
||||
|
||||
const mode = process.argv[2];
|
||||
const filename = process.argv[3];
|
||||
|
|
@ -19,7 +20,7 @@ if (mode === "debug") {
|
|||
assembler_output = assembler.assemble(inputFile_str, true);
|
||||
console.log('');
|
||||
console.group("Machine code output");
|
||||
logMemory(assembler_output.machineCode);
|
||||
logMemory(assembler_output.machineCode, machineConfig.INITIAL_IP_ADDRESS);
|
||||
console.groupEnd();
|
||||
} else {
|
||||
assembler_output = assembler.assemble(inputFile_str);
|
||||
|
|
|
|||
Loading…
Reference in New Issue