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

You're writing in assembly, you don't have to be limited to the constraints of C.

http://www.complang.tuwien.ac.at/forth/threaded-code.html

Name: Anonymous 2014-06-10 19:57

>>27
Oops, I misread the OP. Thought they were writing a virtual machine in DCPU-16 assembly, but they were actually talking about DCPU-16 emulator for PCs.

Yeah, a switch statement is the best you can do in portable C. You can get something close to token-threaded code if you use the gcc labels-as-values extension, but then it won't be portable to all C compilers, and the code generated by even the best C compiler is going to be shit compared to a naive assembly implementation.

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