284
Section 3: Assembler
TI
-
89 / TI
-
92 Plus Sierra C Assembler Reference Manual
Not for Distribution
Beta Version February 2, 2001
The FOR . . . ENDF macro is a restricted form of the for statement in C. It
generates a counter-based iterated loop, which can be executed zero or more
times. The loop is executed until
op1 is greater / less (TO / DOWNTO) than op3.
This macro uses a MOVE instruction to initialize
op1 to the value of op2, either
an ADD instruction to increment
op1 by op4 (TO) or a SUB instruction to
decrement
op1 by op4 (DOWNTO), and a CMP instruction to perform the
termination test involving
op1 and op3. An unconditional forward branch is used
initially to jump to the termination test, which is situated at the end of the loop; a
conditional backward branch is used to jump to the beginning of the loop to
perform the next iteration. The initial jump to the termination test will be omitted
during expansion if it can be determined that the loop will execute at least once.
Upon normal exit from the loop,
op1 will contain the value that caused the loop to
terminate; the condition codes will reflect the final execution of the CMP
instruction. Since the FOR . . . ENDF construct is simply a macro, there are no
restrictions on modifying the operands
op1, op2, op3, and op4 from within the
body of the loop.
Examples
FOR.L A0 = #OUTBUF TO #BUFSIZ-1 BY #4 DO.S
CLR.L (A0)
ENDF
FOR.W D0 = #1 TO #SIZE DO.S
MOVE.B (A0)+,(A1)+
ENDF
As the first example illustrates, the default step size of 1 is inappropriate when
the loop counter is used directly to index through word or long-word data.