Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!overload!dillon From: dillon@overload.Berkeley.CA.US (Matthew Dillon) Newsgroups: comp.sys.amiga.programmer Subject: Re: 68K Assembly language question (stack frames) Message-ID: Date: 22 Feb 91 20:06:14 GMT References: Organization: Not an Organization Lines: 54 In article dlbres14@pc.usl.edu (Brumley David M) writes: >... > >MOVE.W D0,-(A7) * Push parameter 1 on stack >MOVE.W D1,-(A7) * Push parameter 2 on stack >BSR MAX * Call 'max' > >.. > >MAX: LINK A6,-4 * LINK and make 4 byte extra space > MOVE.L #MX,-4(A6) * Put address of name in frame > MOVE.W 8(A6),D0 * Get parameter 1 to D0 <--- ??? > CMP.W 10(A6),D0 * Test against parameter 2 <--- ??? >Ok, my question has to do with the lines: > > MOVE.W 8(A6),D0 * Get parameter 1 to D0 > CMP.W 10(A6),D0 * Test against parameter 2 > >I simply don't understand how 8(A6) references parameter 1 and 10(A6) >references parameter 2 when param1 was pushed onto the stack before >param2! Of course, this is irrelevant to the correct operation of >MAX; it will return the correct value in D0 (or start the walkback to >trace the error), but the authors' comments seem misleading. Have I >got 68K stacks all wrong? The stack looks like this: [pushed D0] [pushed D1] [RETURN PC] sp-> [LINK-SAVE-A6] thus, 0(A6) references the saved link register, A6, 4(A6) references the return-pc (from the BSR), and 8(A6) points to D1, and 10(A6) points to D0 ... the 'parameter 1' and 'parameter 2' comments are mixed up .... 8(A6) is D1, or parameter 2 by the first definition. If you relate this to C you should note that C always pushes parameters in reverse order, so parameter 1 would be pushed LAST, thus 8(A6) would be parameter one and 10(A6) parameter 2, etc... in C (16 bit compilation). >-- >David M. Brumley > -- -Matt Matthew Dillon dillon@Overload.Berkeley.CA.US 891 Regal Rd. uunet.uu.net!overload!dillon Berkeley, Ca. 94708 USA