On 2026-11-06 21:53, Lawrence D’Oliveiro wrote:
> On Fri, 6 Nov 2026 14:30:35 +0100, Carlos E. R. wrote:
>
>> On 2026-11-06 00:17, Lawrence D’Oliveiro wrote:
>>>
>>> Here’s one trivia question: the decrement-and-branch instruction
>>> would fall out of the loop when the count reached -1, not 0 as the
>>> equivalent instruction in nearly every other computer architecture
>>> did. Why?
>>
>> Mmm. I don't remember. A flag went up?
>
> It was quite a clever feature, which I think ended up widely
> misunderstood. Otherwise more architectures would have copied it.
>
> The reason is, so that if the loop count was zero, you could just
> fall out of the loop automatically, without having to do an explicit
> test for that case.
>
> Example skeleton loop: (remember, the loop count was only 16 bits):
>
> move.w «loop-count», dN ; dN = some convenient d-register
> bra loop_bottom
> loop_top:
> ... body of loop ...
> loop_bottom:
> dbra dN, loop_top
> ... here on loop end ...
>
> Notice this will loop exactly «loop-count» times, even if «loop-count»
> is zero.
>
> If you want a 32-bit loop count, it only took a few more instructions:
>
> move.l «loop-count», dN
> bra loop_bottom
> loop_top1:
> swap dN
> loop_top2:
> ... body of loop ...
> loop_bottom:
> dbra dN, loop_top2
> swap dN
> dbra dN, loop_top1
> ... here on loop end ...
>
> (This is all from memory, it’s been a long while since I wrote any
> 68000-family assembler.)
Last time I touched it, was 1992. :-(
--
Cheers,
Carlos E.R.
ES🇪🇸, EU🇪🇺.