asm function in c code

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone
I need to include an asm-function at c code. The function looks like:

int test(int *ptr_test, int test_size);

I created asmroutine.h file where my function is declared and then .s file where the function written in asm exists. I call the function with parameters in .c and there weird things start to happen:

While debugging, i put a breakpoint at the function calling in .c code, then step inside and continue - everything works perfectly; It doesn't work without a breakpoint, ended up in dummy_handler and it never enter an asm-func (I put a bp inside asm)

Maybe I was wrong in declaring and compiller cannot find a right way to asm-code, But with a BP it does. 

 

I provided mentioned files, the target func is cycloner

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I looked through the .c/.h files and see a few weird things but nothing completely horrible.  Things like passing const data to non-const functions, unsigned int length calculations passed to signed int functions (possible overflows), etc.  Although it could be cleaned up it's probably not the source of the problem.

 

Honestly I don't have the patience to trace through the ASM code.  But here's what I recommend to help solve your problem:

 

1.  Create the same ASM routine as simply as possible as a function in a separate file in C code

2.  Use the compiler to generate the intermediate .S code via the appropriate compiler options

3.  Compare the compiler generated ASM code to your original ASM code

 

Be sure to post your findings once you solve this.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One other thought:  the cycloner function appears to be manipulating the passed data four bytes at a time.  What happens if you pass a starting address not aligned on four byte boundaries?  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you need a magic pseudo-op to make “cycloner” have an odd value (indicating a thumb function)?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for paying attention!

But I had no problem with asm, I needed to include it right. The address is from object file stored in cpu flash, so it has to be 4-byte (if i understand you correct)

Well, I tried to include my asm code in .c file itself through __asm__ volatile (";") so there is no cycloner function anymore. Still cannot use breakpoints inside, but in Disassembly while debugging, i see, my device goes through asm code