REP D#/S# - Repeat sequence of instructions as zero overhead loop

CCCC 1100110 1LI DDDDDDDDD SSSSSSSSS REP D/#,S/#

Opcode = %1101011

Destination = Number of instructions to repeat -1 (Count from 0)

Source = Number of times instructions execute, including first time through repeat loop

L = Destination Value addressing modes:

0 = "D" instruction bits specify COG register address which contains value 
1 = Immediate "#" means "D" bits specify value directly ($0-$1ff)

I = Destination Address modes:

0 = "S" instruction bits specify COG register address which contains value 
1 = Immediate "#" means "S" bits specify value directly ($0-$1ff)

CCCC - Condition Codes

Rep works with AUGD, AUGS to assign 23 bit immediate values to both D and S operands. ($0 - $7F_FFFF)

Use "##" to specify large values. Assembler will insert AUGx instructions at address of REP instruction:

        AUGD    #$7F_FFFF —--> target D
        AUGS    #$7F_FFFF ---> target S
target   REP    #D, #S

Code Examples:

Assembler will calculate proper values based on label when "@" is present in Destination operand:

                REP #@FallThrough, #6
                 shl  D, S    
                 add  D, S
FallThrough     JMP    #elsewhere

The SHL and ADD instructions are both executed 6 times, including the first time through the REP loop. Once REP has completed all execute cycles, program control continues to the next instruction identified by "@FallThrough."

For Large Immediate Values, you write:

start    REP    #1, ##10000    'Assembler will insert AUGS at label “start”
          shl  D, S            ‘Instruction 0
          add  D, S            ‘Instruction 1, for a total of 2
         JMP    #elsewhere

The assembler will generate these instructions:

start        AUGS    #10000         ’23 bit immediate value —> modify REP
modify        REP    #1, #S         ‘value comes from AUGS
               shl  D, S            ‘Instruction 0
               add  D, S            ‘Instruction 1, for a total of 2
              JMP    #elsewhere

The SHL and ADD instructions get executed 10000 times, including the first time through the REP loop. When REP is complete, the next instruction, JMP as shown above will execute.

When computing the number of instructions to be repeated, start your count from 0. Two instructions are shown above, for a count total of 1. (number of instructions - 1)

Mixed Values:

               REP #@FallThrough, count
                shl D, S    
                add D, S
FallThrough    JMP    #elsewhere

    […]

count        long    5

The SHL and ADD instructions get executed 5 times, including the first time through the REP loop. The COG register at label "count" contains the number of times REP instructions get executed. When REP is complete, the JMP instruction will execute, identified by label "FallThrough."

REP will terminate when a branch type instruction leaves the set of instructions included in the REP zero overhead loop:

               REP #@FallThrough, count
                shl D, S            ‘instruction 0
                cmp D, S  WZ            
       if_Z     jmp #out            ‘when taken, cancels REP entirely
                add D, S    
FallThrough    JMP    #elsewhere    ‘executed when REP completes normally

               […]

out            nop                   'Out of REP instruction loop
               add D, S

               […]

count    long    5                   'Repeat count