??? 06/28/05 07:06 Read: times |
#96077 - As Matter of Fact.... Responding to: ???'s previous message |
As a matter of fact the Keil C51 compiler generates a JUMP table for a switch statement. I tried an example for a large sequential case switch with 16 cases. The compiler made an indexable jump table like this:
MOV A,sub_sel?1640+01H CJNE A,#010H,?C0035 ?C0035: JC $ + 5H LJMP ?C0017 MOV DPTR,#?C0036 MOV R0,A ADD A,R0 ADD A,R0 JMP @A+DPTR ?C0036: LJMP ?C0018 LJMP ?C0019 LJMP ?C0020 LJMP ?C0021 LJMP ?C0022 LJMP ?C0023 LJMP ?C0024 LJMP ?C0025 LJMP ?C0026 LJMP ?C0027 LJMP ?C0028 LJMP ?C0029 LJMP ?C0030 LJMP ?C0031 LJMP ?C0032 LJMP ?C0033 ; { ; SOURCE LINE # 110 ; case 0: ; SOURCE LINE # 111 ?C0018: ; sub_ret = sub0(); ; SOURCE LINE # 112 LCALL sub0 ; break; ; SOURCE LINE # 113 SJMP ?C0051 ; ; case 1: ; SOURCE LINE # 115 ?C0019: ; sub_ret = sub1(); ; SOURCE LINE # 116 LCALL sub1 ?C0037: ; break; ; SOURCE LINE # 117 SJMP ?C0051 ...The compiler generated code to index the JUMP table is bog standard 8051 "JMP @A+DPTR" stuff. The switch looked like this: int sub_sel; int sub_ret; sub_sel = 13; switch(sub_sel) { case 0: sub_ret = sub0(); break; case 1: sub_ret = sub1(); break; case 2: sub_ret = sub2(); break; case 3: sub_ret = sub3(); break; case 4: sub_ret = sub4(); break; case 5: sub_ret = sub5(); break; case 6: sub_ret = sub6(); break; case 7: sub_ret = sub7(); break; case 8: sub_ret = sub8(); break; case 9: sub_ret = sub9(); break; case 10: sub_ret = sub10(); break; case 11: sub_ret = sub11(); break; case 12: sub_ret = sub12(); break; case 13: sub_ret = sub13(); break; case 14: sub_ret = sub14(); break; case 15: sub_ret = sub15(); break; } Michael Karas |
Topic | Author | Date |
Coding a Jmp table in C | 01/01/70 00:00 | |
Jmp Tables in C | 01/01/70 00:00 | |
you do not | 01/01/70 00:00 | |
Call table? | 01/01/70 00:00 | |
Of course not! | 01/01/70 00:00 | |
use jmp@a+dptr | 01/01/70 00:00 | |
jmp table not in C | 01/01/70 00:00 | |
Wrong ends of sticks? | 01/01/70 00:00 | |
You do not control the Compiler Output | 01/01/70 00:00 | |
You can not have your cake and eat it to | 01/01/70 00:00 | |
Jump Table in C | 01/01/70 00:00 | |
Call Table? (again) | 01/01/70 00:00 | |
Call Table? (again) | 01/01/70 00:00 | |
I never did use function pointers | 01/01/70 00:00 | |
No pain, no gain. | 01/01/70 00:00 | |
the overlaying | 01/01/70 00:00 | |
There can be a gain. | 01/01/70 00:00 | |
My 2 cents worth | 01/01/70 00:00 | |
Incorrect | 01/01/70 00:00 | |
As Matter of Fact....![]() | 01/01/70 00:00 |