[Coco] Microware C compiler #asm question

Jeff Teunissen deek at d2dc.net
Fri Apr 2 17:56:41 EDT 2021


The argument offsets from the address in S depend on how large each
argument passed into the function is, as well as how large any local
variables the function has internal to it.

In this case, your function is just a pure assembly function, so it has no
local variables, and the arguments begin at 4,s. Luckily, argument values
will be one of three sizes: 2 bytes (int or char, which will be promoted to
int; also any pointer), 4 bytes (long int), or 8 bytes (double or float,
which is automatically promoted to double).

Your function definition is, by the way, indistinguishable from just doing

#asm
test: pshs u
 lda #...
.....

 puls u,pc
#endasm

Except if you don't need mess with the U register in your function, you can
remove the pshs u at the beginning, and puls u at the end to save a bit of
time, and then you can end the function with rts. Note that this would
change the offset of the arguments from 4,s to 2,s.

The compiler can't use the function definition to do type checking on
function calls, because A) it isn't a prototype (no C compiler does that,
it can only flag that your definition disagrees with the prototype), and B)
our compiler can't process prototypes yet anyway. That's why the snippet
above is _exactly_ equivalent to the quoted C.

On Tue, Mar 30, 2021, 10:43 PM Bill Nobel <b_nobel at hotmail.com> wrote:

> Hey all, I have a question about the Microware C compiler.   When I use
> #asm/#endasm in a function in the following way:
>
> ...
> test(t, sx, sy)
> struct TILE *t;
> int sx, sy;
> {
> #asm
>
>     lda    #...
> .....
>
> #endasm
> }
>
> What is the register layout for entry and how do I get to the parameters.
> I can’t seem to remember right. I know Y is data register and 4,s is the
> pointer/value to the first argument. What’s the rest?
>
> Bill
> Sent from my iPad
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
>


More information about the Coco mailing list