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.

Compiler/TMS320F28023: What am I missing, bit shift left

Part Number: TMS320F28023


Tool/software: TI C/C++ Compiler

I have the following code snippit:

void To523(float param_dec, uint16* param_hex) {
long param223;
long param227;

#define one_23 0x800000
#define one_27 0x8000000

param223 = param_dec * (1L << 23);		//multiply decimal number by 2^23  (convert float to long)
param223 = param_dec * (one_23);		//multiply decimal number by 2^23  (convert float to long)

And here is the resulting assembly code...

 32     param223 = param_dec * (1L << 23);		//multiply decimal number by 2^23  (convert float to long)
3f1234:   9A00        MOVB         AL, #0x0
3f1235:   28A84B00    MOV          @AH, #0x4b00
3f1237:   1E42        MOVL         *-SP[2], ACC
3f1238:   0644        MOVL         ACC, *-SP[4]
3f1239:   767F2A41    LCR          FS$$MPY
3f123b:   767F2B78    LCR          FS$$TOL
3f123d:   1E48        MOVL         *-SP[8], ACC
 33     param223 = param_dec * (one_23);		//multiply decimal number by 2^23  (convert float to long)
3f123e:   9A00        MOVB         AL, #0x0
3f123f:   28A84B00    MOV          @AH, #0x4b00
3f1241:   1E42        MOVL         *-SP[2], ACC
3f1242:   0644        MOVL         ACC, *-SP[4]
3f1243:   767F2A41    LCR          FS$$MPY
3f1245:   767F2B78    LCR          FS$$TOL
3f1247:   1E48        MOVL         *-SP[8], ACC

So you will see the two C instructions compile into identical code, that is good, the compiler noticed that 1L << 23 is a constant.

But, my question is, "Shouldn't the first 2 assembly instructions load the ACC with 0x800000? I see it is being loaded with 0x4b000000. Why?

Thanks, Mark.

  • Cool Javelin said:
    Shouldn't the first 2 assembly instructions load the ACC with 0x800000? I see it is being loaded with 0x4b000000. Why?

    Because the expression, with all the type changes made explicit, is ...

    param223 = (long) (param_dec * (float) (1L << 23));

    When the integer value (1L << 23) is converted to 32-bit IEEE float representation, the binary bits of that value form the hex string 0x4b000000.  

    Thanks and regards,

    -George

  • George:

    I understand now.

    I am trying to convert floating point coefficients into fixed point (5.23) integers for use in an ADAU1701.

    I have some sample C code from Analog Devices. I will have to do more research and get with them for more info. Their code does not have the 'L' after the 1, so my compiler was treating the 1 as a 16bit number. I am beginning to wonder about the sample code.

    While I have lots of experience coding in general, I have limited experience using floating point (and the bigger doubles.) so this has been added to my learning curve.

    Thanks for the tip. I will try to remember how things get converted by the compiler in formulas.

    Mark.