|
@@ -44,8 +44,8 @@ const ASM_DICTIONARY = {
|
|
"out": insertOutput,
|
|
"out": insertOutput,
|
|
"jnz": insertTestJump.bind(null, OP_CODE_DICTIONARY.JUMP_IF_TRUE),
|
|
"jnz": insertTestJump.bind(null, OP_CODE_DICTIONARY.JUMP_IF_TRUE),
|
|
"jz": insertTestJump.bind(null, OP_CODE_DICTIONARY.JUMP_IF_FALSE),
|
|
"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"),
|
|
"incb": instructionNotYetImplemented.bind(null, "INCB"),
|
|
"hlt": insertHalt,
|
|
"hlt": insertHalt,
|
|
};
|
|
};
|
|
@@ -130,6 +130,42 @@ function insertTestJump(opcode, testingParameter, jumpDestination) {
|
|
tape[tapePointer++] = strToDecimal(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
|
|
* Add the HALT opcode at the next address
|
|
*/
|
|
*/
|