Creating a loop

A loop is created using a loop counter and the conditional branch instruction BNE.

  • Choose a data register as the loop counter. Before entering the loop, set the loop counter to the number of times the loop is to be executed.
  • A label is placed in front of the first instruction of the loop. It is good to give the label a meaningful name. Often it is called loop.
  • At the end of the loop, subtract 1 from the loop counter. If the counter is not zero control branches back to the first instruction of the loop, otherwise control moves to the instruction immediately after the loop.