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 2016-10-26 1:05

So when I write a big switch with like 100 or so branches, like this:
switch(op) {
case 0: /*...*/ break;
case 1: /*...*/ break;
case 2: /*...*/ break;
case 3: /*...*/ break;
...
case 100: /*...*/ break;
}

with the conditions always incrementing and being in order, won't a modern compiler optimize it for me?

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