Path: news.uiowa.edu!news.physics.uiowa.edu!math.ohio-state.edu!uwm.edu!spool.mu.edu!munnari.OZ.AU!comp.vuw.ac.nz!waikato!waikato!news.express.co.nz!actrix.gen.nz!atlantis.actrix.gen.nz!not-for-mail From: dempson@atlantis.actrix.gen.nz (David Empson) Newsgroups: comp.sys.apple2.programmer Subject: Re: 65816 Monitors Date: 8 Jul 1996 21:36:51 +1200 Organization: Actrix - Internet Services Lines: 80 Message-ID: <4rqkrj$mj6@atlantis.atlantis.actrix.gen.nz> References: <4rnd8i$af6@nyx10.cs.du.edu> NNTP-Posting-Host: atlantis.actrix.gen.nz In article <4rnd8i$af6@nyx10.cs.du.edu>, Brett Tabke wrote: > > Yes, it gives the illusion that your getting more than you paid for. > However, that is the one an only gripe I have found with the 65816 > software manual. That is one of the better dedicated CPU manuals > I've ever seen. How has Western Design been about allowing > information from it to be reprinted? It is probably best to ask them. The data sheet for the 65816 has appeared in at least one book, as well as the IIgs hardware reference, so I expect that they are happy enough to have it republished, with a licensing fee. > I'm finally starting to see the real power behind the Direct > Page register. I guess it really didn't sink in that you can change > the Low byte of the zp adr as well. That gives interesting > possibilities for byte manipulation by just inc'ing the lb of the > direct page. Most IIgs high level languages simply use it as a frame pointer into the stack. The DP register is set to the address of the first local variable (usually minus one, since the stack pointer works the same way). Typical function entry code is along the lines of this (assuming the registers are in 16-bit mode): phd tsc sec sbc #4 ; Assuming 4 bytes of local variables needed tcs tcd You now have a stack frame that looks like this (assuming a call with JSL, parameters pushed right-to-left, and 16 bits for each argument): |______________| |_ Argument N _| |______________| DPR + $0A + N*2 | ... | |______________| |_ Argument 2 _| |______________| DPR + $0C |_ Argument 1 _| |______________| DPR + $0A |_ RTL addr _| |_ _| |______________| DPR + $07 |_ Saved DPR _| |______________| DPR + $05 |_ _| |_ Local vars _| |_ _| |______________| DPR + $01 | | <-- New stack pointer, and DPR The function can now use direct page addressing mode to access its local variables and parameters. If more than 256 bytes are needed, the compiler has to calculate the address using an index register. On return, it usually does something like this: tay ; preserve the return value lda 8 ; get the return address (high word) sta 8+N*2 ; overwrite the last argument lda 7 sta 7+N*2 ; do the low byte as well (middle byte copied twice) lda 5 ; get the saved direct page register tcd ; put it back tsc clc adc #4+2+N*2 ; toss the local variables, saved DPR and arguments tcs tya rtl -- David Empson dempson@actrix.gen.nz Snail mail: P.O. Box 27-103, Wellington, New Zealand