How would I jump to the equate of a value?
------
=1:
...
=2:
...
>7:
...
<1:
...
etc.
------
Don't know if it can help but Jeremy gordon have published a paper in APJ #5 about
indexed case selection in Win Callback.
APJ page:
http://asmjournal.freeservers.com/
Jeremy page:
http://www.godevtool.com/index.html
___________________________________
I don't understand what Equates could be usefull for this but, Basically,
and depending on your Assembler syntax, it should be possible to set a
table of Code Adresses. In SpAsm, i would tell:
Routine1:
; Blablabla
ret
Routine2:
; Blablabla
ret
; ...
> mov eax D§MyRoutineSelector ; something holding 1 / 2 ... depending on cases
> lea eax D§MyRoutinesPointers+eax*4
> call D§eax
betov.
.IF value=1
{do something}
jmp done_here
.ENDIF
.IF value=2
{do something}
jmp done_here
.ENDIF
.IF value=7
{do something}
jmp done_here
.ENDIF
.IF value<1 ; it REALLY helps here to have
; value defined as a signed value
{do something}
.ENDIF
done:here:
(check the lst file, I forget if this expands to tight code, ELSEIF may be more appropiate)
I tend to write such code in the manner below, for two reasons: 1) all of the decision code is clumped together in one spot, 2) fewer cache misses when there are lots of cases.
Don't know how it affects branch prediction.
; first compute value to compare, and put in EAX
; then do the following
cmp eax,1
jl case_too_small
je case_equal_1
cmp eax,2
je case_equal_2
cmp eax,7
jg case_too_big
jmp case_default
Each case ends with
jmp end_case
And after the last case, I define a label
end_case:
; followed by non-case code