Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Thread

calling asm routine from c

calling asm routine from c

2004-12-19 by radoslaw_mitura

I have two parts in my program - bootloader that run from the start 
of processor (written in asm) and target application written in c.
At start of processor the loader is runing from flash and copy target 
application from flash to ram, then execute it.
The loader has inital procedures and functions to handle i/o 
operation with serial port (GetChar, PutChar, InitPort). There is no 
problem with the serial if using them from assember (I know which 
registers use and I don't use stact at this functions).
Now I don't want to double the same procedures in c code but I want 
to call the GetChar, PutChar, etc from C code, but I have problem 
with register overwrite used by c code by asm code.
The problem I have is with function:
int GetCharTimeout(int timeout)
The input and output parameters are transfered thru R0 register.
But the function is using R1 and R2 registers too.
Q: How to tell the C code that function in assembler uses R1 and R2 
registers to put it on stack before call. Now I'm doing it in this 
way:
int getChar(int timeout) {
  int ret;
  _asm { 
    push {r1,r2}
    bl GetChar 
    pop {r1,r2}
    mov ret, r0
  }
  return ret;
}
Is there any other way to do the same simplier?

Re: [lpc2000] calling asm routine from c

2004-12-19 by Robert Adsett

At 08:13 PM 12/19/04 +0000, you wrote:
>The problem I have is with function:
>int GetCharTimeout(int timeout)
>The input and output parameters are transfered thru R0 register.
>But the function is using R1 and R2 registers too.
>Q: How to tell the C code that function in assembler uses R1 and R2
>registers to put it on stack before call. Now I'm doing it in this
>way:
>int getChar(int timeout) {
>   int ret;
>   _asm {
>     push {r1,r2}
>     bl GetChar
>     pop {r1,r2}
>     mov ret, r0
>   }
>   return ret;
>}
>Is there any other way to do the same simplier?

This may be a bit pedantic, but I'd write an assembly shell that conforms 
to the procedure call standard for the ARM and use it to call your assembly 
routine. The C call should then be just about transparent.

Or you could just rewrite your existing routines to conform to the standard.

Robert

" 'Freedom' has no meaning of itself.  There are always restrictions,
be they legal, genetic, or physical.  If you don't believe me, try to
chew a radio signal. "

                         Kelvin Throop, III

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.