[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] arguments in registers instead of stack in gcc

Miro Kropacek wrote:
> is there any way how to force gcc to pass arguments to assembler
> function in some specified registers instead of stack? Some compilers
> allow something like "func(register __a0 int* pointer)" declarations.

It is possible to write an inline function wrapping the call to the assembler function. It seems to work as expected, but I'm not sure it will always be safe...

Let say that asmfunc() is an assembly function taking a pointer in a0 as an argument. You can use the inline function call_asmfunc() from your C code.

$ cat paramreg.c
static __inline__ void call_asmfunc(int* pointer)
        register int* param __asm__("a0") = pointer;

        __asm__ volatile
        ("jsr _asmfunc"
        :			/* outputs */
        : "g"(param)		/* inputs */
        : "d0", "d1", "a1" 	/* clobbered regs */

int arr[3];

void test()

$ m68k-atari-mint-gcc -S paramreg.c -o - -O2 -fomit-frame-pointer
        .globl  _test
        lea _arr,%a0
| 5 "paramreg.c" 1
        jsr _asmfunc
| 0 "" 2
.comm _arr,12

Vincent Rivière