Path: utzoo!attcan!uunet!samsung!sdd.hp.com!zaphod.mps.ohio-state.edu!julius.cs.uiuc.edu!psuvax1!psuvm!art100 From: ART100@psuvm.psu.edu (Andy Tefft) Newsgroups: comp.sys.apple2 Subject: relocatable code Message-ID: <90315.194340ART100@psuvm.psu.edu> Date: 12 Nov 90 00:43:40 GMT Organization: Penn State University Lines: 40 I'm trying to write something small in assembly that will be completely relocatable. The problem is that the code contains a lookup table and I need to know where that table is in memory. I can do a neat trick to find where the program is in memory, but the problem is it requires a jsr. This means at least a small subroutine (ok, so it's only about 20 bytes long) be at a fixed point in memory. Here it is: start jsr storit ; this is in the main program ... storit pla ; obviously this has to be at a fixed loc. sta begin pla sta begin+1 pha ; put it back for the rts lda begin pha rts where begin is a pair of convenient 0-page or otherwise fixed locations. This routine returns start+2 in begin and begin+1. Then all i have to do is add a fixed offset from the 'start' location to get the location of my table. I guess I can force the user of the routine to store the starting location of the program at some fixed point and have the program use that, but obviously it isn't foolproof. Is there any other way a program can get the contents of the PC besides pulling them off the stack after a jmp or jsr? The program will not necessarily be brun from basic.system, so I can't use any prodos tricks. The table is about 48 bytes, too long to manually store in memory with lda #3, sta $1000, lda #76, sta $1001, etc. Same deal with the storit subroutine. Think I've covered all the important difficulties there. ideas? ideas?