Re: calling assembly language routines from 'C'



On Apr 8, 9:30 am, 2Penny <lw_rog...@xxxxxxxxxxxxx> wrote:
Thank you Stephane. Any pointers are appreciated and I can
verify (and I intend to) via the ARM website and the ARM Thumb
Proceedure Call Standard. Good stuff !! My 'C' seems to be
rusty though. I haven't looked yet, but is there example
code that can be adapted of the 'C' call and the responding
ASM code?

Without going further though, this is a help.

Thanks again,

2Penny

Stephane wrote:
On Apr 7, 5:16 pm, 2Penny <lw_rog...@xxxxxxxxxxxxx> wrote:

Gentlemen;

I've written a couple of routines in ARM assembly language because
I've gotten to work in assembly language a lot for a number of years
and I've now gotten to work with an ARM
assembler/compiler/debugger/downloader, ARM9 equipped board and JTAG
unit and I've built up assembly language versions of getchar()
and putchar(). The routines work fine inside an ASM program
called "echo" and I'd like to use these routines in a 'C'-ish
program called "echo".

So how does one call ASM routines from 'C'? Can anyone here
point me in the right direction?

2Penny (as in "that's my 2 cents worth")

Hi,

If you want complete information, you can find it on ARM website. What
you are looking for is the "Arm Thumb Procedure Call
Standard" (ATPCS).
In brief, you call your asm function by its symbol (you need to export
it from your asm source), with in consideration that your parameters
will be passed in order in r0-r4, and the return value will be read in
r0. If you have more than two parameters, parameters from the 5th on
are passed on the stack. If you use complex data (bigger than an int)
be aware that, when counting your argument registers, they will
require as many registers as they size in "int size unit".

You might need to modify your ASM if it doesn't comply with these
rules. (Or maybe you can specify another ABI instead of ATPCS, but my
knowledge reaches its limit there.)

Cheers,

Stephane

Hi Stephane,
Is Thumb PCS necessary for calling a asm
routine? I mean, the standard APCS(ARM Procedure Call Standard) is
what should be sufficient. Also would the processor need to be changed
to thumb mode at the start of each routine in assembly while using
ATPCS? Of course if it is thumb mode instructions, it is, otherwise
it shouldn't be necessary at all. My guess is using the standard APCS
would do just fine, unless there is arm-thumb interworking involved,
isn't it?

Regards,
Ankit Chaturvedi

.



Relevant Pages

  • Re: Some advice about references on memory management in C
    ... >> All local variables are located on stack, ... generated by the compiler and is ultimately delt with by the linker. ... Not one that is generally valid or refelcts exactly what the standard says, ... but rules of thumb ...
    (comp.lang.c)
  • Re: calling assembly language routines from C
    ... properly with the ASM routines I was almost whooping. ... verify via the ARM website and the ARM Thumb ... ASM code? ... I've gotten to work in assembly language a lot for a number of years ...
    (comp.sys.arm)
  • Re: where can i download bsp for SA11X0BD
    ... Not surprisingly a Google search on "ARM Thumb" brings this up as the #1 ... > Dear Bruce Eitman ... > Can you tell me waht is the meaning of the word "Thumb". ... >> beitman AT applieddata DOT net ...
    (microsoft.public.windowsce.platbuilder)
  • Re: where can i download bsp for SA11X0BD
    ... Not surprisingly a Google search on "ARM Thumb" brings this up as the #1 ... > Dear Bruce Eitman ... > Can you tell me waht is the meaning of the word "Thumb". ... >> beitman AT applieddata DOT net ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Access violation at the end of the program
    ... supported by other compilers or even other versions of the same compiler. ... As a rule of thumb, ... committee is considering including these safe versions to the standard. ...
    (microsoft.public.vc.language)