const logMemory = (mem, start=0, end=mem.length) => { // This function can only handle // an even number of array entries if ((start % 2) === 1) { start -= 1; } if ((end % 2) === 1) { end += 1; } mem = mem.slice(start, end); console.log(`┌────────┬────────┬────────┐`); console.log(`│ addr │ op │ arg │`); console.log(`├────────┼────────┼────────┤`); //for (let i = 0; i < mem.length; i += 2) { for (let i = start; i < mem.length; i +=2) { console.log(`│ ${num2hex(i)} │ ${num2hex(mem[i])} │ ${num2hex(mem[i+1])} │`); // Add a blank row every 4 lines: if (((i + 2) % 8) === 0) { if ((i < (mem.length - 2))) { console.log(`│ │ │ │`); } } } console.log(`└────────┴────────┴────────┘`); } const logRunningHeader = () => { console.log(); let time = new Date(); console.log( `┌─────────────────────┐`); console.log( `│ Running at ${time.toLocaleTimeString('en-GB')} │` ); console.log( `└─────────────────────┘`); } const num2hex = (num) => num.toString(16).toUpperCase().padStart(2, "0"); const hex2num = (hex) => parseInt(hex, 16); module.exports = { "logMemory": logMemory, "logRunningHeader": logRunningHeader, "num2hex": num2hex, "hex2num": hex2num, }