Loop directives



REPEAT nb_repetition,variable_counteur,start_value,step_value

Parameters "variable counter", "start value" and "step value" are optional

The directive allows to repeat a block of instructions. You can either set a number of repetitions, or use the conditional mode with the UNTIL block end directive. For compatibility with Vasm, it is possible to end a block with ENDREP or ENDREPEAT instead of REND

repeat 10 : ldi : rend ; produce 10x LDI
repeat 10,x : ld a,x : rend ; produce LD A,1 : LD A,2 : LD A,3 ... LD A,10
cpt=90 : repeat : defb cpt : cpt=cpt-2 : until cpt>0 ; produce sequence 90,88,86, ... 2, 0
repeat 5,x : print x : rend ; display 1,2,3,4,5
repeat 5,x,0 : print x : rend ; display 0,1,2,3,4
repeat 5,x,0,2 : print x : rend ; display 0,2,4,6,8

STARTINGINDEX [value[,increment]]

By default, REPEAT loops start their counter at 1. It is possible to change this behavior for all subsequent REPEATs by specifying a value to this directive: typically zero, but you can specify any value.
The second parameter (optional) is the increment value (1 as default)
Without parameter, increment and starting value are reset to 1

repeat 5,x : print x : rend ; display 1,2,3,4,5
startingindex 0
repeat 5,x : print x : rend ; display 0,1,2,3,4


WHILE condition : WEND

Repeats a block as long as the declared condition is true. At any time (inside the loop) it is possible to use the internal variable WHILE_COUNTER to get the loop counter.

while cpt>0
  print 'cpt=',cpt,' while_counter=',while_counter

Will produce the following output on the console

cpt= 4.00 while_counter= 1.00
cpt= 3.00 while_counter= 2.00
cpt= 2.00 while_counter= 3.00
cpt= 1.00 while_counter= 4.00
cpt= 0.00 while_counter= 5.00


These keywords are to be used as a variable inside a loop from which you want to get the counter. Not very practical use except in a WHILE, prefer to declare a variable during the REPEAT, believe me ;)

Sauf mention contraire, le contenu de cette page est protégé par la licence Creative Commons Attribution-ShareAlike 3.0 License