Path: csiph.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!border2.nntp.dca1.giganews.com!Xl.tags.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 04 Feb 2016 14:31:05 -0600 From: Scott Hemphill Newsgroups: comp.sys.apple2.programmer Subject: Re: most efficient way to save/restore 6502 registers References: <61723ee6-c434-48d0-9bb0-bd44b545c922@googlegroups.com> Reply-To: hemphill@alumni.caltech.edu Date: Thu, 04 Feb 2016 15:31:05 -0500 Message-ID: <87mvrgi5fa.fsf@hemphills.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:je//q/JA4M048rk9jyITjrc+mqk= MIME-Version: 1.0 Content-Type: text/plain Lines: 36 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-YgTxFpfl4Pw5J1KYMeBi+WRIU9GLFC91uGQOWacfm0J2KgZMVq9NV0ItfbQAgWIVSe2cKuqkakTxGd1!6PbOCLLCVFPErPGm6dya1uBDitgCkBmNsbvVQJDP4A4r+BIDQoyBm2A= X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2339 Xref: csiph.com comp.sys.apple2.programmer:2205 Mark Lemmert writes: > I am wondering if anybody knows why the most Apple II assembly > subroutines save/restore registered via the stack (method 1 below), > instead of using variables (method 2 below)? > > And, what are the advantages and disadvantages are for each method? > > Thanks a lot for any insights! (1) I think you pretty much covered it. Note that if you do a lot of saving/restoring, you could (with both schemes) reduce the per instance memory usage by doing this: JSR XYSAVE ... JSR XYRESTORE You could even omit the call to XYRESTORE if XYSAVE manipulates the stack by putting the address to XYRESTORE on it, so that the RET from your subroutine automatically restores the registers. (2) If your subroutine calls itself recursively, you need to store the registers on a stack. (3) If your subroutine doesn't know which memory banks are switched in (e.g. when processing an interrupt) then you may not want to store the registers in memory. (4) Saving the registers in memory allows you to restore them multiple times. Scott -- Scott Hemphill hemphill@alumni.caltech.edu "This isn't flying. This is falling, with style." -- Buzz Lightyear