Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!pasteur!ucbvax!hplabs!well!ewhac From: ewhac@well.UUCP (Leo L. Schwab) Newsgroups: comp.sys.amiga.tech Subject: Re: Adjusting the stack pointer Summary: Machts nichts Message-ID: <10098@well.UUCP> Date: 23 Dec 88 08:27:38 GMT References: <5047@garfield.MUN.EDU> Reply-To: ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) Distribution: na Organization: ~rPa_{~~cif~t(i~c ~r_{^?Belw3t(~rl~ Lines: 48 Quote: "I plan to live forever -- or die trying." -- Vila In article <5047@garfield.MUN.EDU> john13@garfield.MUN.EDU (John Russell) writes: >Manx-generated code uses the form > >addq.w #(4*N),sp > ^ > >to reset the stack pointer after calling a function with N (long) args on the >stack. Examples which adhere to the syntax of other Amiga assemblers use > >addq.l #(4*N),sp > ^ > >Is the Manx format dangerous if the stack is being incremented past a >64k boundary? Is there a reason to use one and not the other? > It turns out that, for ADDQ, specifying .w over .l doesn't buy you anything; both are 8 clocks. However, ADDQ only works for immediate values between 1-8. Outside that range, you would be inclined to use ADDA. To use your notation: adda.l #(4*N),sp ; 16 clocks, 6 bytes However, 32K of local variables in a single context is highly unusual (unless you've got a lot of buffers hanging around, in which case you should probably be using AllocMem() to get them). Thus, it is (usually) safe to say: adda.w #(4*N),sp ; 12 clocks, 4 bytes A smart compiler will recognize when the desired offset is greater than 32K (the offset is signed, remember), and use the ADDA.L when needed. It further turns out that you can get even better performance than that by saying: lea 4*N(sp),sp ; 8 clocks, 4 bytes This does exactly what the ADDA.W construct above does, only cheaper. The 68000 is full of little non-orthogonal goodies like this. [Timing information source: MC68000 programming quick-reference card, available from Motorola.] _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ Leo L. Schwab -- The Guy in The Cape INET: well!ewhac@ucbvax.Berkeley.EDU \_ -_ Recumbent Bikes: UUCP: pacbell > !{well,unicom}!ewhac O----^o The Only Way To Fly. hplabs / (pronounced "AE-wack") "Work FOR? I don't work FOR anybody! I'm just having fun." -- The Doctor