From 6a4548df5e405adb080320080c67b7054b75bcaf Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 22 May 2023 23:56:50 -0500 Subject: implement MOV --- src/parser/grammar.jison | 2 -- src/vm/core.js | 4 ++-- src/vm/instruction.js | 15 +++++++++++++++ src/vm/instruction.test.js | 38 +++++++++++++++++++++++++++++++++++++- 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/parser/grammar.jison b/src/parser/grammar.jison index 4f4a433..c8de8a2 100644 --- a/src/parser/grammar.jison +++ b/src/parser/grammar.jison @@ -203,5 +203,3 @@ e label : LABEL { $$ = yytext; } ; - - diff --git a/src/vm/core.js b/src/vm/core.js index 399cfc6..074e156 100644 --- a/src/vm/core.js +++ b/src/vm/core.js @@ -11,8 +11,8 @@ class Core { for (let i=0; i { 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