diff options
author | sanine-a <sanine.not@pm.me> | 2023-05-23 11:52:02 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2023-05-23 11:52:02 -0500 |
commit | d9dcab1271568f1c4bf70e97b707fb8cf42e10fd (patch) | |
tree | 10b1d24e0db7e25a26a95bdaacd1219e3af5e64f /src/vm/instruction.test.js | |
parent | 2880c1565102d8a969846c5e68300ced88066943 (diff) |
fix core boundary wrapping
Diffstat (limited to 'src/vm/instruction.test.js')
-rw-r--r-- | src/vm/instruction.test.js | 46 |
1 files changed, 45 insertions, 1 deletions
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]); +}); |