[fpc-pascal] Branch table
Giuliano Colla
giuliano.colla at fastwebnet.it
Mon Aug 20 17:32:04 CEST 2018
Il 18/08/2018 15:52, Marco Borsari via fpc-pascal ha scritto:
> it works only for index 0, and crashes otherwise. Maybe
> a problem of alignment? Or must be tab declared in data section?
On the Intel architecture you cannot perform pointer arithmetic as if a
pointer were just a number.
A pointer is composed of two parts: a "selector" and an "offset", which
must be handled separately.
If in place of your addition (add ebx,eax) you leave the appropriate
instruction to take care of putting together selector and offset, it works.
Just change your lines:
mov ebx,tab;
add ebx,eax;
jmp ebx;
Into:
jmp tab[eax]
and it will work just fine. Just tested.
Giuliano
--
Do not do to others as you would have them do to you.They might have different tastes.
More information about the fpc-pascal
mailing list