Bladeren bron

Add less than and equality check

ApisNecros 3 weken geleden
bovenliggende
commit
392b4acf8d
1 gewijzigde bestanden met toevoegingen van 38 en 2 verwijderingen
  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
  */