Structured Control - For
For - Utilizes op1 as a counter and loops while op1 is between the values of op2 and op3 inclusive. Loops may be written that count up (TO) or down (DOWNTO). The user may specify the step size with op4. If no step size is specified a default step size of #1 is used.
The For statement has the following syntax:
FOR[.size] op1 = op2 TO
op3 [BY op4] DO[.extent]
code
ENDF
or
FOR[.size] op1 = op2 DOWNTO op3 [BY
op4] DO[.extent]
code
ENDF
size - Optional B, W, or L, specifying the size of the operand comparison. These values correspond to the Byte, Word, or Long word data size. If any of the four operands is an address register, size may not be B (byte).
op1 - The counter register. Must be an addressing mode that allows modification of the destination.
op2 - The initial number to be stored in op1. May be any addressing mode.
op3 - The number to be counted up/down to. The direction of count is specified by either TO or DOWNTO. May be any addressing mode.
op4 - Optional amount to step by. If omitted, you must NOT include the BY keyword. The step defaults to one. May be any addressing mode.
extent - Optional value S or L, indicating the size of the forward branch to use (short or long).
code - The series of assembly commands executed until the counter op1 equals op3.
One space should be used to separate each part of the statement.
===Notes===
Immediate numbers may be used for op2, op3, and op4. To do this, simply place a # sign before the number. For example:
FOR.L D1 = #7 TO #36 BY #2 DO.S
code
ENDF
The FOR-TO loop is not executed if op2 is
greater than op3 upon entry. Similarly, the FOR-DOWNTO
loop is not executed if op2 is less than op3.
The FOR uses signed comparisons so the following code does not loop because #255
is interpreted as -1 on byte size comparisons. Changing from FOR.B to FOR.W or
FOR.L will correct the loop.
FOR.B D1 = #1 TO #255 DO.S
code
ENDF
The bits of the CCR (condition code register) are modified before the code is run.