
Repeat Mode
7-8
7.1.7
Nesting Block Repeats
Block repeats (RPTB and RPTBD) are nestable. Because all of the control of
a block repeat is defined by the RS, RE, RC, and ST registers, these registers
must be saved and stored to nest block repeats. For example, if you write an
interrupt service routine that requires the use of RPTB or RPTBD, it is possible
that the interrupt associated with the routine may occur during another block
repeat. The interrupt service routine can check the RM bit to determine wheth-
er the block repeat mode is active. If RM is set, the interrupt routine should
save ST, RS, RE and RC, in this order. The interrupt routine can then perform
a block repeat. Before returning from the interrupted routine, the interrupt rou-
tine should restore RC, RE, RS, and ST, in this order. If the RM bit is not set,
you do not need to save and restore these registers.
The RPTS instruction can also be used in a block repeat loop if the proper reg-
isters are saved.
Because the program counter is modified at the end of the loop according to
the contents of registers RS, RE, and RC, no operation should attempt to
modify the repeat counter or the program counter to a different value at the end
of the loop.
It takes four cycles of overhead to save and restore these registers. Hence,
sometimes, it may be more economical to implement a nested loop by the
more traditional method of using a register as a counter and then using a
delayed branch, rather than by using the nested repeat block approach. Often,
implementing the outer loop as a counter and the inner loop as a RPTB/
RPTBD instruction produces the fastest execution.
Note:
The order in which the registers are saved/restored is important to guarantee
correct operation. The ST register should be restored last, after the RC, RE,
and RS registers. ST should be restored after restoring RC, because the RM
bit cannot be set to one if the RC register is 0 or –1. For this reason, if you
execute a POP ST instruction (with ST(RM) = 1) while RC = 0, the POP
instruction recovers all of the ST register bits except the RM bit, which stays
at 0 (repeat mode disabled). Also, RS and RE should be correctly set before
you activate the repeat mode.
Section 1.7, Repeat Modes in the TMS320C4x General-Purpose Applications
User’s Guidecontains examples of how to use repeat-mode instructions.