A.D.A. Amiga Demoscene Archive

        Welcome guest!

  

  

  

log in with SceneID

  

Demos Amiga Demoscene Archive Forum / Coding / Parameters from assembler to stormcpp

 

Author Message
PeabrainC64
Member
#1 - Posted: 23 Mar 2016 02:31
Reply Quote
hello,

yes in the topic is the problem.
i got a assembler function like ....

xdef _test
_test:
add.l d1,d0
rts

and a declaration like this ...

extern "C" int test(register int __d0,register int __d1);

and the call z = test(1,3); gives a various number.

so my question. how must i change the declaration of test, that it returns me the d0-register?

extern "C" register int test(register int __d0,register int __d1) __d0; doesn't work.

thank you and best regards,
peabrain
chainq
Member
#2 - Posted: 24 Mar 2016 20:57 - Edited
Reply Quote
Well, I'm not a C guy, and I don't know Storm CPP (yuck...) but:

Do one even needs to specify it? I mean unlike with parameters, return values are actually documented to be returned in D0 by the Amiga ABI (and in general on m68k, most if not all systems follow that).

The Amiga ROM Kernel Reference Manual (Third Printing, September 1986) in Preface, Page iv says:

"REGISTER CONVENTIONS

All system functions follow a simple set of register conventions. The conventions apply
when any system function is called; programmers are encouraged to use the same conventions
in their own code.

The registers D0, D1, A0, and Al are always scratch; they are free to be modified at any
time. A function may use these registers without first saving their previous contents.
The values of all other data and address registers must first be preserved. If any of
these registers are used by a function, their contents must be saved and restored
appropriately.

If assembly code is used, function parameters may be passed in registers. The conventions
in the preceding paragraphs apply to this use of registers as well. Parameters
passed in D0, D1, A0, or A1 may be destroyed. All other registers must be preserved.
If a function returns a result, it is passed back to the caller in D0. If a function returns
more than one result, the primary result is returned in D0 and all other results are
returned by accessing reference parameters.

The A6 register has a special use within the system, and it may not be used as a parameter
to system functions. It is normally used as a pointer to the base of a function vector
table. All kernel functions are accessed by jumping to an address relative to this
base."


So I think all C (and other) compilers respect this ABI on Amiga, or something very close to this. Some compilers actually use D1 to return the upper half of a 64bit result, that is not documented there, and is not a problem, because D1 is declared as scratch anyway.

If you get weird results, remember, int might be 16bit only (depending on compiler settings?), which would affect both the parameter passing and the return value as well.

 

  Please log in to comment

  

  

  

 

A.D.A. Amiga Demoscene Archive, Version 3.0