home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!news.service.uci.edu!orion.oac.uci.edu!eapg070
- From: eapg070@orion.oac.uci.edu (Caroll Elke Pohl)
- Subject: Calling assembly from C
- Nntp-Posting-Host: orion.oac.uci.edu
- Message-ID: <2B639791.18213@news.service.uci.edu>
- Summary: using #pragma parameter doesn't work
- Newsgroups: comp.sys.mac.programmer
- Organization: University of California, Irvine
- Keywords: C,assembly
- Lines: 63
- Date: 25 Jan 93 07:32:33 GMT
- Distribution: usa
-
- thanx to the many who responded to my earlier post.
- i took your suggestions but still i am stymied.
-
- for those who don't remember, the challenge is to call an assembly language
- routine from C passing the parameters in registers (using MPW 3.3).
- towhit, i wrote the following source files:
-
- /* test.c */
- #pragma parameter __D0 PLUS(__D0,__D1)
- long PLUS (long,long);
-
- main ()
- {
- long i,j,k;
- i = 1;
- j = 2;
- k = PLUS (i,j);
- }
-
- and of course:
-
- ;test.a
- PLUS proc EXPORT
- add.l d1,d0
- rts
-
- END
-
- when linked together you would hope the C code would place i in D0,
- j in D1, a JSR to PLUS and finally D0 placed in k.
-
- in fact however, i and j are pushed onto the stack and the whole program
- fails miserably.
-
- as several good people pointed out, the syntax for these #pragma parameter
- statements can be found in "Memory.h". however, in these declarations,
- the routines in question are really traps so they're declared more like
-
- #pragma parameter __D0 FoobarTrap(__A0)
- long FoobarTrap (void*)=0xAAAA;
-
- which, as you may surmise, inserts the trap 0xAAAA instead of a standard
- JSR. just for the fun of it, i declared my routine in this fashion to see
- how it would compile and, sure enough, i and j got placed in D0 and D1.
- of course the code was otherwise useless but it proved a point (what, i'm
- not sure).
-
- so, can anyone explain this and/or offer a solution?
- i'm at my wits end.
-
- help!
- please e-mail
-
- -caroll
-
- p.s., to the guy who suggested an inline jsr, i only wish MPW did
- inline assembly!
-
- ) """ (
- (Q Q)
- Don't spook ( | )
- the horse! \ A /
- (___)
-