I have a server socket which receives a byte (operation code) from the client.
Depending on what the value of that byte is, I need to decode further data with a specific function.
For example:
- if the value is
0x01
, I need tocall function1
to decode it. - for
0x02
, executecall function2
- and so forth...
I don't want to hardcode it all with compare and jump statements because there are more than 150 possible values and that would result to 400+ lines of code.
What would be the best option to implement this, resulting in the cleanest code? In C language, I would do this with a simple array: array[index]
where array stores the function pointers and index is the operation code. This would result in O(1) speeds.
This is just a general question, but I'm working with x86_64 asm with NASM syntax if that helps.