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

Code efficiancy

Hi all,
My code is based on C and I have a lot of cases where I assign a value to a variable. Is it more efficiency to just place the value or first to check if the variable already has this value?
I made two identical sample codes where in one code I had only an assignment of a value and in the other one I had verification first. I see that the CODE area in the second sample was bigger then the first one.
If CODE area is smaller, it's not mean that all code is more efficiency.
Any ideas?

Ruven

Parents
  • Hi,
    ...if the variable already has this value
    What do you mean?

    Next construction:
    if (a != 9) a=9;
    has no sense with the exception of writting into cycle-limited areas (for example, EEPROM, FLASH etc).

    Btw, another way to assign a value to a variable is make it via array; something like it:

    static unsigned char array[256] = {value1, value2, ...};

    a = array[x];

    such way should work fast if compiler translates it in MOVC A,@A+DPTR - just one assembly command.

    Good days!


    Good days!

Reply
  • Hi,
    ...if the variable already has this value
    What do you mean?

    Next construction:
    if (a != 9) a=9;
    has no sense with the exception of writting into cycle-limited areas (for example, EEPROM, FLASH etc).

    Btw, another way to assign a value to a variable is make it via array; something like it:

    static unsigned char array[256] = {value1, value2, ...};

    a = array[x];

    such way should work fast if compiler translates it in MOVC A,@A+DPTR - just one assembly command.

    Good days!


    Good days!

Children