summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2023-05-23 12:26:50 -0500
committersanine-a <sanine.not@pm.me>2023-05-23 12:26:50 -0500
commit86793f0afd74092be507325a40d85bc62bd47597 (patch)
tree98d7b2cbf32e45032dd7cfbf524d7b4d875dbcc1 /src
parent70c42ab50d6eb78d0cc825d2d7f0b318398819ba (diff)
implement JMN
Diffstat (limited to 'src')
-rw-r--r--src/vm/instruction.js18
-rw-r--r--src/vm/instruction.test.js38
2 files changed, 56 insertions, 0 deletions
diff --git a/src/vm/instruction.js b/src/vm/instruction.js
index 2afd3f7..f323f84 100644
--- a/src/vm/instruction.js
+++ b/src/vm/instruction.js
@@ -124,3 +124,21 @@ exports.JMZ = function(core, pc, ins) {
return [core.normalize(pc, 1)];
}
}
+
+
+exports.JMN = function(core, pc, ins) {
+ let test;
+
+ if (ins.b.mode === AddrMode.Immediate) {
+ test = (ins.b.value !== 0);
+ } else {
+ const src = core.getValue(pc, ins.b);
+ test = (src.b.value !== 0);
+ }
+
+ if (test) {
+ return [core.getLocation(pc, ins.a)];
+ } else {
+ return [core.normalize(pc, 1)];
+ }
+}
diff --git a/src/vm/instruction.test.js b/src/vm/instruction.test.js
index 6175ab2..2880da7 100644
--- a/src/vm/instruction.test.js
+++ b/src/vm/instruction.test.js
@@ -428,3 +428,41 @@ test('JMZ correctly jumps in immediate mode', () => {
core.data[pc].b.value = 0;
expect(JMZ(core, pc, ins)).toEqual([CORESIZE-1]);
});
+
+
+test('JMN correctly jumps in non-immediate mode', () => {
+ const core = new Core(CORESIZE);
+ const pc = 2;
+ core.data[pc] = {
+ opcode: 'JMN',
+ a: { mode: 'direct', value: -3 },
+ b: { mode: 'direct', value: 1 },
+ };
+ core.data[pc+1] = {
+ opcode: 'JMN',
+ a: { mode: 'direct', value: -3 },
+ b: { mode: 'direct', value: 0 },
+ };
+ const ins = core.data[pc];
+
+ expect(JMN(core, pc, ins)).toEqual([pc+1]);
+ core.data[pc+1].b.value = 1;
+ expect(JMN(core, pc, ins)).toEqual([CORESIZE-1]);
+});
+
+
+test('JMN correctly jumps in immediate mode', () => {
+ const core = new Core(CORESIZE);
+ const pc = 2;
+ core.data[pc] = {
+ opcode: 'JMN',
+ a: { mode: 'direct', value: -3 },
+ b: { mode: 'immediate', value: 0 },
+ };
+ const ins = core.data[pc];
+
+ expect(JMN(core, pc, ins)).toEqual([pc+1]);
+ core.data[pc].b.value = 1;
+ expect(JMN(core, pc, ins)).toEqual([CORESIZE-1]);
+});
+