Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!rex!rouge!dlbres14 From: dlbres14@pc.usl.edu (Brumley David M) Newsgroups: comp.sys.amiga.programmer Subject: 68K Assembly language question (stack frames) Message-ID: Date: 21 Feb 91 13:38:54 GMT Sender: anon@rouge.usl.edu Distribution: comp Organization: Univ. of Southwestern LA, Lafayette Lines: 51 The following example of stack frame parameter passing is taken from _68000 Assembly Language: Techniques for Building Programs_ by Donald Kranz and James Stanley, Addison-Wesley: Reading, Mass. 1986. p 121. "Let's look at a hypothetical routine 'max' that incorporates two of the uses of a stack frame. This routine is passed two 16-bit integer values, and returns the larger of the two in register D0. If the two numbers are equal, we assume catastrophic failure elsewhere and call a routine walkback that will display the walkback sequence. [The walkback stuff is irrelevant to my question.] The code calling 'max' might look like this: MOVE.W D0,-(A7) * Push parameter 1 on stack MOVE.W D1,-(A7) * Push parameter 2 on stack BSR MAX * Call 'max' The code for 'max' could look like this: 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 <--- ??? BEQ WALKBACK * Do walkback if equal BLT IS_P2 * Jump if P2 > P1 BRA EXIT * P1 > P2 IS_P2: MOVE.W 10(A6),D0 * Put parameter 2 into D0 EXIT: UNLK A6 * Unlink frame RTS * Get out of routine MX: DC.B 'MAX',0 * Name for walkback [...]" 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? -- David M. Brumley