user6499716
user6499716

Reputation:

Assembly function called from c is ignored

I am calling a function called fpow which is implemented in ARM assembly.

extern float fpow(float x, float y);

int main()
{
    //...
    R = fpow(x, y);
    //...
}

The problem is that R contains x after the call. It seems like the function is not doing anything and since r0 is the return register it looks like fpow is returning x.

Here is the ARM assembly implementation:

.globl fpow

fpow: 

  stmfd sp!, {r4, r5, r6, lr} 


  mov r4, r0 
  mov r5, r1 


  mov r1, #0 

  bl __aeabi_fcmpeq 
  ...      
  bl __aeabi_fmul 
  bl pow2 
  ldmfd sp!, {r4, r5, r6, pc} 

Upvotes: 0

Views: 168

Answers (2)

Peter Cordes
Peter Cordes

Reputation: 363980

What options are you using to compile your C? Are you using -mfloat-abi=hard or soft?

If soft, the C compiler will expect the fpow return value as a float (IEEE binary32) bit-pattern in r0.

A calling-convention mismatch would explain seeing the first arg as return value:

If the C compiler's asm is using the hard float-ABI, the first FP arg-passing register (s0) is also the FP single-precision return-value register. If your hand-written asm is written for the soft float ABI, it won't modify s0.

Upvotes: 1

SoronelHaetir
SoronelHaetir

Reputation: 15164

Your extern declares powf but you call (and appear to implement fpow). Fix it so that all three match, Right now I suspect (though am not certain) that you are running into an issue with C's handling of undeclared functions.

Upvotes: 1

Related Questions