home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!world!siegel
- From: siegel@world.std.com (Rich Siegel)
- Subject: Re: Think C & #pragma parameter (was: help calling assembly from C)
- Message-ID: <C1E4Hz.5BA@world.std.com>
- Organization: GCC Technologies
- References: <2B6198C1.22487@news.service.uci.edu> <keith-240193173019@kip-50.taligent.com> <1jvlnrINNst4@crcnis1.unl.edu>
- Distribution: usa
- Date: Mon, 25 Jan 1993 03:32:23 GMT
- Lines: 70
-
- In article <1jvlnrINNst4@crcnis1.unl.edu> mgleason@cse.unl.edu (Mike Gleason) writes:
- >
- >Well, I found out the hard way awhile back that this doesn't work like one
- >would expect in Think C 5. Think C's #pragma parameter only works on "sub-
- >sequent inline function definitions" (p. 194 of the manual). So in Think C,
- >you can't really use this for your own functions unless you bother with crap
- >like "void foo(void) = { 0x4e71, 0x4e71, etc... };" I wouldn't mind if Think
- >C required the whole function to be in gazzembly, but accepting only raw hex
- >is unacceptable.
-
- So big deal. What's assembly language without a little work? :-)
-
- Here's a way to do it - it's not necessarily as nice as having a #pragma
- to do it for you, but it does work, and you could probably cons up some
- macros to help...
-
- Declare your function as a void function, with no arguments, and at
- the beginning, you can have a bit of code which copies the register
- arguments into named local variables. You don't have to, though, if
- you're writing the entire function in assembly language:
-
- void func(void)
- {
- char *str;
- short len;
-
- asm
- {
- move.w d0, len
- move.l a0, str
- }
-
- // ...and the rest of your function.
-
- // If you need to return a result to a C caller, return it in d0.
- }
-
- To call this function, just have a bit of inline assembly that moves the
- arguments into registers and calls the function:
-
- asm
- {
- lea char_buf, a0
- move.w buf_len, d0
- jsr func
- }
-
- (I'm coming into this thread late, and so you may have already considered
- this; however:)
-
- You may wish to revisit your code and figure out whether it's worth
- taking the time to optimize your parameter passing; if it's so
- time-critical that you're worrying about the number of cycles it takes
- to push and pop arguments, then you may well be better off moving the
- function(s) you're going to call inline with the rest of your code.
- Besides, for a normal routine, the passing of arguments really gets
- lost in the noise; if it doesn't, then you -definitely- should move
- the function inline.
-
- #pragma parameter is really a hack (which originated with MPW C) to
- provide a way to call register-based traps without requiring an
- external glue library; trying to use it for anything else is extending
- it somewhat beyond its limits...
-
- R.
- --
- -----------------------------------------------------------------------
- Rich Siegel Internet: siegel@world.std.com
- Senior Software Engineer
- GCC Technologies
-