[Coco] Calling convention used by older 6809 C compilers

Pierre Sarrazin sarrazip at sarrazip.com
Tue Jun 25 00:46:15 EDT 2024


Dixit William Astle via Coco (2024-06-24 09:44):
> On 2024-06-23 20:46, Pierre Sarrazin via Coco wrote:
> > Your specification says that "all arguments go on the stack for
> > variadic functions", but does that still apply to the hidden
> > parameter that points to a struct return value?
> 
> I believe it is passed on the stack but I didn't test that particular
> permutation.

It is indeed.

I finally got gcc6809 to half-work on my machine, and I was able to
look at the generated asm. This C function:

    struct LargeStruct { long foo; };

    struct LargeStruct f4v(int a, ...) {
        struct LargeStruct s;
        s.foo = 0xABCD1234L;
        return s;
    }

gives this asm:

    _f4v:
            pshs    y,u
            leau    ,s
            ldx     6,u
            ldy     #-21555
            sty     ,x
            ldy     #4660
            sty     2,x
            puls    y,u,pc

The ldx instruction loads the struct return address from the stack.

Argument 'a' is at 8,u.

The situation is the same for the 1- and 2-byte struct cases.

-- 
Pierre Sarrazin <sarrazip @ sarrazip . com>


More information about the Coco mailing list