From a6a59d51f626426bb3257ad32ea86cec08d7e3b9 Mon Sep 17 00:00:00 2001 From: sanine Date: Tue, 23 May 2023 10:01:05 -0500 Subject: implement CMP --- src/vm/instruction.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/vm/instruction.js') 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]; + } + } +} -- cgit v1.2.1