Created
March 10, 2019 21:42
-
-
Save pramoth/12c9b5aa002163984463987470d6e0a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {StackFrame} from "./stack-frame"; | |
| export class Opcode { | |
| //code for part3 | |
| static ISTORE_1 = (satckFrame: StackFrame): void => { | |
| satckFrame.localVariables[1] = satckFrame.operandStack.pop() | |
| satckFrame.pc++ | |
| } | |
| static ILOAD_1 = (satckFrame: StackFrame): void => { | |
| satckFrame.operandStack.push(satckFrame.localVariables[1]) | |
| satckFrame.pc++ | |
| } | |
| static BIPUSH = (satckFrame: StackFrame): void => { | |
| let byteValue = satckFrame.instructions[satckFrame.pc + 1] | |
| satckFrame.operandStack.push(byteValue) | |
| satckFrame.pc = satckFrame.pc + 2 | |
| } | |
| static IINC = (satckFrame: StackFrame): void => { | |
| let index = satckFrame.instructions[satckFrame.pc +1 ] | |
| let incrementBy = satckFrame.instructions[satckFrame.pc + 2] | |
| satckFrame.localVariables[index] = satckFrame.localVariables[index] + incrementBy | |
| satckFrame.pc = satckFrame.pc + 3 | |
| } | |
| static GOTO = (satckFrame: StackFrame): void => { | |
| let msb = satckFrame.instructions[satckFrame.pc +1] | |
| let lsb = satckFrame.instructions[satckFrame.pc +2] | |
| let offset = (msb << 8) + lsb; | |
| satckFrame.pc = offset | |
| } | |
| static IF_ICMPGE = (satckFrame: StackFrame): void => { | |
| let operand2 = satckFrame.operandStack.pop(); | |
| let operand1 = satckFrame.operandStack.pop(); | |
| if (operand1 >= operand2) { | |
| let msb = satckFrame.instructions[satckFrame.pc +1] | |
| let lsb = satckFrame.instructions[satckFrame.pc +2] | |
| let offset = (msb << 8) + lsb; | |
| satckFrame.pc = offset | |
| } else { | |
| satckFrame.pc = satckFrame.pc +3 | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment