|
@@ -54,11 +54,7 @@ module.exports = class Computer {
|
|
|
break;
|
|
|
}
|
|
|
case this.OPCODES.MULTIPLY: {
|
|
|
- const operandLeft = this.stack.Next().Get();
|
|
|
- const operandRight = this.stack.Next().Get();
|
|
|
- const position = this.stack.Next().Get();
|
|
|
-
|
|
|
- this.Operation_Multiply(operandLeft, operandRight, position);
|
|
|
+ this.Operation_Multiply(rawOpcode);
|
|
|
break;
|
|
|
}
|
|
|
case this.OPCODES.INPUT: {
|
|
@@ -127,13 +123,16 @@ module.exports = class Computer {
|
|
|
* Multiplies two numbers and stores the result at the provided
|
|
|
* position on the stack.
|
|
|
*
|
|
|
- * @param {number} operandLeft The first operand
|
|
|
- * @param {number} operandRight The second operand
|
|
|
- * @param {number} outputPosition The position on the stack to place the result
|
|
|
+ * @param {number} rawOpcode The opcode in memory used to make this call
|
|
|
* @returns {void}
|
|
|
*/
|
|
|
- Operation_Multiply(operandLeft, operandRight, outputPosition) {
|
|
|
- [operandLeft, operandRight] = this._ParseOperands(operandLeft, operandRight);
|
|
|
+ Operation_Multiply(rawOpcode) {
|
|
|
+ const operandLeftMode = ComputerParameterMode.ParseParameterMode(rawOpcode, 1);
|
|
|
+ const operandRightMode = ComputerParameterMode.ParseParameterMode(rawOpcode, 2);
|
|
|
+
|
|
|
+ const operandLeft = this.stack.Next().Get(operandLeftMode);
|
|
|
+ const operandRight = this.stack.Next().Get(operandRightMode);
|
|
|
+ const outputPosition = this.stack.Next().Get(ComputerParameterMode.IMMEDIATE_MODE);
|
|
|
|
|
|
const newValue = operandLeft * operandRight;
|
|
|
this.stack.Put(outputPosition, newValue);
|