diff options
author | sanine <sanine.not@pm.me> | 2023-05-23 10:01:05 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-05-23 10:01:05 -0500 |
commit | a6a59d51f626426bb3257ad32ea86cec08d7e3b9 (patch) | |
tree | 349723a10a8b8c9a842b11b2e91df92a880e8103 /src/vm/instruction.js | |
parent | cf71a97881e170fa018bf5fd0f02cdb13b874af8 (diff) |
implement CMP
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]; + } + } +} |