Page 1 of 1

asm: ldir on 6800x

Posted: Fri Feb 04, 2022 5:00 pm
by nitrofurano
a question related to assembly language: what kind of routine would do the same as ldir (from z80) or ldirw (from z380) on 68008, 68000 and etc.? or where can i get useful information that would help us?

Re: asm: ldir on 6800x

Posted: Fri Feb 04, 2022 5:38 pm
by NormanDunbar
Assuming you are moving bytes, as per the Z80's LDIR, which, if I remember correctly moves bytes from (HL) to (DE) using BC as a counter, stopping at zero.

Code: Select all

start
    lea a1,source_bytes_address
    lea a2,dest_address
    move.w #byteCount,d0
    bra.s loopEnd

loop
    move.b (a1)+,(a2)+

loopEnd
    dbra d0,loop
    rts
That copies D0.W bytes from (A1) to (A2) but you can use any address register for the source/dest and any data register for the count. These DBcc instructions stop when the value in the counting register is -1, not at zero. To get around this, you must either:

A. Load the counter with one less than the byte count; or
B. Load the counter with the correct byte count and skip to the end of the loop.

Both are fine if you know the byte count. If the byte count is being calculated, then it might be zero, in which case, the second variant is best.

Useful Information?

Me? ;)
Here on the forum?
The MC68000 family programmers' Refernce manual at https://www.nxp.com/files-static/archiv ... 000PRM.pdf (I use this one)



HTH

Cheers,
Norm.

Re: asm: ldir on 6800x

Posted: Fri Feb 04, 2022 6:16 pm
by tofro
Norm,

that difference (maybe I used the Z80 for a bit too long) makes me define loopCounts as

Code: Select all

howManyBytes EQU  howMany
                move.w #howManyBytes-1,dX

Re: asm: ldir on 6800x

Posted: Fri Feb 04, 2022 9:26 pm
by NormanDunbar
Aye!

If I kniw how many repetitions I need, it's a move.w #whatevrr-1, if I don't, I skip to the end to do the decrement for me.

I used to just do the calculation, subtract 1, then enter the top of the loop, but George (Gwilt) and others, gave me a telling off. I think it was because the calculstion could have been zero, subtract 1 is -1 but the dbra would make it -2 and then we get 65536 repetitions instead of none.

Cheers,
Norm.