Yahoo Groups archive

Lpc2000

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

Message

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?

Attachments

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.