Lawrence D’Oliveiro <l…@nz.invalid> writes:
> Carlos E. R. wrote:
>> The 68000 had a beautiful assembler. Or rather, a beautiful
>> instruction set.
>
> Definitely inspired by the PDP-11. Pity it was big-endian. Also, the
> division into “address” versus “data” registers did seem to be a step
> backwards.
>
> 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?
At the surface level, because DBcc is a rather bizarrely shaped
instruction, with the condition code applying to the whole instruction
rather; operating with inverse sense; and branching unless the decrement
results in a value of -1 (i.e. 0xFFFF). So there’s _two_ conditional
steps (unless the condition is a constant, e.g. the common use of
DBF). Page 4-90 in the PRM[1] shows the definition.
So there’s several things to explain. I don’t have access to the
thinking of the designers, but I think the following are plausible
explanations:
1) The whole-instruction conditionality allows for early exits from
loops (depending of course how they are structured). So you get two
checks for a single instruction.
2) Using 0xFFFF for the sentinel value comes, microarchitecturally, ‘for
free’ because it just means checking the carry out from the
decrement, which is 1 in precisely the situation where the decrement
reaches -1. Using 0 as the sentintel would mean testing the whole
result value.
3) The inverse sense of the conditional. The PRM explains this one in
terms of ‘UNTIL’ loops, which were perhaps more popular in the
programming languages of the time than they are today.
[1] https://www.nxp.com/docs/en/reference-manual/M68000PRM.pdf