Atari Logo
Atari Computer

Hauptseite -
Welches System? -
Hardware -
Software -
Emulatoren -
Internet
MausNet
Programmieren
Verweise
Über

Assembler

Previous Next TOC

NAME DBcc -- Decrement and branch conditionally
SYNOPSIS
DBccDn,<label>
Size of offset = (Word)
FUNCTION Controls a loop of instructions. The parameters are: a condition code, a data register (counter), and an offset value. The instruction first tests the condition (for termination); if it is true, no operation is performed. If the termination condition is not true, the low-order 16 bits of the counter are decremented by one. If the result is -1, execution continues at the next instruction, otherwise, execution continues at the specified address.

Condition code 'cc' specifies one of the following:
0000F FalseZ = 1
0001T TrueZ = 0
0010HIHIghC + Z = 0
0011LSLow or SameC + Z = 1
0100CCCarry ClearC = 0
0101CSCarry SetC = 1
0110NENot EqualZ = 0
0111EQEQualZ = 1
1000VCoVerflow ClearV = 0
1001VSoVerflow SetV = 1
1010PLPLusN = 0
1011MIMInusN = 1
1100GEGreater or EqualN (+) V = 0
1101LTLess ThanN (+) V = 1
1110GTGreater ThanZ + (N (+) V) = 0
1111LELess or EqualZ + (N (+) V) = 1

Keep the following in mind when using DBcc instructions:

  1. A DBcc acts as the UNTIL loop contruct in high level languages. E.g., DBMI would be "decrement and branch until minus".
  2. Most assemblers accept DBRA or DBF for use when no condition is required for termination of a loop.

The DBcc will, unlike the Bcc instruction, take the branch only if the set of conditions are NOT satified. The loop will be terminated if the condition is true, or the counter is zero BEFORE a decrement, and wrap to -1. This mean that if you execute code like:

 move.w#30,d0
   
.Loop  
 move.l(a0)+,(a1)+
 dbfd0,.Loop
   
  then the copy will be executed *31* times, and 124 bytes of memory will be copied, not 120.
   
 A good practice is therefore to write:
   
 move.w#31-1,d0
   
.Loop  
 move.l(a0)+,(a1)+
 dbfd0,.Loop
   
  To compare two strings that may be in excess of 64k length for beeing equal, you could execute the following code:
 ...
   
 move.l#$53452-1,d0
 beq.s.NoLength ; Zero length!
 bra.s.StartOuterLoop; The upper word contain count of 65536's...
   
.OuterLoop  
 swapd0
   
.InnerLoop  
 cmp.b(a0)+,(a1)+
 dbned0,.InnerLoop; Remember, drop trough on condition TRUE.
   
.StartOuterLoop ; d0 will be $FFFF on 2.+ run-through
 bne.s.NotEqual; Dropped through due to Not Equal?
 swapd0; Get upper part of word...
 dbfd0,.OuterLoop
 ...
   
  It would not be possible to use two sets of DBNEs, as SWAP changes the condition codes - and we don't want the drop- though to be on account of D0, instead of the compares...
   
  Another neat trick is to use instruction as a conditional decrementer; this code will decrement d0.w if the last instruction returned NOT EQUAL:
 ...
 dbeqd0,.Next
   
.Next  
 ...

FORMAT
1514131211109876543210
0101CONDITION11001REGISTER
16 BITS OFFSET (d16)
"CONDITION" is one of the condition code given some lines before.
"REGISTER" is the number of data register.
Offset is the relative gap in byte to do branching.
RESULT Not affected.


Best viewed with any browser English version not yet available.

Änderungen und Irrtümer vorbehalten. Letzte Änderung:
14 September 2001.
Home - Mail an den Webmaster - Impressum