Skip to content
Matthijs van Duin edited this page Apr 9, 2018 · 2 revisions

Loop instruction - random notes

Loop instruction peculiarities:

  • Loop counter is taken from the lowest 16 bits of the register operand.
  • Loop count in the machine opcode is one less than the actual loop count (0 for 1 iteration, 1 for 2 iterations and so on). The assembler automatically takes care of this, so user should write the loop count directly.
  • Compiler must guard against "short" loops (0 or 1 instruction body) by inserting NOPs.
  • Compiler must guard against "long" loops (number of instructions in the body is 256 or more) by rejecting HW doloop and using regular cbranch.
  • Compiler should be able to emit LOOP with constant count value.
  • Compiler should be able to emit LOOP with register count value.
  • Compiler must emit valid opcode even if count value expression is QI, HI or SI.
  • Compiler should reject LOOP insn emit if body contains function calls or assembler blocks.
  • Compiler should handle correctly jumps to- or after- the loop body.
Clone this wiki locally