LOOPZ loc16,#16bit
6-127
LOOPZ loc16,#16bit Loop While Zero
SYNTAX OPTIONS OPCODE OBJMODE RPT CYC
LOOPZ loc16,#16bit 0010 1100 LLLL LLLL
CCCC CCCC CCCC CCCC
X − 5N+5
Operands loc16 Addressing mode (see Chapter 5)
#16bit 16-bit immediate value (0x0000 to 0xFFFF range)
Description Loop while zero.
while([loc16] & 16bit = 0);
The LOOPZ instruction uses a bitwise AND operation to compare the value
referenced by the “loc16” addressing mode and the 16-bit mask value. The
instruction performs this comparison repeatedly for as long as the result of
the operation is 0. The process can be described as follows:
1) Set the LOOP bit in status register ST1.
2) Generate the address for the value referenced by the “loc16” addressing
mode.
3) If “loc16” is an indirect-addressing operand, perform any specialized
modification to the SP or the specified auxiliary register and/or the ARPn
pointer.
4) Compare the addressed value with the mask value by using a bitwise
AND operation.
5) If the result is not 0, clear the LOOP bit and increment the PC by 2. If the
result is 0, then return to step 1.
The loop created by steps 1 through 5 can be interrupted by hardware
interrupts. When an interrupt occurs, if the LOOPZ instruction is still active,
the return address saved on the stack points to the LOOPZ instruction.
Therefore, upon return from the interrupt the LOOPZ instruction is fetched
again.
While the result of the AND operation is 0, the LOOPZ instruction begins
again every five cycles in the decode 2 phase of the pipeline. Thus the
memory location or register is read once every five cycles. If you use an
indirect addressing mode for the “loc16” operand, you can specify an
increment or decrement for the pointer (SP or auxiliary register). If you do,
the pointer is modified each time in the decode 2 phase of the pipeline. This
means that the mask value is compared with a new data-memory value each
time.
The LOOPZ instruction does not flush prefetched instructions fr4om the
pipeline. However, when an interrupt occurs, prefetched instructions are
flushed.