jumptables
Eddie.Wyatt at ius2.cs.cmu.edu.UUCP
Eddie.Wyatt at ius2.cs.cmu.edu.UUCP
Thu Mar 12 06:15:03 AEST 1987
To follow is the assemble language generated by a C compiler running
on a Vax 780 (Unix os of course) for a case statement.
LL0:
.data
.text
.align 1
.globl _main
_main:
.word L12
jbr L14
L15:
movl -4(fp),r0
jbr L17
L18:
movl -12(fp),-8(fp)
jbr L16
L19:
movl -16(fp),-20(fp)
jbr L16
L20:
movl -20(fp),-16(fp)
jbr L16
L21:
movl -8(fp),-16(fp)
jbr L16
L22:
movl -8(fp),-24(fp)
jbr L16
L23:
movl -24(fp),-16(fp)
jbr L16
L17:
casel r0,$0,$5
L24:
.word L18-L24
.word L19-L24
.word L20-L24
.word L21-L24
.word L22-L24
.word L23-L24
L25:
L16:
ret
.set L12,0x0
L14:
subl2 $24,sp
jbr L15
.data
Original code
main()
{
int c;
int h, k, j, i, m;
switch (c)
{
case 0:
h = k;
break;
case 1:
i = j;
break;
case 2:
j = i;
break;
case 3:
j = h;
break;
case 4:
m = h;
break;
case 5:
j = m;
break;
}
}
Note that the vax has a special case instruction.
The answer to your question of why you can't have jump tables is
that it is up to the C compiler to make such optimizations that may be machine
depended.
May I also ask have you checked the code that your C compiler has generated
to make sure it is not generating direct threaded code for case statements?
As I have been told, the C compiler for the Suns does.
Eddie Wyatt
Research Programming (CMU)
edw at ius1.cs.cmu.edu
More information about the Comp.lang.c
mailing list