aboutsummaryrefslogtreecommitdiffgithub
diff options
context:
space:
mode:
authorAustin Adams <git@austinjadams.com>2019-02-04 00:11:04 -0500
committerAustin Adams <git@austinjadams.com>2019-02-04 00:11:04 -0500
commit9e1c75f3910a58733c7394421fca15ff591076f3 (patch)
tree415a028e7bb6e01f6fe0cb58f9231891b9283e45
parentf1c3f91ddf6e2a6d36efbfa9774ee1e290e43347 (diff)
downloadnovice-9e1c75f3910a58733c7394421fca15ff591076f3.tar.gz
novice-9e1c75f3910a58733c7394421fca15ff591076f3.tar.xz
Display printable ascii characters in disassembly
-rw-r--r--novice/simulator/cli-debugger.test.ts8
-rw-r--r--novice/simulator/debugger.test.ts2
-rw-r--r--novice/simulator/debugger.ts11
3 files changed, 15 insertions, 6 deletions
diff --git a/novice/simulator/cli-debugger.test.ts b/novice/simulator/cli-debugger.test.ts
index c96e556..e4a24f7 100644
--- a/novice/simulator/cli-debugger.test.ts
+++ b/novice/simulator/cli-debugger.test.ts
@@ -355,8 +355,8 @@ describe('cli debugger', () => {
expect(stdoutActual).toMatch(/0x3000[^]+^==> 0x3000: 0xe002 -8190 lea r0, 2 $/m);
expect(stdoutActual).toMatch(/0x3001[^]+^ 0x3001: 0xf022 -4062 puts $/m);
expect(stdoutActual).toMatch(/0x3002[^]+^ 0x3002: 0xf025 -4059 halt $/m);
- expect(stdoutActual).toMatch(/0x3003[^]+^ 0x3003: 0x0068 104 $/m);
- expect(stdoutActual).toMatch(/0x3004[^]+^ 0x3004: 0x0065 101 $/m);
+ expect(stdoutActual).toMatch(/0x3003[^]+^ 0x3003: 0x0068 104 'h' $/m);
+ expect(stdoutActual).toMatch(/0x3004[^]+^ 0x3004: 0x0065 101 'e' $/m);
});
});
@@ -382,8 +382,8 @@ describe('cli debugger', () => {
return dbg.run().then(() => {
expect(stdoutActual).toMatch(/0x3001[^]+^0x3001: 0xf022 -4062 puts $/m);
expect(stdoutActual).toMatch(/0x3002[^]+^0x3002: 0xf025 -4059 halt $/m);
- expect(stdoutActual).toMatch(/0x3003[^]+^0x3003: 0x0068 104 $/m);
- expect(stdoutActual).toMatch(/0x3004[^]+^0x3004: 0x0065 101 $/m);
+ expect(stdoutActual).toMatch(/0x3003[^]+^0x3003: 0x0068 104 'h' $/m);
+ expect(stdoutActual).toMatch(/0x3004[^]+^0x3004: 0x0065 101 'e' $/m);
});
});
diff --git a/novice/simulator/debugger.test.ts b/novice/simulator/debugger.test.ts
index 13261a3..c37b9ed 100644
--- a/novice/simulator/debugger.test.ts
+++ b/novice/simulator/debugger.test.ts
@@ -152,7 +152,7 @@ describe('debugger', () => {
[0x3005, 0x14bf, 5311, 'add r2, r2, -1', []],
[0x3006, 0x0ffc, 4092, 'brnzp loop', []],
[0x3007, 0xf025, -4059, 'halt', []],
- [0x3008, 0x0021, 33, null, ['bang']],
+ [0x3008, 0x0021, 33, "'!'", ['bang']],
[0x3009, 0xd000, -12288, null, []],
[0x300a, 0x0000, 0, 'nop', []],
[0x300b, 0x0000, 0, 'nop', []],
diff --git a/novice/simulator/debugger.ts b/novice/simulator/debugger.ts
index 9932eec..ab79b48 100644
--- a/novice/simulator/debugger.ts
+++ b/novice/simulator/debugger.ts
@@ -135,7 +135,16 @@ class Debugger extends Simulator {
const word = this.load(pc);
const sext = sextTo(word, this.isa.mem.word);
const labels = this.labelsForAddr(pc);
- result.push([pc, word, sext, this.disassemble(pc, word), labels]);
+ let disassembled = this.disassemble(pc, word);
+
+ // If cannot disassemble and a printable ascii character,
+ // stick that bad boy in there
+ if (!disassembled && ' '.charCodeAt(0) <= word &&
+ word <= '~'.charCodeAt(0)) {
+ disassembled = `'${String.fromCharCode(word)}'`;
+ }
+
+ result.push([pc, word, sext, disassembled, labels]);
}
return result;