Call Lib Routine from Assembly : CW6.4 for Coldfire

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

Call Lib Routine from Assembly : CW6.4 for Coldfire

3,373 Views
BillH
Contributor I
I have an assembly language subroutine
 

asm void DProcess(int16 Index)
{
 // on call D0 contains the index to the channel
 
 
 lea  g_sWaveData, a0          // a0 points to the first data structure
 move.l #SIZE_OF_ANALYSIS_STRUCTS,d1
 mulu.w d0, d1
 asl.l #1, d1            // d1 now contains pointer to the data structure
 adda.l d1, a0
.
.
.

 move.l d4, d0     // setup call
 jsr  sqrt
 move.l d0, 12(a0)
...
 
How do I get the system to recognize that sqrt is a library subroutine?
 
 
Labels (1)
0 Kudos
7 Replies

517 Views
CrasyCat
Specialist III
Hello
 
  I assume you have an ANSI C source code.
 The Coldfire compiler adds a leading _ to symbol names.
 
 So if you want to refer the ANSI C library function sqrt, you need to write JSR _sqrt.
 
 Also make sure that you are passing the parameters to the function in the appropriate way.
 
CrasyCat
0 Kudos

516 Views
BillH
Contributor I
Using _sqrt does not resolve the issue.
 
I still get the following error message:
 
Error   : undefined label '_sqrt'
WaveformAnalysis.c line 105   } 
 
I have attached the entire file for reference.  It contains both an assembly version of the code and a C version of the code.  Note: they are not quite identical.
0 Kudos

517 Views
J2MEJediMaster
Specialist I
The undefined label for sqrt makes me ask: Are you using the math.h header file?

Also, you might want to check the CodeWarrrior Development Studio ColdFire Architectures Edition Build Tools Reference manual, the Inline Assembly and ColdFire Runtime Libraries sections. HTH.

---Tom
0 Kudos

517 Views
BillH
Contributor I
Including MATH.H does not resolve the issue.  If you look at the code attached to the earlier post you will see the C version of the routine also.  If I comment out the  jsr _sqrt line in the assembly version then the file will build and the reference to sqrt() in the C code works just fine.
 
I can't find anything that seems to apply to this in any of the online manuals with Code Warrior.  Do you have any example of calling a subroutine from an assembly language subroutine when the subroutine being called is not in the same file?
 
 
0 Kudos

517 Views
CrasyCat
Specialist III
Hello
 
I did some tests on my side.
If you are using MCF5213, MCF5223x or MCF5222x, CodeWarrior is using reduced size library per default for these parts.
Floating point operations are disabled in reduced size library.
You need to enable floating point arithmetic support in MSL library for these parts if you want to use it.
 
Please refer to following thread for instruction on how to achieve that.
 
Basically you need to update the "ansi_prefix.CF.size.h" and either link against the full size library or generate a library file where floating point arithmetic is enabled.
 
I hope this helps.
CrasyCat
0 Kudos

517 Views
BillH
Contributor I
Please pay careful attention to what I am saying.
 
If I comment out the jsr _sqrt in the assembly code so the file will complie, but leave the sqrt() call in the c code in the same file, then the c code generates assembly
 
;  134:  g_sWaveData.ch[index].rms = sqrt(rms / NUMBER_OF_DATA_POINTS_PER_CHANNEL);
;  135: 
;  136: 
;
0x00000152  0x202EFFE8               move.l   -24(a6),d0
0x00000156  0x2400                   move.l   d0,d2
0x00000158  0xE082                   asr.l    #8,d2
0x0000015A  0x7217                   moveq    #23,d1
0x0000015C  0xE2AA                   lsr.l    d1,d2
0x0000015E  0xD082                   add.l    d2,d0
0x00000160  0x7209                   moveq    #9,d1
0x00000162  0xE2A0                   asr.l    d1,d0
0x00000164  0x4EB900000000           jsr      _sqrt
0x0000016A  0x2D40FFDC               move.l   d0,-36(a6)
0x0000016E  0x202EFFC0               move.l   -64(a6),d0
0x00000172  0x2D40FFF8               move.l   d0,-8(a6)
0x00000176  0x202EFFF8               move.l   -8(a6),d0
0x0000017A  0x222EFFF8               move.l   -8(a6),d1
0x0000017E  0xE989                   lsl.l    #4,d1
0x00000180  0x41F900000000           lea      _g_sWaveData,a0
0x00000186  0x202EFFDC               move.l   -36(a6),d0
0x0000018A  0x2180180C               move.l   d0,(12,a0,d1.l)
0x0000018E  0x4FEF003C               lea      60(a7),a7
0x00000192  0x2E1F                   move.l   (a7)+,d7
0x00000194  0x4E5E                   unlk     a6
0x00000196  0x4E75                   rts     
This results in a call to the long integer version of the sqrt function (NOT A FLOATING POINT CALL).  The linker links to
 
  00004CBC 00000040 .text   sqrt (C_4i_CF_RegABI_MSL.a w_sqrt.o       )
which is a library already in the project.
 
The library is obviously available. The program compiles, links and executes correctly. 
 
With the jsr _sqrt ( also tried jsr sqrt, jsr w_sqrt and jsr _w_sqrt) in the assembly language the error is generated by the COMPILER not the linker.  The fundamental issue is:
 
How does one make the COMPILER recognize a subroutine name in an assembly program where the subroutine is outside the file.
 
 
 
0 Kudos

517 Views
CrasyCat
Specialist III
Hello
 
You mean you have implemented your own sqrt function, which is calculating a square root from a value but is manipulating long int instead of double?
 
If this is the case, I would give another name to the function as sqrt for any C programmer is working with double arithmetic. This might be confusing for everybody.This is a standard ANSI C library function and ANSI defines it to operate on double.
 
Now back to your initial question. If you have your own implementation of sqrt, you need to define a prototype for the function before you invoke it.
Following code snippet works fine to me.
 
Code:
long       sqrt(long) ;asm void DProcess(int16 Index){ // on call D0 contains the index to the channel   lea  g_sWaveData, a0          // a0 points to the first data structure move.l #SIZE_OF_ANALYSIS_STRUCTS,d1 mulu.w d0, d1 asl.l #1, d1            // d1 now contains pointer to the data structure adda.l d1, a0 move.l d4, d0     // setup call jsr  sqrt move.l d0, 12(a0)}
 
CrasyCat
0 Kudos