diff options
Diffstat (limited to 'src/vm/instruction.js')
-rw-r--r-- | src/vm/instruction.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/vm/instruction.js b/src/vm/instruction.js index 146a88b..df5369d 100644 --- a/src/vm/instruction.js +++ b/src/vm/instruction.js @@ -52,3 +52,32 @@ exports.SUB = function(core, pc, ins) { return [pc + 1]; } + + +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]; + } else { + return [pc + 1]; + } + } else { + const left = core.getValue(pc, ins.a); + const right = core.getValue(pc, ins.b); + if ( + // compare opcode + left.opcode === right.opcode && + // compare a-field + left.a.mode === right.a.mode && + left.a.value === right.a.value && + // compare b-field + left.b.mode === right.b.mode && + left.b.value === right.b.value + ) { + return [pc + 2]; + } else { + return [pc + 1]; + } + } +} |