dbcc

Test condition, decrement and branch

Tests a condition, then decrements the low-word counter and branches only if the condition is false and the counter has not become -1.

Size .w

XNZVC –––––
  • Changes no flag

Forms

  • dbcc ,

Operands

Dn
A data register, d0 to d7. More
label
A branch target, written as a label or address. The assembler calculates the relative displacement. More

If the condition is true, execution continues at the next instruction and the counter is unchanged. If it is false, the low word of the data register is decremented; the branch is taken unless that word becomes -1. The upper word is unchanged, and dbcc does not change the flags.

The suffix selects the condition. See condition codes. dbf and dbra always take the decrement path. Starting the low word at N repeats a loop body N + 1 times, up to 65,536 times when it starts at $FFFF.

* --- Loops d0+1 times (decrements THEN tests) ---
move.l #3, d0
move.l #0, d1
loop:
    addq.l #1, d1
    dbra d0, loop ; loop runs 4 times (3, 2, 1, 0)

* --- Stop early when the tested value reaches zero ---
move.l #10, d2
move.l #3, d3
loop2:
    subq.l #1, d3
    tst d3
    dbeq d2, loop2 ; Z set: stop with d3 = 0 and d2 = 8