lab17: init

This commit is contained in:
2026-04-22 11:03:07 -07:00
parent 6aa6c9f076
commit 6d6820009b
13 changed files with 417 additions and 0 deletions

33
lab17/op-codes.js Normal file
View File

@@ -0,0 +1,33 @@
'use strict';
let opcodes = {
0x01: { mnemonic: 'ADD', evaluate: (vm) => {
let v1 = vm.stack.pop();
let v2 = vm.stack.pop();
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.
}},
0x5B: { mnemonic: 'JUMPDEST', evaluate: (vm) => {
// Does nothing. We could check to make sure that jumps
// always land at JUMPDEST opcodes, but it is not totally
// clear that it is worth the bother.
}},
0x60: { mnemonic: 'PUSH1', evaluate: (vm) => {
// The next byte is data, not another instruction
vm.pc++;
let v = vm.bytecode.readUInt8(vm.pc);
vm.stack.push(v);
}},
0x0c: { mnemonic: 'PRINT', evaluate: (vm) => {
// **NOTE**: This is not a real EVM opcode.
console.log(vm.stack.pop());
}},
};
exports.opcodes = opcodes;