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

problem using idata in calculations

Hi,

Is there a problem using idata for variables used in "heavy"calculations ?

( heavy = 3 products 2 sums in a same instruction)

I use microvision 1.30 dll 1.30 C compiler v5.20

In my program some calculations produce good results when used with data and wrong and changeant results when used with idata.



Thanks.
Gregory.

Parents
  • Can you give any indication of the maximum stack depth the compiler could use when evaluating an arbitrarily complex expression?

    The compiler only stacks temporary results when absolute required. Typically, this is only required in complex expressions using long or float types which include function calls.

    For example, consider the following:

    long a,b,c,d,e;
    
    e = (a*b) + (c*d);

    In this case, the compiler multiplies a and b, then multiplies c and d, and finally adds the two products. Long multiplications are performed by a compiler function ?C?LMUL. The two multiplicands are loaded into R0-R3 and R4-R7. The result is returned in R4-R7.

    So, in the above example, after (a*b) is multiplied, the result must be saved (on the stack) and then (c*d) can be calculated. Thus, for this example 4 bytes of stack space are used.

    If we complicate the example:

    long a,b,c,d,e,f,g;
    
    e = (a*b) + (c*d) + (f*g);

    Still, only 4 bytes of stack space are used.

    In theory, the maximum stack space that may be used is not limited by the compiler. So, it is possible that the microcontroller could run out of stack space.

    In reality, it is extremely difficult to create statements so complex that they require more than 8-10 bytes of stack space.

    Jon

Reply
  • Can you give any indication of the maximum stack depth the compiler could use when evaluating an arbitrarily complex expression?

    The compiler only stacks temporary results when absolute required. Typically, this is only required in complex expressions using long or float types which include function calls.

    For example, consider the following:

    long a,b,c,d,e;
    
    e = (a*b) + (c*d);

    In this case, the compiler multiplies a and b, then multiplies c and d, and finally adds the two products. Long multiplications are performed by a compiler function ?C?LMUL. The two multiplicands are loaded into R0-R3 and R4-R7. The result is returned in R4-R7.

    So, in the above example, after (a*b) is multiplied, the result must be saved (on the stack) and then (c*d) can be calculated. Thus, for this example 4 bytes of stack space are used.

    If we complicate the example:

    long a,b,c,d,e,f,g;
    
    e = (a*b) + (c*d) + (f*g);

    Still, only 4 bytes of stack space are used.

    In theory, the maximum stack space that may be used is not limited by the compiler. So, it is possible that the microcontroller could run out of stack space.

    In reality, it is extremely difficult to create statements so complex that they require more than 8-10 bytes of stack space.

    Jon

Children