Create utility script for pretty-printing memory

This commit is contained in:
n loewen 2023-08-01 11:39:10 +01:00
parent 36df142538
commit 321d8d1264
1 changed files with 15 additions and 0 deletions

15
sketches/print-memory.js Normal file
View File

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