This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCSTUDIO-C2000: switch-case-statements - jump tables

Part Number: CCSTUDIO-C2000

Hello everyone,

I have a very long nested switch-case branch (about 5000 lines of code). I am trying to understand how the compiler creates the jump table. For me the switch-case branch is a piece of program. Therefore the jump table must be in the section .switch and this section is logically in the program memory. But in "compiler user's guide"

the statements about it are very different and partly contradictory.


On the page 146 it is to be read that the jump table is in the section .econst (this section is in the program memory).

On the next page 147 you can read that the jump table is in the section .switch. And this section is in program memory if -unified_memory-option is on. Otherwise it is in the data memory. Without my doing the jump table (a piece of program code) is in the data memory. I can't understand that.

Can someone explain me how the compiler creates the jump table for switch-case branch and where exactly is the jump table placed? And in my case (very long switch-case branch), how can I do best?


Many thanks in advance - Bui

  • I'm nearly certain the manual is wrong when it says switch tables go in .econst.  I'll confirm that and get back to you.

    Thanks and regards,

    -George

  • I can confirm the manual is incorrect.  Switch tables are always in a section named .switch.  The entry EXT_EP-10555 has been filed to correct this error.  You are welcome to follow it with that link.

    where exactly is the jump table placed?

    Wherever the linker command file allocates the .switch section.  The compiler presumes .switch is in program memory.  By default, code generated to read entries in the switch table use special PREAD instructions that can read memory locations with the program memory bus.  If you build with the compiler switch --unified_memory, the compiler presumes that all of memory is accessible to the data memory bus, and then it uses ordinary MOV or MOVL instructions to read entries in the switch table.  Using the PREAD instructions is slightly less efficient in time and code space.

    Thanks and regards,

    -George

  • Hi George,


    Thank you very much for your reply. I have another question.


    You mean:

    By default, the compiler option --unified_memory is NOT enabled (without -mt option), in the linker command file *.cmd I have to allocate the section .switch in program code


                  .switch         : > ....            PAGE=0


    If the compiler option --unified_memory is enabled (with -mt option), I have to allocate the section .switch in the data code.


                  .switch         : > .....           PAGE = 1


    If you are right, do we then have a contradiction to the statement in

                    

    Which statement is correct?

    Thanks in advance - Bui

  • The description in the table is incorrect.  When -mt is not used, .switch must go in program memory.  With -mt, .switch can go in either program or data memory.  I updated EXT_EP-10555 to have a correction made to this table.

    Thank you for pointing out these errors in the compiler manual.

    Thanks and regards,

    -George

  • it seems very logical to me now.

    Many thanks - Bui