Maxim Integrated 19-13
MAX31782 User’s Guide
Revision 0; 8/11
19.7.5 Looping Operations
Looping over a section of code can be performed by using the conditional jump instructions. However, there is built-in
functionality, in the form of the ‘DJNZ LC[n], src’ instruction, to support faster, more compact looping code with separate
loop counters. The 16-bit registers LC[0], and LC[1] are used to store these loop counts. The ‘DJNZ LC[n], src’ instruc-
tion automatically decrements the associated loop counter register and jumps to the loop address specified by src if
the loop counter has not reached 0.
To initialize a loop, set the LC[n] register to the count you wish to use before entering the loop’s main body.
The desired loop address should be supplied in the src operand of the ‘DJNZ LC[n], src’ instruction. When the sup-
plied loop address is relative (+127/-128 words) to the DJNZ LC[n] instruction, as is typically the case, the assembler
automatically calculates the relative offset and inserts this immediate value in the object code.
move LC[1],#10h ;loop16times
LoopTop: ;loopaddrrelativetodjnzLC[n],srcinstruction
call LoopSub
djnz LC[1],LoopTop ;decrementLC[1]andjumpifnonzero
When the supplied loop address is outside the relative jump range, the prefix register (PFX[0]) is used to supply the
high byte of the loop address as required.
move LC[1],#10h ;loop16times
LoopTop: ;loopaddrnotrelativetodjnzLC[n],src
call LoopSub
...
djnz LC[1],LoopTop ;decrementLC[1]andjumpifnonzero
;assemblesto: movePFX[0],#high(LoopTop)
; djnzLC[1], #low(LoopTop)
If loop execution speed is critical and a relative jump cannot be used, one might consider preloading an internal 16-bit
register with the src loop address for the ‘DJNZ LC[n], src’ loop. This ensures that the prefix register will not be needed
to supply the loop address and always yields the fastest execution of the DJNZ instruction.
move LC[0],#LoopTop ;usingLC[0]asaddressholdingregister
;assemblesto: movePFX[0],#high(LoopTop)
; moveLC[0], #low(LoopTop)
move LC[1],#10h ; loop16times
...
LoopTop: ;loopaddressnotrelativetodjnzLC[n],src
call LoopSub
...
djnz LC[1],LC[0] ;decrementLC[1]andjumpifnonzero
If opting to preload the loop address to an internal 16-bit register, the most time and code efficient means is by perform-
ing the load in the instruction just prior to the top of the loop:
move LC[1],#10h ;Setloopcounterto16
move LC[0],IP ;Setloopaddresstothenextaddress
LoopTop: ;loopaddrnotrelativetodjnzLC[n],src
...
Kommentare zu diesen Handbüchern