[Coco] 6502 to 6809 translation

John Kent jekent at optusnet.com.au
Tue Aug 2 01:50:47 EDT 2011



On 2/08/2011 4:09 AM, Robert Gault wrote:
> 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
>

I don't there is a lda x,y only accumulator A, B or D offset from the 
index register.

> 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
>

X & Y registers on the 6502 are 8 bit.so you can use the B accumulator 
as a counter.

> 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
>
> -- 
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
>
>

-- 
http://www.johnkent.com.au
http://members.optusnet.com.au/jekent





More information about the Coco mailing list