From 6a4548df5e405adb080320080c67b7054b75bcaf Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 22 May 2023 23:56:50 -0500 Subject: implement MOV --- src/vm/instruction.test.js | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 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 5dc7eea..3535b76 100644 --- a/src/vm/instruction.test.js +++ b/src/vm/instruction.test.js @@ -1,7 +1,7 @@ 'use strict'; const { Core } = require('./core.js'); -const { DAT } = require('./instruction.js'); +const { DAT, MOV } = require('./instruction.js'); const CORESIZE = 8000; @@ -13,3 +13,39 @@ test('DAT does nothing and kills the program', () => { const ins = core.data[pc]; expect(DAT(core, pc, ins)).toEqual([]); }); + + +test('MOV correctly moves a full instruction', () => { + const core = new Core(CORESIZE); + const pc = 20; + core.data[pc] = { + opcode: 'MOV', + a: { mode: 'direct', value: 0 }, + b: { mode: 'direct', value: 1 }, + }; + const ins = core.data[pc]; + expect(core.data[pc+1].opcode).toBe('DAT'); + expect(MOV(core, pc, ins)).toEqual([pc+1]); + expect(core.data[pc]).toEqual(core.data[pc+1]); + expect(core.data[pc+1].opcode).toBe('MOV'); +}); + + +test('MOV correctly moves a B-field', () => { + const core = new Core(CORESIZE); + const pc = 20; + core.data[pc] = { + opcode: 'MOV', + a: { mode: 'immediate', value: 100 }, + b: { mode: 'direct', value: 1 }, + }; + const ins = core.data[pc]; + expect(core.data[pc+1].opcode).toBe('DAT'); + expect(MOV(core, pc, ins)).toEqual([pc+1]); + expect(core.data[pc+1]).toEqual({ + opcode: 'DAT', + a: { mode: 'immediate', value: 0 }, + b: { mode: 'immediate', value: 100 }, + }); + +}); -- cgit v1.2.1