lab17: part 2
This commit is contained in:
@@ -7,11 +7,16 @@ let opcodes = {
|
|||||||
vm.stack.push(v1+v2);
|
vm.stack.push(v1+v2);
|
||||||
}},
|
}},
|
||||||
0x02: { mnemonic: 'MUL', evaluate: (vm) => {
|
0x02: { mnemonic: 'MUL', evaluate: (vm) => {
|
||||||
//
|
|
||||||
// **YOUR CODE HERE**
|
|
||||||
//
|
|
||||||
// Pop the top two arguments off of the stack,
|
// Pop the top two arguments off of the stack,
|
||||||
// and then push the result on to 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) => {
|
0x5B: { mnemonic: 'JUMPDEST', evaluate: (vm) => {
|
||||||
// Does nothing. We could check to make sure that jumps
|
// Does nothing. We could check to make sure that jumps
|
||||||
@@ -24,6 +29,12 @@ let opcodes = {
|
|||||||
let v = vm.bytecode.readUInt8(vm.pc);
|
let v = vm.bytecode.readUInt8(vm.pc);
|
||||||
vm.stack.push(v);
|
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) => {
|
0x0c: { mnemonic: 'PRINT', evaluate: (vm) => {
|
||||||
// **NOTE**: This is not a real EVM opcode.
|
// **NOTE**: This is not a real EVM opcode.
|
||||||
console.log(vm.stack.pop());
|
console.log(vm.stack.pop());
|
||||||
|
|||||||
Reference in New Issue
Block a user