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.

why ACC is used for unsigned int casting

Hi

  I am copying the part of .lst file where in i just want the 16bits for computation, but the compiler is using the ACC and screwing up the operation. I hope the question is clear enough. If not please let me know.

     426              ; 131 | *pObject_Data++ = ((unsigned int)(data[i+1] << (unsigned char)8) | data[i]);
     427              ;                                                                      
     428              ; 132 | else                                                                  
     429              ;----------------------------------------------------------------------
     430 00000082 9247          MOV       AL,*-SP[7]            ; |131|
     431 00000083 9C01          ADDB      AL,#1                 ; |131|
     432 00000084 8344          MOVL      XAR5,*-SP[4]          ; |131|
     433 00000085 58A9          MOVZ      AR0,AL                ; |131|
     434 00000086 5947          MOVZ      AR1,*-SP[7]           ; |131|
     435 00000087 8A44          MOVL      XAR4,*-SP[4]          ; |131|
     436 00000088 5603          MOV       ACC,*+XAR5[AR0] << #8 ; |131|
         00000089 0895
     437 0000008a CA9C          OR        AL,*+XAR4[AR1]        ; |131|
     438 0000008b 8A46          MOVL      XAR4,*-SP[6]          ; |131|
     439 0000008c 2BAA          MOV       PH,#0
     440 0000008d 28AB          MOV       PL,#1
         0000008e 0001
     441 0000008f 5657          ADDUL     P,XAR4
         00000090 00A4
     442 00000091 A946          MOVL      *-SP[6],P             ; |131|
     443 00000092 96C4          MOV       *+XAR4[0],AL          ; |131|
     444 00000093 6F07          B         L10,UNC               ; |131|

 

Thanks

Manju

 

  • Manju,

    I don't think that the compiler is 'screwing up' something in your code snippet. I guess you know that AL is the lower 16 bit part of ACC, so the OR-instruction in line 436 is performed correctly.

    Her is my "reading" of your code:

    Line 430:  reads variable i from stack (stackpointer minus 7) into AL

    Line431: adds 1 to AL

    Line 432: reads the start address of "data" from SP-4 into register XAR5

    Linr 433: load "i+1" from AL into AR0

    Line 434: load "i" from SP-1 to AR1

    Line 435: load start address of "data" from, SP-4 into register XAR4

    Line 436:  load the 16-bit number (MOV) from XAR5+AR0 (data[i+1]), left shifted by 8 into AL, with sign extension into AH ( 16bit <<8 = 24 bit)

    Line 437: perform a logical OR between the value in AL ( the lower 8 bit from data[i+1], now in the upper byte of AL an eight zeros in the lower byte of AL) and store the result in AL

    Line 438: read the pointer "pObject_Data" from SP-6 (and SP-5) into register XAR4

    Lines 439/440 load a 32bit number 1 into register P

    Line 441 Add XAR4 and P ( that is the post increment of the pointer), result is in P

    Line442:  Store the incremented pointer back into Stack SP-6 and SP-5

    Line 443: Stor the result of the OR - instruction (AL) back into memory, pointed to by XAR4 (that is the pointer "pObject_Data", before the increment)

    Summary:

    Your assembly code does a logical or between the lower 8 bit of data[i+1] (because data[i+1] is shifted left 8 times) and the full 16 bit size of data[i]. That's also, what your C code says.

    If your intention was to compress the lower 8 bit of data[i+1] and the lower 8 bit of data[i] into a new 16-bit data, then the correct C line would be:

    * pObject_Data++ = ((unsigned int) ((data[i+1] <<8) | (data[i] & 0x00FF))) 

    AND:

     Your line 426 contains 4 opening brackets '(' but only 3 closings ')'.....    - so please check your C-code.

     

     

     

  • Manju,

    sorry, forget  the last statement in my previous reply, after finding my eyeglasses I spotted the missing closing bracket number 4....

    Frank

     

  • Thanks Frank