Loop Trip Count In C - Texas Instruments TMS320C6000 Programmer's Manual

Hide thumbs Also See for TMS320C6000:
Table of Contents

Advertisement

Linear Assembly Considerations
Example 8–18. Loop Trip Count in C
int count_loop_iterations(int count)
{
int iters, i;
iters = 0;
for (i = count; i > 0; i––)
iters++;
return iters;
}
Example 8–19. Loop Trip Count in Linear Assembly without BDEC
.global _count_loop_iterations
_count_loop_iterations .cproc count
.reg
ZERO
CMPLT
[flag]
B
MV
loop:
.trip
ADD
SUB
[i]
B
does_not_iterate:
.return iters
.endproc
8-46
Without BDEC and BPOS, this loop would be written as shown in
Example 8–19 below. This example uses branches to test whether the loop
iterates at all, as well as to perform the loop iteration itself. This loop iterates
exactly the number of times specified by the argument 'count'.
i, iters, flag
iters
count,
1,
flag
does_not_iterate
count,
i
1
iters,
1,
iters
i,
1,
i
loop
Using BDEC , the loop is written similarly. However, the loop counter needs to
be adjusted, since BDEC terminates the loop after the loop counter becomes
negative. Example 8–20 illustrates using BDEC to conditionally execute the
loop, as well as to iterate the loop. In the typical case, the loop count needs
to be decreased by 2 before the loop. The SUB and BDEC before the loop per-
form this update to the loop counter.
; Initialize our return value to 0.
; Do not iterate if count
; i = count
; This loop is guaranteed to iterate at
; least once.
; iters++
; i––
; while (i > 0);
; Return our number of iterations.

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the TMS320C6000 and is the answer not in the manual?

Questions and answers

Table of Contents