lab17: part 2

This commit is contained in:
2026-04-22 12:03:22 -07:00
parent 6d6820009b
commit 1c5df94c31

View File

@@ -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());