From 4d5377870ee554036ac9aab570ac2bc809fc88bd Mon Sep 17 00:00:00 2001 From: sanine-a Date: Tue, 23 May 2023 12:33:39 -0500 Subject: implement DJN --- src/vm/instruction.test.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/vm/instruction.test.js') diff --git a/src/vm/instruction.test.js b/src/vm/instruction.test.js index 2880da7..82d9819 100644 --- a/src/vm/instruction.test.js +++ b/src/vm/instruction.test.js @@ -466,3 +466,43 @@ test('JMN correctly jumps in immediate mode', () => { expect(JMN(core, pc, ins)).toEqual([CORESIZE-1]); }); + +test('DJN correctly jumps in non-immediate mode', () => { + const core = new Core(CORESIZE); + const pc = 2; + core.data[pc] = { + opcode: 'DJN', + a: { mode: 'direct', value: -3 }, + b: { mode: 'direct', value: 1 }, + }; + core.data[pc+1] = { + opcode: 'DJN', + a: { mode: 'direct', value: -3 }, + b: { mode: 'direct', value: 1 }, + }; + const ins = core.data[pc]; + + expect(DJN(core, pc, ins)).toEqual([pc+1]); + expect(core.data[pc+1].b.value).toBe(0); + expect(DJN(core, pc, ins)).toEqual([CORESIZE-1]); + expect(core.data[pc+1].b.value).toBe(-1); +}); + + +test('DJN correctly jumps in immediate mode', () => { + const core = new Core(CORESIZE); + const pc = 2; + core.data[pc] = { + opcode: 'DJN', + a: { mode: 'direct', value: -3 }, + b: { mode: 'immediate', value: 1 }, + }; + const ins = core.data[pc]; + + expect(DJN(core, pc, ins)).toEqual([pc+1]); + expect(core.data[pc].b.value).toBe(0); + expect(DJN(core, pc, ins)).toEqual([CORESIZE-1]); + expect(core.data[pc].b.value).toBe(-1); +}); + + -- cgit v1.2.1