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.

Difference in ++/-- between assembly and C

Anonymous
Anonymous

Hi,

 

I would like to ask a question on addressing modes in C6000.

 

I experimented with load/store address generation, and found a difference between ++/-- result with C-style:

 

 

For C, the increment/decrement is always unit, but is ucst5 for Load/Store assembly instructions. I initially find it strange, but then I thought it is perhaps because:

 

1.    In C, ++/-- are most commonly used as loop counter, and the real increment/decrement depends on the context. It is also convenient to multiply the loop counter with another constant for other calculations. Therefore, unit increment is convenient and intuitive.

2.    For assembly especially in Load/Store operations, since they are commonly used in conjunction with a loop to copy blocks of data, using ucst5 as increment/decrement avoid additional multiplication (time expensive) or addition, and is quite natural and convenient particularly for these instructions.

 

 

So is this the reason? Could anyone provide some comments on this?

  

   

 

Zheng

  • In C, x++ has exactly the same effect on x that x+=1 does.  If x is a pointer, this means x advances past one object of the type it is pointing at.  Depending on the type of the pointer, this could be an arbitrarily large number of bytes.  This is the case you need to compare to the assembly syntax.

    In the C6x assembly, the ++ operator is only used on pointers.  The A5++[N] form is a generalization of the C syntax; it advances the pointer past N units of the type of the access (byte, short, word, doubleword).

  • Anonymous
    0 Anonymous in reply to Archaeologist

    Archaeologist ,

    Archaeologist said:

    If x is a pointer, this means x advances past one object of the type it is pointing at.  Depending on the type of the pointer, this could be an arbitrarily large number of bytes.  This is the case you need to compare to the assembly syntax.


    I tested this and it was the case. Thanks very much for clarification.
     
      
    Zheng