💾 Archived View for mirrors.apple2.org.za › archive › ground.icaen.uiowa.edu › MiscInfo › Programmin… captured on 2024-07-09 at 03:50:59.
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
On 26 Jan 2003, Michael J. Mahon wrote: > Date: 26 Jan 2003 11:51:02 GMT > From: Michael J. Mahon <mjmahon@aol.com> > Newsgroups: comp.sys.apple2.programmer > Subject: Re: Assembly inline "Print" routine > > Jeff Blakeney replied: > > >On Sun, 26 Jan 2003 06:18:08 GMT, "Terry & Utahna" > ><tolsen64@hotmail.com> wrote: > > > >>It's been many years since I've done any assembly programming. Now I'm > >>working on a project but for the life of me I can't remember the "inline > >>print" routine I used to use. It went something like: > >> > >> jsr PrintRoutine > >> asc "Hello World!",00 > >> ...continue assembly code here > >> > >>The print routine somehow knew to RTS to the instruction just after the 00 > >>termination on that string. I think the return address was pulled from the > >>stack and the "modified" return address was pushed just before the RTS...Am > >>I close???? > > > >Yes, that is what you can do for an inline print routine. > > > >The print routine needs to pull the RTS address off the stack and use > >that as the address of the first character to print and when it hits > >the $00 at the end of the string it needs to push the address of the > >location after the $00 and do an RTS. > > Almost. > > The address pushed by a JSR is the return point - 1, and an RTS > increments the return address before fetching the next instruction. > > As a result, the string is at the popped address + 1, and the address > of the $00 should be pushed back onto the stack before returning. > > -michael > > Check out amazing quality 8-bit Apple sound on my > Home page: http://members.aol.com/MJMahon/ > Hi, Mr. Mahon is right. Here is my little solution recently used in a demo program: ;**************************************** ; 24-Jul-2000 StringWritePC ; ; PC = pointer to string ; ==> A,X,Y = saved ; ;**************************************** stringwritepc: STA strpc5+1; save A PLA STA strpc2+1; pull return address PLA STA strpc2+2 BNE strpc3; jump always (should not be zero) strpc2: LDA $ffff; read characters from string BEQ strpc4; endmarker reached? JSR cout; print character strpc3: INC strpc2+1; increment address BNE strpc2 INC strpc2+2 BNE strpc2; jump always (should not become zero) strpc4: LDA strpc2+2; push address on stack PHA LDA strpc2+1 PHA strpc5: LDA #0; restore A RTS Kind regards Holger