[fpc-pascal] Branch table

Marco Borsari borsa77 at libero.it
Sat Aug 18 15:52:26 CEST 2018


Il 17/08/2018 18:04, Giuliano Colla ha scritto:

> I modified your code, to add a jump table (as it is in the example you
> mention)

I came to that

program branch;
{$ASMMODE intel}
label tab,stop,a,b,c;
var idx:byte;
begin
write('Index? ');
readln(idx);
asm
xor eax,eax;
mov al,idx;
shl ax,2;
mov ebx,tab;
add ebx,eax;
jmp ebx;
tab:
dd (*offset*) a;
dd (*offset*) b;
dd (*offset*) c;
end['EAX','EBX'];
a:
writeln('0');
goto stop;
b:
writeln('1');
goto stop;
c:
writeln('2');
stop:
writeln('stop');
end.

but it works only for index 0, and crashes otherwise. Maybe
a problem of alignment? Or must be tab declared in data section?



More information about the fpc-pascal mailing list