S
sfx1999
Guest
What exactly is the difference between JIT emulation as apposed to a regular interpreter? I plan on writing an emulator some day, so it would help me a lot if I knew this.
char* memory = malloc( SOME_LARGE_AMOUNT );int mem_pointer = 0;while(true){ switch(memory[mem_pointer++]){ // Pick a function based upon the opcode in this part of memory case 0: // NOP break; case 1: // Immediate Mode ADD A to B and store into address C char a = memory[mem_pointer++]; char b = memory[mem_pointer++]; memory[mem_pointer] = a + b; break; // et cetra default: printf("Unknown Opcode encountered!"); exit(-1); }}
Are you sure? At one point I looked at the assembly generated by GCC for a 6502 emulator and it actually created a jump table for a big switch statement.It is a lot faster to make a bunch of pointers to functions and use the opcodes as a look up table then to use switch/case.
That was about 7 years ago, when the first emulators came up. Don't ask me which version of gcc, or which switches exactly. I'd guess it was simply -O2.Micky, when you did that, did you use any optimazation switches?
That's a possibilityIt's a learning experience. Anyway, it could help on PDAs and stuff.
You'll need to know assembler. You can copy around functions written in C in memory under certain conditions (position-independent code), but I wouldn't depend on it...Now if someone could tell me how to dynamically create code into memory and call it using C, I would really appreciate it.