Which design do you guys find to be better of the following two when fetching the instruction:
1) A jump table with all of the opcodes (function pointers in the right places in the table) that are referenced.
2) A large switch loop with a case for each opcode.
At present, I have mine doing things with a jump table but am curious of which way is better. I have an individual function for each opcode. Way I see it is I only had to write the code just once.
Most compilers will turn a "gigantic big-ass switch/case statement" into a jump table (while, if I remember correctly, a small number of switch/case statements results in a series of mov/cmp statements). It's your responsibility to determine which happens by looking at the generated assembly code from the compiler, and/or by doing profiling.
If you don't know whether or not to trust the compiler, then your own jump/function table is perfectly fine.
Quote:
Which design do you guys find to be better of the following two when fetching the instruction:
Whichever meets your design goals. A good starting place is whichever is most clear/maintainable. Surely one is easier to write than the other. Use that.
I use two jump tables. The first one decodes the addressing mode and the argument (immediate byte, indirect etc), the next one do the opcode operations. With this system, most of opcodes can be condensed in just one.
Zepper wrote:
I use two jump tables. The first one decodes the addressing mode and the argument (immediate byte, indirect etc), the next one do the opcode operations. With this system, most of opcodes can be condensed in just one.
This is how I do it too. It makes for extremely clean code that's easy to manage and others to understand.
miker00lz wrote:
Zepper wrote:
I use two jump tables. The first one decodes the addressing mode and the argument (immediate byte, indirect etc), the next one do the opcode operations. With this system, most of opcodes can be condensed in just one.
This is how I do it too. It makes for extremely clean code that's easy to manage and others to understand.
I thought I was the only one!!! Its so easy to manage and the readability is out of this world.