Eric House writes:
> On Tue, 31 Aug 1999, John Marshall wrote:
>> The `"a"'s say to put the parameters (s and d) into _a_ddress registers,
>> the %k notation refers to whichever register it chose for the corresponding
>> parameter,
> 
> Is it safe to assume that this is integrated with the compiler's register
> allocation scheme?

Absolutely -- this is what I was trying to convey when I said "whichever
register it chose [...]" :-).  `%0' refers to the the asm's 0th parameter
(i.e., the variable  d); it certainly doesn't mean it has to be in A0.

You have to be sure not to clobber registers that the compiler is using
without telling it.  There is an example of this in the manual section.

> Is there any alternative syntax available for situations where the
> programmer wants to take responsibility to allocating registers
> him/herself?

Yes -- you tell the compiler that you're going to clobber all the registers,
or you save and restore them yourself.  There's examples in the manual and
in the prc-tools startup code.

> I have some functions I'd like to rewrite in assembler,
> from the LINK down to the RTS.  I'd love to be able to use macros to
> give symbolic names to local variables and formal parameters, etc., but
> perhaps that's asking too much.

So what you really want to do is write some of your functions in C and
others in macro assembler.  Well, people have been doing this for decades!
You can just declare a function in a header file and then write the function
in a .s file, using whatever registers it likes (*), and when you assemble
that file, compile and assemble the others, and then link them all together,
the others will never know the difference!

There's a (pathetic!) example of this in the multiapp example on my web
page.  But really the best thing to do is just play around with the `-S'
option.  GCC is a very old fashioned compiler that compiles into assembly
language, which is then fed to the assembler.  The `-S' option allows you
to look at the asm before it gets to the assembler, and to vandalise it if
you want to.  This can be very instructive.  :-)

> but maybe it was (also)
> asking too much to be able to write the kind of 68K code I once fed to
> MPW and Think C.  Or maybe I could get used to this if I tried. :-)

Writing different parts of a program in different languages like this is
one of the miracles of separate compilation.  Writing whole functions in
inline assembly inside a .c file is a kludge -- but nonetheless you *can*
do it and it's only ugly at the edges.  Again, there are examples in the
prc-tools startup code.

That example was only obscure because it was small and all on one line.
The other examples out there look more like what you're used to.

    John

(*  As long as it follows the ABI:  functions must preserve A2-A6/D3-D7
and return scalars in D0 and pointers in A0.)

Reply via email to