This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Function Pointer - Look Up Table

Hello,

I'm using a 80C51 with the MX - extension in my design.
I want to build up a look up table (ROM) that contains the addresses of several functions. The address of each function must be split into high, middle and low - byte so that i can use it later as a "jump - table" in assembler.

For example:
/* some functions. */
void fA();
void fB();
void fC();

/* Look up table: */
static code LUT [3][3] = {H(fA), M(fA), L(fA), {H(fB), M(fB), L(fC),...

I've already tried some macros which i found in other posts like:

#define L_B(v) (*(((unsigned char *) (&v) + 0)))

This macro doesn't work with function - addresses but works well on common pointers.

Best regards,
Patrick

Parents
  • So that i can use it later as a "jump - table" in assembler.

    Then you had better construct the table in assembler, too. There's only so much you can usefully do in C, and this is at least right on the boundary, if not beyond it.

    And prepare for a deluge of secondary problems caused by doing this. Yes, arrays of function pointers are a clever idea in theory. In practice on 8051-style devices, they tend to cause more trouble than they're worth. It's generally better to use switch() statements, and leave it to the compiler to decide whether to turn them into jump tables or not.

Reply
  • So that i can use it later as a "jump - table" in assembler.

    Then you had better construct the table in assembler, too. There's only so much you can usefully do in C, and this is at least right on the boundary, if not beyond it.

    And prepare for a deluge of secondary problems caused by doing this. Yes, arrays of function pointers are a clever idea in theory. In practice on 8051-style devices, they tend to cause more trouble than they're worth. It's generally better to use switch() statements, and leave it to the compiler to decide whether to turn them into jump tables or not.

Children
No data