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 3:38

>>8-10
it's funny because while switch can be very easily implemented O(1) or very close to it (ex O(log n)) MS Visual C++tm Enterprise edition uses O(n)

>>1
How would one go about making a virtual machine without using a huge and clumsy switch( opcode ) statement?
you can use a array with function pointers but I remember some other ways too
another way is to have a huge and clumsy switch but let the preprocessor handle it (just like I did)
I had made a script in bash and with the help of the preprocessor I had made it so it will map every opcode in a switch statement to a function or some lines of code while I do not give it a list of the functions (the were in another file and the list was generated by the script in the stile X(functionName, something, somethingElse) and was used by many parts of my program
sorry if I am not understandable, I am sleepy

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