<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Il 17/08/2018 15:46, Marco Borsari via fpc-pascal ha scritto:<br>
</p>
<blockquote type="cite"
cite="mid:d3f4f71b-1c63-8209-2310-a830dd7e1288@libero.it">I found
that someone made that for me at link
<br>
<a class="moz-txt-link-freetext"
href="http://www.mindfruit.co.uk/2012/01/switch-blocks-jump-tables.html"
moz-do-not-send="true">http://www.mindfruit.co.uk/2012/01/switch-blocks-jump-tables.html</a>
<br>
and I have tried to rewrite the program in at&t syntax
<br>
<br>
program branch2;
<br>
{$ASMMODE att}
<br>
label next,stop,a,b,c;
<br>
var idx:byte;
<br>
begin
<br>
write('Index? ');
<br>
readln(idx);
<br>
asm
<br>
movb idx,%al
<br>
jmp *next(,%eax,4)
<br>
next:
<br>
jmp a;
<br>
jmp b;
<br>
jmp c;
<br>
end['EAX'];
<br>
a:
<br>
writeln('0');
<br>
goto stop;
<br>
b:
<br>
writeln('1');
<br>
goto stop;
<br>
c:
<br>
writeln('2');
<br>
stop:
<br>
writeln('stop');
<br>
end.
<br>
<br>
but this fails compilation at line 10 with messages
<br>
Unsupported symbol type for operand
<br>
Unknown identifier 'NEXT'
<br>
Well, I think I can live without it, it is only for
<br>
the sake of curiosity,
<br>
Marco
</blockquote>
<br>
I modified your code, to add a jump table (as it is in the example
you mention) and here it works just fine. The code which works is:<br>
<pre>program branch2;
{$ASMMODE att}
label stop,a,b,c;
var idx:byte;
Jtab: array [0..2] of pointer;
begin
// Fill up the Jump table with the addresses of jump targets
Jtab[0] := @a;
Jtab[1] := @b;
Jtab[2] := @c;
write('Index? ');
readln(idx);
asm
mov $0x0,%eax // clear upper bits of eax
movb idx,%al // so that it contains just idx
jmpq *Jtab(,%eax,8) // 8 is for x86_64; replace with 4 for i386
end['EAX'];
a:
writeln('0');
goto stop;
b:
writeln('1');
goto stop;
c:
writeln('2');
stop:
writeln('stop');
end.
</pre>
Enjoy programming!<br>
<br>
Giuliano<br>
<pre class="moz-signature" cols="72">--
Do not do to others as you would have them do to you.They might have different tastes.</pre>
</body>
</html>