[Coco] 6309 Weirdness ??

Darren A. darccml at hotmail.com
Wed May 16 21:40:52 EDT 2007


OK, things are even stranger than I first thought.  Below is a BASIC program 
that can be used to demonstrate my new theory:

10 CLEAR 200,&H6FFF:A=&H7000
20 READ B$:IF B$="XX" THEN 40
30 POKE A,VAL("&H"+B$) :A=A+1:GOTO 20
40 EXEC &H7000
50 PRINT "X = ";HEX$(PEEK(&H600));HEX$(PEEK(&H601))
100 DATA 8E,FF,FD: REM LDX #-3
110 DATA 10,30,15: REM ADDR X,PC
120 DATA 12: REM NOP
130 DATA BF,06,00: REM STX $600
140 DATA 39: REM RTS
150 DATA XX

The program pokes the following code into memory, executes it, and displays 
the value of the X register that gets saved at address $600:

7000  LDX   #-3
7003  ADDR  X,PC
7006  NOP
7007  STX   $0600
700A  RTS

When I run the program I see:  X = FFF2

I think the actual instructions executed are:
7000  LDX   #-3
7003  ADDR  X,PC     ; PC = $7003+3+1-3 = $7004
7004  LEAX  -11,X    ; X = -3-11 = $FFF2
7006  NOP
7007  STX   $0600
7009  RTS

Note that the instruction following ADDR is a single byte (NOP). Now 
elimintate that NOP by deleting line 120 and run the program again.

This time I see:  X = FFFD

I think the actual instructions executed are:
7000  LDX   #-3
7003  ADDR  X,PC     ; PC = $7003+3+3-3 = $7006
7006  STX   $0600
7009  RTS

Note that on this run, the size of the instruction following ADDR was 3 
bytes long (STX $600).
Now let's insert a 2-byte instruction after ADDR by entering the following:

120 DATA 86,00 : REM LDA #0

If you run the program with this change, the CPU crashes (actually invokes 
the illegal instruction trap).
I think the actual instructions executed are:

7000  LDX   #-3
7003  ADDR  X,PC     ; PC = $7003+3+2-3 = $7005
7005  FCB  $15     ; Illegal Instruction

So, given this information, my new theory (and this seems really weird) is 
that the PC value used in the ADDR instruction is having the length of the 
following instruction added to it. I know this is getting crazy, but I just 
can't stop!

Darren

_________________________________________________________________
More photos, more messages, more storage—get 2GB with Windows Live Hotmail. 
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_2G_0507




More information about the Coco mailing list