Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!samsung!sdd.hp.com!ucsd!dog.ee.lbl.gov!helios.ee.lbl.gov!ux5.lbl.gov!beard From: beard@ux5.lbl.gov (Patrick C Beard) Newsgroups: comp.sys.mac.programmer Subject: Re: Think C chokes on assembler macro, help! Message-ID: <6530@helios.ee.lbl.gov> Date: 17 Aug 90 05:12:35 GMT References: <4225@dogie.macc.wisc.edu> Sender: usenet@helios.ee.lbl.gov Reply-To: beard@ux5.lbl.gov (Patrick C Beard) Organization: Berkeley Systems, Inc. Lines: 51 X-Local-Date: 16 Aug 90 22:12:35 PDT In article <4225@dogie.macc.wisc.edu> yahnke@vms.macc.wisc.edu (Ross Yahnke, MACC) writes: #There is this nifty little routine in the MacTech Journal that #decribes how to write a Think C macro to call an assembly routine #that will pop the state of a handle onto the stack and then lock #the handle. Also described is the corresponding routine to pop #the state back off the stack. I can't get it to compile. # #The macro is: # #define _PushLock(H) asm \ # { move.l H,a0 \ # _HGetState \ # move.b d0,-(sp) \ # move.l H,a0 \ # _HLock \ # } /* PushLock */ # #My C call is: # _PushLock((*Major)->Contrived.Complex.aHandle); # #Think C chokes when compiling/assembling the above line with #the message "Pointer is required". This is presumably occuring #when it tries to assemble: # move.l (*Major)->Contrived.Complex.aHandle,a0 Think about what this means. What addressing mode could possibly be used to generate the correct code with all of these dereferences? You are mixing C and assembly a little TOO freely. The only way this macro can work is if you use a temporary which is on the stack, or in a register. Now, this version will work whatever you pass it: #define _PushLock(H) \ { Handle temp = H; \ asm { \ move.l temp,a0 \ _HGetState \ move.b d0,-(sp) \ move.l temp,a0 \ _HLock \ }} /* PushLock */ It works because you force all the complicated addressing to happen automatic- ally and the compiler does all the work. temp is always relative to A6. I hope this helps. -- ------------------------------------------------------------------------------- - Patrick Beard, Macintosh Programmer (beard@lbl.gov) - - Berkeley Systems, Inc. "..............Good day!" - Paul Harvey - -------------------------------------------------------------------------------