Hacker News new | ask | show | jobs
by haldean 4571 days ago
Not to nitpick, but doesn't it need to be two instructions? You first do a relative jump by the value you're switching on, which takes you to another jump that jumps you to the actual code for that case. I can't think of a way to do it in just one instruction.
1 comments

Just do an indirect branch, using a table of target pointers. If you had the opcode in eax, the single instruction would be something like:

    jmp  [lookupTable + eax]
Ah, good point. Thanks!