Re:TinyVM: A lightweight, fast virtual machine in < 500 l...
by monopede on Saturday July 02, 2011 @08:45PM
(#2722759)
Looking at the instruction set it doesn't even support subroutines. It would only need a way to get and set the current program counter (like ARM) and you could implement subroutine calls using push, pop, and jmp.
[ Parent
| on HN ]
Re:TinyVM: A lightweight, fast virtual machine in < 500 l...
by jws on Sunday July 03, 2011 @12:02AM
(#2723040)
I think subroutines would go something like:
PUSH the_address_you_want_to_come_back_to
JMP some_other_spot
the_address_you_want_to_come_back_to:
BLAH
BLAH
...
some_other_spot:
BLAH
BLAH
POP some_scratch_address
JMP some_scratch_address
So yes, JSR is two opcodes and RTS is also two opcodes, but it works.
Re:TinyVM: A lightweight, fast virtual machine in < 500 l...
by kragen on Monday July 04, 2011 @05:12PM
(#2727892)
In your first snippet, you seem to be assuming that JMP is direct, and in the second, you seem to be assuming that JMP is indirect. It appears to be direct: https://github.com/GenTiradentes/tinyvm/blob/master/tvm.c#L5...
You could, of course, do it with self-modifying code if that's possible. (I'm not familiar enough with the VM to know if it is.)