Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!tut.cis.ohio-state.edu!anaconda.cis.ohio-state.edu!meekins From: meekins@anaconda.cis.ohio-state.edu (Tim Meekins) Newsgroups: comp.sys.apple2 Subject: Re: ML subroutines (passing parameters in ML) Message-ID: <112122@tut.cis.ohio-state.edu> Date: 24 Apr 91 21:05:50 GMT References: <3397@kluge.fiu.edu> <13845@ucrmath.ucr.edu> Sender: news@tut.cis.ohio-state.edu Organization: The Ohio State University, Department of Computer and Information Science Lines: 35 In article <13845@ucrmath.ucr.edu> rhyde@musial.ucr.edu (randy hyde) writes: >There are many different ways to pass parameters in assembly language. > [snip] >4) Pass parameters on the stack. This is how most HLLs pass parameters. >It is slow, big, and accessing the parameters is inconvenient, >especially on processors like the 65816 which don't have a frame pointer >register. Nonetheless, there are some advantages to this technique: >It's easy to understand, easy to verify, and naturally supports >recursion and reentrancy. It supports any number of parameters (unlike >registers) and is easily expanded. > Hard to do on a GS? it's quite simple actually if you map the the direct page to the stack. So parameter 1 becomes dP location 0, 2 become 2, 3 becomes 4, etc (assuming words and no local variables and so forth). This remapping also allows local variables to used more efficiently. In fact, subroutines written this almost always tend to use direct page variables more often than absolute addressing variables. This large use of the DP more than makes up for the small overhead of setting up the stack. Although the set up code may look nasty to the meek, it is quite simple and macros exist for automating it. For example, my macro library has a macro called 'subroutine' which works similar to Orca/M's 'subroutine' macro. All you do is define your local varibales using equates then invoke the subroutine macro, listing each parameter and their lengths. It almost looks like a Pascal procedure definition. -- +---------------------------S-U-P-P-O-R-T-----------------------------------+ |/ Tim Meekins <<>> Snail Mail: <<>> Apple II \| |> meekins@cis.ohio-state.edu <<>> 8372 Morris Rd. <<>> Forever! <| |\ timm@pro-tcc.cts.com <<>> Hilliard, OH 43026 <<>> /|