asm: ldir on 6800x

Anything QL Software or Programming Related.
Post Reply
User avatar
nitrofurano
Chuggy Microdrive
Posts: 53
Joined: Sat Nov 16, 2013 10:48 am

asm: ldir on 6800x

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


User avatar
NormanDunbar
Forum Moderator
Posts: 2492
Joined: Tue Dec 14, 2010 9:04 am
Location: Buckie, Scotland
Contact:

Re: asm: ldir on 6800x

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


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.
User avatar
tofro
Font of All Knowledge
Posts: 3148
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: asm: ldir on 6800x

Post 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


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
NormanDunbar
Forum Moderator
Posts: 2492
Joined: Tue Dec 14, 2010 9:04 am
Location: Buckie, Scotland
Contact:

Re: asm: ldir on 6800x

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


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.
Post Reply