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.js | |
parent | 2880c1565102d8a969846c5e68300ced88066943 (diff) |
fix core boundary wrapping
Diffstat (limited to 'src/vm/instruction.js')
-rw-r--r-- | src/vm/instruction.js | 28 |
1 files changed, 17 insertions, 11 deletions
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]; +} |