|
@@ -11,6 +11,7 @@ module.exports = class Computer {
|
|
|
this.OPCODES = {
|
|
|
ADD: 1,
|
|
|
MULTIPLY: 2,
|
|
|
+ OUTPUT: 4,
|
|
|
HALT: 99,
|
|
|
};
|
|
|
this.PARAMETER_MODES = {
|
|
@@ -58,6 +59,10 @@ module.exports = class Computer {
|
|
|
this.Operation_Multiply(operandLeft, operandRight, position);
|
|
|
break;
|
|
|
}
|
|
|
+ case this.OPCODES.OUTPUT: {
|
|
|
+ const outputPosition = this.stack.Next().Get();
|
|
|
+ this.Operation_Output(outputPosition);
|
|
|
+ }
|
|
|
case this.OPCODES.HALT:
|
|
|
status = false;
|
|
|
break;
|
|
@@ -102,6 +107,15 @@ module.exports = class Computer {
|
|
|
this.stack.Put(outputPosition, newValue);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Execute the OUTPUT opcode
|
|
|
+ *
|
|
|
+ * @param {number} outputPosition The memory address of the value to output
|
|
|
+ */
|
|
|
+ Operation_Output(outputPosition) {
|
|
|
+ console.log(this.stack.Get(outputPosition));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Outputs the computer's stack to the console
|
|
|
* @returns {void}
|