From 1c5df94c31cfc760b162cce2ef12cc24820bc754 Mon Sep 17 00:00:00 2001 From: Yuri Tatishchev Date: Wed, 22 Apr 2026 12:03:22 -0700 Subject: [PATCH] lab17: part 2 --- lab17/op-codes.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lab17/op-codes.js b/lab17/op-codes.js index f12141d..3ee9473 100644 --- a/lab17/op-codes.js +++ b/lab17/op-codes.js @@ -7,11 +7,16 @@ let opcodes = { vm.stack.push(v1+v2); }}, 0x02: { mnemonic: 'MUL', evaluate: (vm) => { - // - // **YOUR CODE HERE** - // // Pop the top two arguments off of the stack, // and then push the result on to the stack. + let v1 = vm.stack.pop(); + let v2 = vm.stack.pop(); + vm.stack.push(v1*v2); + }}, + 0x03: { mnemonic: 'SUB', evaluate: (vm) => { + let v1 = vm.stack.pop(); + let v2 = vm.stack.pop(); + vm.stack.push(v1-v2); }}, 0x5B: { mnemonic: 'JUMPDEST', evaluate: (vm) => { // Does nothing. We could check to make sure that jumps @@ -24,6 +29,12 @@ let opcodes = { let v = vm.bytecode.readUInt8(vm.pc); vm.stack.push(v); }}, + 0x90: { mnemonic: 'SWAP1', evaluate: (vm) => { + let v1 = vm.stack.pop(); + let v2 = vm.stack.pop(); + vm.stack.push(v1); + vm.stack.push(v2); + }}, 0x0c: { mnemonic: 'PRINT', evaluate: (vm) => { // **NOTE**: This is not a real EVM opcode. console.log(vm.stack.pop());