Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!mailrus!caen.engin.umich.edu!mystone From: mystone@caen.engin.umich.edu (Dean Yu) Newsgroups: comp.sys.mac.programmer Subject: Re: LSP/THINK Code Resource question Message-ID: <4438a627.1285f@maize.engin.umich.edu> Date: 4 Jul 89 16:34:00 GMT References: <4246@tank.uchicago.edu> Reply-To: mystone@sol.engin.umich.edu Distribution: na Organization: Computer Aided Engineering Network, University of Michigan Lines: 40 Sender: Followup-To: In article <4246@tank.uchicago.edu> ra_robert@gsbacd.uchicago.edu writes: > >I'm writing an MDEF with LSP/THINK Pascal. Near the start of my MDEF I call a >sub-procedure in which I allocate a pointer with NewPtr (which I dispose of >before exiting the MDEF). While debugging (with TMON), I intercepted the >NewPtr call, but the NewPtr call isn't in my sub-proc any longer, but rather >it's near the start of main the code. I think this section of main code is >called from my sub-proc and then jumps back there. Any idea of what's going >on? It's more difficult to debug when the assembly differs greatly from the >source (i.e, why is my NewPtr call not in the section of code (my sub-proc) >where it "should" be?). > I noticed something similar in MPW Pascal last night. From what I've been able to fathom, this seems to be some form of optimization. Most Toolbox routines are stackbased, ie, the parameters are passed to the routines on the stack. However, _NewPtr is register based -- the size of the new pointer is passed in register D0, and the address is returned in A0. It looks like these compilers make their own stack based routine for creating a new pointer which in turn calls the original _NewPtr with the parameters in the proper registers. It kinda makes sense this way; instead of saving A0/D0, creating the pointer, moving A0 into your application storage, and restoring A0/D0 for every _NewPtr call, it pushes the size you want on the stack, call a procedure that handles all the register shuffling for you, and returns the address on the pointer on the stack. If _NewPtr gets called a lot in your program, this does save quite a bit of space. _______________________________________________________________________________ Dean Yu | E-mail: mystone@{sol,caen}.engin.umich.edu University of Michigan | Real-mail: Dean Yu Computer Aided Engineering Network | 909 Church St | Apt C ===================================| Ann Arbor, MI 48104 | Phone: Given on a need to know basis, and "I am the Merit Host. I speak for | only if you're going to offer me a the bitstream." (In other words, | job... these are my very own opinions; | my employer wants to have nothing |=========================================== to do with them, or me.) | This space available for rent -------------------------------------------------------------------------------