Forum : 8051
Original Post
| Post Information | Post |
|---|---|
|
June 1, 2007 - 3:56pm
|
How can I force the RC51 compiler to produce jump tables for switch statements ? thanks M.Marolda |
Forum : 8051
| Post Information | Post |
|---|---|
|
June 1, 2007 - 3:56pm
|
How can I force the RC51 compiler to produce jump tables for switch statements ? thanks M.Marolda |
A jump table will be generated when the "case" values are consecutive:
Typically:
switch ( c )
{
case 10:
fct10();
break;
case 11:
fct11();
break;
case 12:
fct12();
break;
case 13:
fct13();
break;
etc...
When the values are too different, table with couples "address+value" will be generated.
I still can't see how to obtain a real jump table,
I tried to compile your example and this is the result:
Source code
void provaJT(unsigned char c) { switch ( c ) { case 10: P1_0=0; break; case 11: P1_1=0; break; case 12: P1_2=0; break; case 13: P1_3=0; break; } }RC51 compiler result
_provaJT PROC ; SOURCE LINE # 34 ;$@$C_SOURCE_FILE(c:\progetti_8051\io\main_loop.c) ;$@$C_SOURCE_LINE(34) MOV A,R7 ADD A,#0F6H JZ ?CASE4 DEC A JZ ?CASE5 DEC A JZ ?CASE6 DEC A JZ ?CASE7 RET ?CASE4: ; SOURCE LINE # 37 ;$@$C_SOURCE_LINE(37) CLR P1_0 ; SOURCE LINE # 38 ;$@$C_SOURCE_LINE(38) RET ?CASE5: ; SOURCE LINE # 40 ;$@$C_SOURCE_LINE(40) CLR P1_1 ; SOURCE LINE # 41 ;$@$C_SOURCE_LINE(41) RET ?CASE6: ; SOURCE LINE # 43 ;$@$C_SOURCE_LINE(43) CLR P1_2 ; SOURCE LINE # 44 ;$@$C_SOURCE_LINE(44) RET ?CASE7: ; SOURCE LINE # 46 ;$@$C_SOURCE_LINE(46) CLR P1_3 ; SOURCE LINE # 49 ;$@$C_SOURCE_LINE(49) RET ENDPIt depends on the number of tested values. If you add more cases, you will get the following listing:
Perfect!!
Know I have a wonderfull and fast assembler code.
Thank you a lots
Massimo Marolda