summaryrefslogtreecommitdiff
path: root/src/vm/instruction.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/vm/instruction.js')
-rw-r--r--src/vm/instruction.js28
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];
+}