[Coco] 6502 to 6809 translation

Robert Gault robert.gault at att.net
Mon Aug 1 14:09:09 EDT 2011


Phill Harvey-Smith wrote:
> On 01/08/2011 13:23, John Kent wrote:
>> Rather than using Y you might want to use B,
>>
>> that way
>>
>> lda (data_addr),y
>>
>> would become
>>
>> ldy data_addr
>> lda b,y
>
> Yeah that would work quite a lot of the code seems to be something like
>
> ldy #something
> loop:
> lda (indirect),y
> ;; do something with a here !
> iny
> bne loop
>
>
> So I guess that would become
>
> ldy (indirect)
> ldb #something
> loop:
> lda b,y
> incb
> bne loop
>
>
> That would work well I think.
>
> Thanks.
>
> Phill.
>

There are lots of ways to create 6809 code that does the same thing as some 6502 
code. The main questions are what registers do you need to protect and just how 
closely do you want to emulate the 6502 code?

For example, there is a corresponding command to the 6502 iny :: 6809 leay 1,y

There is no equivalent to lda [data_addr],y . If data_addr is an address which 
contains an address, neither lda data_addr,y nor lda [data_addr,y] will work. 
but you could use:

data_addr fdb $8000
  ldy #$20
  ldx data_addr
loop lda x,y
  leay 1,y
  bne loop

That is about as close to the 6502 code as you can get but it is not necessarily 
"good" code. When should this loop stop? Do any of these registers need to be 
saved before entering the loop? If you know when the loop should stop, there are 
better ways of writing the loop. As an example:

data_addr fdb $8020
size fdb 1325
  ldy data_addr
  ldx size
loop lda ,y+
  do something with regA
  leax -1,x
  bne loop

Now the loop can repeat any number of times from 2-65535. If you need less than 
255 reps, then regB could count down. If the size of the loop depends on the 
data, you don't even need to keep track. If $00 marks the end of the data:

data_addr fdb $8020

  ldy data_addr
loop lda ,y+
  beq exit
  do something with regA
  bra loop

If some other value is the end flag then:

data_addr fdb $8020

  ldy data_addr
loop lda ,y+
  cmpa #endflag
  beq exit
  do something with regA
  bra loop



More information about the Coco mailing list