From 86793f0afd74092be507325a40d85bc62bd47597 Mon Sep 17 00:00:00 2001 From: sanine-a Date: Tue, 23 May 2023 12:26:50 -0500 Subject: implement JMN --- src/vm/instruction.test.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/vm/instruction.test.js') 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]); +}); + -- cgit v1.2.1