浏览代码

Add less than and equality check

ApisNecros 3 周之前
父节点
当前提交
392b4acf8d
共有 1 个文件被更改,包括 38 次插入2 次删除
  1. 38 2
      yaict

+ 38 - 2
yaict

@@ -44,8 +44,8 @@ const ASM_DICTIONARY = {
     "out": insertOutput,
     "jnz": insertTestJump.bind(null, OP_CODE_DICTIONARY.JUMP_IF_TRUE),
     "jz": insertTestJump.bind(null, OP_CODE_DICTIONARY.JUMP_IF_FALSE),
-    "slt": instructionNotYetImplemented.bind(null, "SLT"),
-    "seq": instructionNotYetImplemented.bind(null, "SEQ"),
+    "slt": insertLessThanCheck,
+    "seq": insertEqualityCheck,
     "incb": instructionNotYetImplemented.bind(null, "INCB"),
     "hlt": insertHalt,
 };
@@ -130,6 +130,42 @@ function insertTestJump(opcode, testingParameter, jumpDestination) {
     tape[tapePointer++] = strToDecimal(jumpDestination);
 }
 
+/**
+ * Insert a less than check onto the tape
+ *
+ * @param {string} operand1 The first parameter to test. Can be either an immediate value or an address
+ * @param {string} operand2 The parameter to test against. Can be either an immediate value or an address
+ * @param {string} outputDestination The address to write the output to
+ */
+function insertLessThanCheck(operand1, operand2, outputDestination) {
+    if (!isAddress(outputDestination)) {
+        throw new WrongParameterModeError();
+    }
+
+    tape[tapePointer++] = strToDecimal(getParameterMode(operand2) + getParameterMode(operand1) + OP_CODE_DICTIONARY.LESS_THAN);
+    tape[tapePointer++] = strToDecimal(operand1);
+    tape[tapePointer++] = strToDecimal(operand2);
+    tape[tapePointer++] = strToDecimal(outputDestination);
+}
+
+/**
+ * Insert an equality check onto the tape
+ *
+ * @param {string} operand1 The first parameter to test. Can be either an immediate value or an address
+ * @param {string} operand2 The parameter to test equality against. Can be either an immediate value or an address
+ * @param {string} outputDestination The address to write the output to
+ */
+function insertEqualityCheck(operand1, operand2, outputDestination) {
+    if (!isAddress(outputDestination)) {
+        throw new WrongParameterModeError();
+    }
+
+    tape[tapePointer++] = strToDecimal(getParameterMode(operand2) + getParameterMode(operand1) + OP_CODE_DICTIONARY.EQUALS);
+    tape[tapePointer++] = strToDecimal(operand1);
+    tape[tapePointer++] = strToDecimal(operand2);
+    tape[tapePointer++] = strToDecimal(outputDestination);
+}
+
 /**
  * Add the HALT opcode at the next address
  */