Virtual Machine

So after learning about Notch's new game, I decided it might be fun to try to program a very simplistic virtual machine myself. I just wanted to ask some general questions as to if my style is okay, or could be done in a better way:
1. I currently use a member function pointer array (I know it should be changed to a simple function pointer array) to resolve the operation, but I have read that most compilers will actually optimize long switch statements into something like a lookup table, allowing for faster code (Due to the fact that arguments don't have to be pushed onto the stack) Should I use a switch statement instead?
2. Second, to hold my registers I use an Array as well (for 16 bit general registers) which allows me to pass the register in as an index into the array. This forces me to check that the argument is not longer than the array (This could be omitted if I were to write a decent assembler, but I like the safety), but gives me general access to all registers of the same length.
3. I also have a number of 8 bit registers (using the same index scheme) but I can't find a way to combine 8 and 16 bit operations into one function, which forces me to write multiple op codes for each operation (e.g. Add reg16,reg16 Add reg8,reg8 Add reg16, Immediate etc.) Is there a way to improve on this?
4. In relation to question 3. what type of arguments should I allow, and how would I combine them into the least amount of functions for each operation? For example, should Add regX, MemPointer be a base case? Where MemPointer is the value of what the given memory address points to?
Topic archived. No new replies allowed.