Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

VM instruction implementation without huge switch()?

Name: Anonymous 2014-06-09 23:26

How would one go about making a virtual machine without using a huge and clumsy switch( opcode ) statement?

The architecture I'm implementing (DCPU-16) has about 35-40 different instructions.

Name: Anonymous 2014-06-10 1:50

>>3
switch is not constant. Its upper bound is N. If the opcode being executed is the last opcode in your switch, you need to make N, or in this case 40, comparisons, whereas lg(40) = 5.

A switch would be better if you know that certain opcodes will be executed from frequently than others, in which case you can order your switch by the frequency of the opcode.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List