asm: ldir on 6800x
- nitrofurano
- Chuggy Microdrive
- Posts: 53
- Joined: Sat Nov 16, 2013 10:48 am
asm: ldir on 6800x
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?
- NormanDunbar
- Forum Moderator
- Posts: 2492
- Joined: Tue Dec 14, 2010 9:04 am
- Location: Buckie, Scotland
- Contact:
Re: asm: ldir on 6800x
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.
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.
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
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.
Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Re: asm: ldir on 6800x
Norm,
that difference (maybe I used the Z80 for a bit too long) makes me define loopCounts as
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
ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
- NormanDunbar
- Forum Moderator
- Posts: 2492
- Joined: Tue Dec 14, 2010 9:04 am
- Location: Buckie, Scotland
- Contact:
Re: asm: ldir on 6800x
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.
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.
Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.