assembly function embedded in C++ source file does not compile

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

assembly function embedded in C++ source file does not compile

3,405 Views
Veter
Contributor I
I have assembly function in C++ source. It compiles under DIAB, but does not compiles with CW for ColdFire. Could anyone tell what needs to be changes in the function in order for it to compile and work?
 
Function:
asm int tm_asm_checksum (register int loopCount,register tt32Bit dataPtr,register tt32Bit checksum)
{
%   reg loopCount; reg dataPtr; reg checksum; lab CHECKSUM_LOOP
;/* Set branch counter to number of times to iterate through loop */
   mtspr   9,loopCount
   addi    dataPtr,dataPtr,0xFFFC
   
;/* Clear the carry bit */
   addic   checksum,checksum,0
                     
CHECKSUM_LOOP:
   lwzu    r6,4(dataPtr)
   adde    checksum,r6,checksum
   bdnz    CHECKSUM_LOOP
;/*
; * In case there was a carry due to the last addition, add the carry bit back
; * in to the sum ( checksum = checksum + 0 + XER[carry] ).
; */
   xor     r6,r6,r6
   adde    checksum,r6,checksum
   addi    r3,checksum,0
}
Labels (1)
0 Kudos
Reply
6 Replies

979 Views
SimonMarsden_de
Contributor II
Hi Veter

The in-line assembler code is for a PowerPC processor, not ColdFire! The ColdFire equivalent is something like:

int tm_asm_checksum (int loopCount,tt32Bit dataPtr,tt32Bit checksum)
{
 asm {
     move.l    checksum,d0       // Build result in D0
     move.l    dataPtr,a0        // A0 -> data
     move.l    loopCount,d1      // D1 holds loop count
     clr.l     d2
 CHECKSUM_LOOP:
     add.l     (a0)+,d0          // Add next value into checksum
     addx.l    d2,d0             // Also add in the carry
     subq.l    #1,d1
     bne       CHECKSUM_LOOP
 }
}   


This is not quite step-for-step equivalent - because the SUBQ instruction on ColdFire changes the Carry flag, it's been restructured slightly. However I believe (hope!) that it will give the same result.

By the way, neither the PowerPC example nor the ColdFire version zeros out 'checksum' before executing. I assume that this is done by the caller. The code also doesn't check for a loop count of 0.


Hope this helps


Simon
0 Kudos
Reply

979 Views
Veter
Contributor I
Simon, thank you very much. This is the most helpfull unswer that could only hope for. Strength and Honor
0 Kudos
Reply

979 Views
mccPaul
Contributor I
Hi Veter,
 
It will be easier to help if you can state the version of CW you are using and also to give the compiler error.
 
Cheers,
 
Paul.
0 Kudos
Reply

979 Views
Veter
Contributor I
I'm using CodeWarrior Development Studio for ColdFire Architectures Version 6.3, Build 14
Below are the compiler errors.
Thank you!
 
Error   : illegal type qualifier(s)
trcsppcd.c line 51   { 
Error   : illegal token
trcsppcd.c line 52   %   reg loopCount; reg dataPtr; reg checksum; lab CHECKSUM_LOOP 
Error   : ':' expected
trcsppcd.c line 52   %   reg loopCount; reg dataPtr; reg checksum; lab CHECKSUM_LOOP 
Error   : label 'reg' redefined
trcsppcd.c line 52   %   reg loopCount; reg dataPtr; reg checksum; lab CHECKSUM_LOOP 
Error   : ':' expected
trcsppcd.c line 52   %   reg loopCount; reg dataPtr; reg checksum; lab CHECKSUM_LOOP 
Error   : ':' expected
trcsppcd.c line 55       mtspr   9,loopCount 
Error   : function has no initialized stackframe
trcsppcd.c line 57       addi    dataPtr,dataPtr,0xFFFC 
Error   : ':' expected
trcsppcd.c line 60       addic   checksum,checksum,0 
Error   : ':' expected
trcsppcd.c line 63       lwzu    r6,4(dataPtr) 
Error   : ':' expected
trcsppcd.c line 64       adde    checksum,r6,checksum 
Error   : ':' expected
trcsppcd.c line 65       bdnz    CHECKSUM_LOOP 
Error   : ':' expected
trcsppcd.c line 71       xor     r6,r6,r6 
Error   : label 'adde' redefined
trcsppcd.c line 72       adde    checksum,r6,checksum 
Error   : illegal addressing mode
trcsppcd.c line 74       addi    r3,checksum,0 
 
0 Kudos
Reply

979 Views
Kremer
Contributor I
Hi Veter
 
 I´m not sure what is wrong with the code warrior but you can edit the target settings for the C/C++ language by accessing the target settings (ALT+F7) and editing the Language Settings - C/C++ Language options as the ColdFire_Build_Tools_Reference.pdf tells to do.
0 Kudos
Reply

979 Views
CrasyCat
Specialist III
Hello
 
Inline assembler is different between Diab and Freescale.
Please refer to the ColdFire_Build_Tools_Reference.pdf manual chapter "Inline Assembler" for information on supported inline assembler syntax.
 
%   reg loopCount; reg dataPtr; reg checksum; lab CHECKSUM_LOOP
for example is surely not understood by Freescale inline assembler.
 
If you are not able to get a compilable source code, you need to submit a service request  for that.
 
To log the issue please go to following URL:
    http://www.freescale.com/TechSupport
and click on "Submit a service request"
 
Make sure to attached a project reproducing the issue as well as installed products information.

  To retrieve that info:
    - Start CodeWarrior
    - Select Help -> About Freescale CodeWarrior
    - Click on "Install Products"
    - Click on save as and save content of the dialog to a text file that you will attach to the SR.

Finally make sure to explain what you intend to do (i.e. what the Diab notation were supposed to do).

I hope this helps.

CrasyCat
0 Kudos
Reply