Program Counter

Programming the 6502 microprocessor and its relatives in assembly and other languages.
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Post by GARTHWILSON »

True, and you're reminding me of why I abandoned my quest for relocatable code on the 6502-- code that could be scooted around in memory after it was loaded and may have already been running. It wasn't so much the code location that was the problem as the data location. It can still be done, but it was getting too cumbersome to be worth it. If you have some slick ideas though, I might take it up again.
kc5tja
Posts: 1706
Joined: 04 Jan 2003

Post by kc5tja »

dcl raises a point that I didn't consider at the time. However, if you're willing to invest in using 5 bytes of zero-page at a fixed (or linker-patched) address,

Code: Select all

.proc whereAmI
  ldx #3
again:
  lda thunk,x
  sta zpThunk,x
  dex
  bpl again
  jsr zpThunk

thunk:
  pla
  tax
  pla
  rts
.endproc
You have to JSR to whereAmI -- JMPing to it will likely cause a crash.
User avatar
dclxvi
Posts: 362
Joined: 11 Mar 2004

Post by dclxvi »

I've added Where-Am-I routines to the wiki at:

http://6502org.wikidot.com/software-whereami
Post Reply