[Coco] 6502 to 6809 translation
jekent at optusnet.com.au
Tue Aug 2 02:22:02 EDT 2011
On 2/08/2011 8:40 AM, William Astle wrote:
> You're missing a detail in the original question. Let's make the
> following assumptions, codified as source code:
> org $2000
> data_addr fdb $8000
> org $2020
> fdb $8272
> org $4000
> ldy #$20
> * sequence 1
> lda [data_addr,y]
> * sequence 2
> lda data_addr,y
> * sequence 3
> ldd data_addr
> lda d,y
> * end options
> org $8020
> fcb $42
> org $8272
> fcb $32
> Sequence 1 will result in A containing $32 because it will read the
> address at $2020 and use that as the address to load A from.
> Sequence 2 will result in A containing $82 because it will fetch A
> from $2020.
> Sequence 3 will result in A containing $42, which is what the original
> 6502 instruction would do (assuming it were implemented on the 6809).
> Essentially, the 6502 is loading a 16 bit base address from the
> address of data_addr and adding the value in Y to that address to form
> the effective address which is used for loading A. Using 6809
> nomenclature, that would be "LDA [data_addr],y", which obviously does
> not exist. Such weird (to us) gyrations are required because the 6502
> has no 16 bit registers and on the 6502, the address of "data_addr"
> would have to be in the direct page.
For lda b,y according to my VHDL 6809, B is sign extended so you are
right for an offset from 128 to 255 from a 16 bit base address you will
need to use D as the base address rather than B as a replacement for Y
so your sequence 3 I would say is correct. The thing is that D is made
up of A & B so when you load A you destroy the base address in D but I
guess you can reload it again later anyway.
LDA data_addr, y "data_addr" is a constant offset not a variable
address. I think the 6502 used direct page memory for the indirect
indexed addressing although it's a while since I looked at the 6502.
More information about the Coco