Print memory tables in hex

This commit is contained in:
n loewen 2023-08-01 12:57:30 +01:00
parent fa3ade15dd
commit e75049551f
1 changed files with 4 additions and 5 deletions

View File

@ -3,13 +3,12 @@ exports.printTable = (x) => {
console.log(`│ addr │ op │ arg │`); console.log(`│ addr │ op │ arg │`);
console.log(`├────────┼────────┼────────┤`); console.log(`├────────┼────────┼────────┤`);
for (let i = 0; i < x.length; i += 2) { for (let i = 0; i < x.length; i += 2) {
console.log(`${leftPadNum(i)}${leftPadNum(x[i])}${leftPadNum(x[i+1])}`); console.log(`${num2hex(i)}${num2hex(x[i])}${num2hex(x[i+1])}`);
if (((i + 2) % 8) === 0) { if (((i + 2) % 8) === 0) {
console.log(`│ │ │ │`); console.log(`│ │ │ │`);
} }
} }
console.log(`└────────┴────────┴────────┘`); console.log(`└────────┴────────┴────────┘`);
function leftPadNum(n) {
return n.toString().padStart(2, "0")
}
} }
const num2hex = (num) => num.toString(16).toUpperCase().padStart(2, "0");