C51: a lot of values assignment

Hi,

In my C code, I need to assign a lot of values.
Like this:
a1,a2,... are variables as char.
v1,v2...,w1,w2...y1,y2 are constant (like 0x00, 0x01, ...etc)

if (i==0){
a1 = v1;
a2 = v2;
...
a50=v50;
} else if (i==2){
a1 = w1;
a2 = w2;
...
a50=w50;
} else if (i==3){
a1 = y1;
a2 = y2;
...
a50=y50;
} else {
}

I would like to minimize the code memory usage as possible.
Which coding style or method is suggested to implement it ?
Should I declare "array" or use " #define " ?
Please kindly provide suggestions. Thanks a lot!

Parents
  • #define doesn't remove any assigns.

    Definitely consider using arrays. Just remember that 8051 chips aren't exactly loving work with arrays because a bit of lack of addressing modes.

    Another thing - should you really assign 50 values? Or have change one pointer to point to a struct/array containing the specific set of 50 values? Is it real variable variables or do you use them as constants, where it would be possible to have them stored in code memory?

Reply
  • #define doesn't remove any assigns.

    Definitely consider using arrays. Just remember that 8051 chips aren't exactly loving work with arrays because a bit of lack of addressing modes.

    Another thing - should you really assign 50 values? Or have change one pointer to point to a struct/array containing the specific set of 50 values? Is it real variable variables or do you use them as constants, where it would be possible to have them stored in code memory?

Children
More questions in this forum