summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/vm/core.js4
-rw-r--r--src/vm/instruction.js8
-rw-r--r--src/vm/instruction.test.js10
3 files changed, 15 insertions, 7 deletions
diff --git a/src/vm/core.js b/src/vm/core.js
index 9b0fe77..4fdd0a0 100644
--- a/src/vm/core.js
+++ b/src/vm/core.js
@@ -37,13 +37,13 @@ class Core {
case AddrMode.Indirect: {
let loc = this.normalize(pc, address.value);
let b = this.data[loc].b.value;
- return this.normalize(loc, b);
+ return this.normalize(pc, b);
}
case AddrMode.Predecrement: {
let loc = this.normalize(pc, address.value);
this.data[loc].b.value -= 1;
let b = this.data[loc].b.value;
- return this.normalize(loc, b);
+ return this.normalize(pc, b);
}
default:
throw `Invalid addressing mode "${address.mode}"`;
diff --git a/src/vm/instruction.js b/src/vm/instruction.js
index c235b9a..dcf9a51 100644
--- a/src/vm/instruction.js
+++ b/src/vm/instruction.js
@@ -162,3 +162,11 @@ exports.DJN = function(core, pc, ins) {
return [core.normalize(pc, 1)];
}
}
+
+
+exports.SPL = function(core, pc, ins) {
+ return [
+ core.normalize(pc, 1),
+ core.getLocation(pc, ins.a),
+ ];
+}
diff --git a/src/vm/instruction.test.js b/src/vm/instruction.test.js
index 82d9819..cf23404 100644
--- a/src/vm/instruction.test.js
+++ b/src/vm/instruction.test.js
@@ -76,7 +76,7 @@ test('MOV correctly handles indirection', () => {
b: { mode: 'immediate', value: 2 },
});
- expect(core.data[pc+1]).toEqual({
+ expect(core.data[pc+2]).toEqual({
opcode: 'DAT',
a: { mode: 'immediate', value: 0 },
b: { mode: 'immediate', value: 100 },
@@ -93,18 +93,18 @@ test('MOV correctly handles predecrement indirection', () => {
core.data[pc] = {
opcode: 'MOV',
a: { mode: 'immediate', value: 100 },
- b: { mode: 'predecrement', value: -1 },
+ b: { mode: 'predecrement', value: 1 },
};
const ins = core.data[pc];
expect(core.data[pc+1].opcode).toBe('DAT');
expect(MOV(core, pc, ins)).toEqual([pc+1]);
- expect(core.data[pc-1]).toEqual({
+ expect(core.data[pc+1]).toEqual({
opcode: 'DAT',
a: { mode: 'immediate', value: 0 },
b: { mode: 'immediate', value: -1 },
});
- expect(core.data[pc-2]).toEqual({
+ expect(core.data[pc-1]).toEqual({
opcode: 'DAT',
a: { mode: 'immediate', value: 0 },
b: { mode: 'immediate', value: 100 },
@@ -130,7 +130,7 @@ test('MOV correctly handles core boundaries', () => {
b: { mode: 'immediate', value: -1 },
});
- expect(core.data[0]).toEqual({
+ expect(core.data[CORESIZE-2]).toEqual({
opcode: 'DAT',
a: { mode: 'immediate', value: 0 },
b: { mode: 'immediate', value: 100 },