Hello StackOverflow Community,
How do I call a function from a function pointer array based on the passed opcode?
For example when I read the opcode '0x1A' and pass it to a function pointer array I want to call some function for example 'add()'.
How can I do that without using switch/case ?
My function pointer array:
void (*execOp[4])(int opcode) = { add, sub, div, mul };
My Codebase:
const int memory[2]= {0x1A, 0x1D}; // Memory
int pc=0; //Program counter
int opcode; //Current opcode
//Functions
void fetch()
{
opcode=memory[pc];
}
void add()
{
printf("add");
}
int main()
{
//Decoding Opcodes from Memory
for(;;)
{
fetch();
}
return 0;
}