From d9dcab1271568f1c4bf70e97b707fb8cf42e10fd Mon Sep 17 00:00:00 2001 From: sanine-a Date: Tue, 23 May 2023 11:52:02 -0500 Subject: fix core boundary wrapping --- src/vm/instruction.test.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'src/vm/instruction.test.js') diff --git a/src/vm/instruction.test.js b/src/vm/instruction.test.js index a93a3b0..8efa47f 100644 --- a/src/vm/instruction.test.js +++ b/src/vm/instruction.test.js @@ -1,7 +1,11 @@ 'use strict'; const { Core } = require('./core.js'); -const { DAT, MOV, ADD, SUB, CMP, SLT } = require('./instruction.js'); +const { + DAT, + MOV, ADD, SUB, CMP, SLT, + JMP, +} = require('./instruction.js'); const CORESIZE = 8000; @@ -109,6 +113,33 @@ test('MOV correctly handles predecrement indirection', () => { }); +test('MOV correctly handles core boundaries', () => { + const core = new Core(CORESIZE); + const pc = CORESIZE-1; + core.data[pc] = { + opcode: 'MOV', + a: { mode: 'immediate', value: 100 }, + b: { mode: 'predecrement', value: 2 }, + }; + const ins = core.data[pc]; + expect(core.data[0].opcode).toBe('DAT'); + expect(MOV(core, pc, ins)).toEqual([0]); + expect(core.data[1]).toEqual({ + opcode: 'DAT', + a: { mode: 'immediate', value: 0 }, + b: { mode: 'immediate', value: -1 }, + }); + + expect(core.data[0]).toEqual({ + opcode: 'DAT', + a: { mode: 'immediate', value: 0 }, + b: { mode: 'immediate', value: 100 }, + }); + +}); + + + test('ADD correctly adds two full instructions', () => { const core = new Core(CORESIZE); const pc = 20; @@ -347,3 +378,16 @@ test('SLT properly compares B-fields', () => { expect(SLT(core, pc, ins)).toEqual([pc+2]); }); + +test('JMP correctly jumps', () => { + const core = new Core(CORESIZE); + const pc = 2; + core.data[pc] = { + opcode: 'JMP', + a: { mode: 'direct', value: -3 }, + b: { mode: 'direct', value: 0 }, + }; + const ins = core.data[pc]; + + expect(JMP(core, pc, ins)).toEqual([CORESIZE-1]); +}); -- cgit v1.2.1