Re: Designs of microkernels
Posted: Tue Jan 19, 2021 2:17 pm
Perhaps I didn't quite make my meaning clear. My fault entirely.
As I said, a stack-based VM will use a single bytecode instruction that implicitly pops the operands and then pushes the result.
The implementation for the instruction (jit or interpreter, it doesn't matter) will, when it encounters that instruction, pop operands, execute, and then push the result.
The article linked does not make it clear that it is talking about implementation and not bytecode when it says
This might simply be me misinterpreting the article, which would again be my fault entirely.
I do agree that the images are correct, though.
I'll also note that implementation for a register-based VM would have to carry out essentially the same steps.
It has to use the CPU stack or registers to pass arguments/values the same way.
And your vm_add_v2 needs to push eax again after the add instruction
As I said, a stack-based VM will use a single bytecode instruction that implicitly pops the operands and then pushes the result.
The implementation for the instruction (jit or interpreter, it doesn't matter) will, when it encounters that instruction, pop operands, execute, and then push the result.
The article linked does not make it clear that it is talking about implementation and not bytecode when it says
Comparing this to the stated instruction for the register-based VM, which states that a single line of instruction is required, does indicate to me that the 4 lines in the stack-based version are intended as a representation of the bytecode.four lines of instructions is needed to carry out an addition operation
This might simply be me misinterpreting the article, which would again be my fault entirely.
I do agree that the images are correct, though.
I'll also note that implementation for a register-based VM would have to carry out essentially the same steps.
It has to use the CPU stack or registers to pass arguments/values the same way.
Code: Select all
; Takes r1, r2, r3 as add operand register indexes
vm_add:
mov r1, [reg_struct + 8 * r1]
mov r2, [reg_struct + 8 * r2]
add r1, r1, r2
mov [reg_struct + 8 * r3], r1
ret