I'm trying to use nasm to create a jump table so I don't have to slow down the processor as it iterates through a bunch of compares. For simplicity, we will use register AL here as the value returned from an earlier user input function.
Let's say for example I have this code to process the input:
cmp AL,00h
je doitem0
cmp AL,01h
je doitem1
cmp AL,02h
je doitem2
cmp AL,03h
je doitem3
cmp AL,04h
je doitem4
.....
cmp AL,11h
je doitem17
I have attempted to convert it to something like this:
blk equ 8h ;code block size so jump code fits nicely
mov AH,0h
shl AL,3 ;shift 3x = multiply by block size
add AX,jt
jmp AX
;start of jump table
jt:
org jt+blk*0h
jmp doitem0
org jt+blk*1h
jmp doitem1
org jt+blk*2h
jmp doitem2
org jt+blk*3h
jmp doitem3
...
org jt+blk*11h
jmp doitem17
However nasm 2.10.04 (the version I have) is fussy on the second idea. For every org statement, I get the error:
error: org value must be a critical expression
So if it doesn't like the way I'm using the org statement, is there another way I can make an efficient jump table so that the program doesn't have to have the tedious task of comparing the input to up to 16 different values to reach the user's choice?