dbne

Decrement and branch until not equal

Decrements the first operand by 1 and branches to the specified address if not equal is false and the first operand is not -1.

Size .w

XNZVC –––––
  • Changes no flag
  • Reads Z

Forms

  • dbne ,

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

dbra is the same as dbf (will decrement until it reaches -1). It reads the operand as a word, so it can run at maximum 64k times

* --- 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)

* --- With condition: dbne stops early if condition is true ---
move.l #10, d2
move.l #$FF, d3
loop2:
    subq.l #1, d3
    tst d3
    dbne d2, loop2 ; stops when d3 = 0 OR d2 exhausted