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.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/vm/instruction.js') diff --git a/src/vm/instruction.js b/src/vm/instruction.js index a79427b..878d20b 100644 --- a/src/vm/instruction.js +++ b/src/vm/instruction.js @@ -20,7 +20,7 @@ exports.MOV = function(core, pc, ins) { core.data[dstLocation] = JSON.parse(JSON.stringify(src)); } - return [pc + 1]; + return [core.normalize(pc, 1)]; } @@ -35,7 +35,7 @@ exports.ADD = function(core, pc, ins) { dst.b.value += src.b.value; } - return [pc + 1]; + return [core.normalize(pc, 1)]; } @@ -50,7 +50,7 @@ exports.SUB = function(core, pc, ins) { dst.b.value -= src.b.value; } - return [pc + 1]; + return [core.normalize(pc, 1)]; } @@ -58,9 +58,9 @@ exports.CMP = function(core, pc, ins) { if (ins.a.mode === AddrMode.Immediate) { const test = core.getValue(pc, ins.b); if (test.b.value === ins.a.value) { - return [pc + 2]; + return [core.normalize(pc, 2)]; } else { - return [pc + 1]; + return [core.normalize(pc, 1)]; } } else { const left = core.getValue(pc, ins.a); @@ -75,9 +75,9 @@ exports.CMP = function(core, pc, ins) { left.b.mode === right.b.mode && left.b.value === right.b.value ) { - return [pc + 2]; + return [core.normalize(pc, 2)]; } else { - return [pc + 1]; + return [core.normalize(pc, 1)]; } } } @@ -87,17 +87,23 @@ exports.SLT = function(core, pc, ins) { if (ins.a.mode === AddrMode.Immediate) { const test = core.getValue(pc, ins.b); if (ins.a.value < test.b.value) { - return [pc + 2]; + return [core.normalize(pc, 2)]; } else { - return [pc + 1]; + return [core.normalize(pc, 1)]; } } else { const left = core.getValue(pc, ins.a); const right = core.getValue(pc, ins.b); if (left.b.value < right.b.value) { - return [pc + 2]; + return [core.normalize(pc, 2)]; } else { - return [pc + 1]; + return [core.normalize(pc, 1)]; } } } + + +exports.JMP = function(core, pc, ins) { + const dstLoc = core.getLocation(pc, ins.a); + return [dstLoc]; +} -- cgit v1.2.1