Shop OBEX P1 Docs P2 Docs Learn Events
Code Example: REP — Parallax Forums

Code Example: REP

potatoheadpotatohead Posts: 10,261
edited 2015-10-20 22:24 in Propeller 2
Here is another one. We may reverse the operands. That has not happened yet, but the label based syntax has. I came up with "FallThrough" as a way to get at that label ambiguity. Feel free to post up bugs, errors, whatever. I'll make the edits, and get a GitHUB doc started in the near future here.

If you have one you want to do, I suggest just using the same format. These are searchable in the forum easy.

REP - Repeat sequence of instructions as zero overhead loop

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

CCCC - Condition Codes

Opcode = %1101011 

D = Value sourced from Destination COG address
S = Value sourced from Source COG address

L = Destination Address mode:  0 = Value sourced from COG Destination Register 
                     	       1 = Immediate "#", value sourced from D instruction bits

I = Source Address mode:       0 = Value sourced from COG Source Register 
                     	       1 = Immediate "#", value sourced from S instruction bits


# = D as immediate value $0-$1ff

## = works with AUGD, AUGS for large immediate values $0-$7F_FFFF****

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


Examples:

Assembler will calculate proper values based on label:

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

The SHL and ADD instructions are executed 6 times, including the first time through the REP loop.  When REP is complete, it falls through to the next instruction identified by "@label" as shown with ".FallThrough" above.


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


PASM that results:


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, it falls through to the next instruction, JMP as shown above.

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, it falls through to the next instruction identified by "@label" as shown with ".FallThrough" above.

When a label is used, the assembler will calculate the correct value needed to include all the instructions BETWEEN the REP instruction and the fall through instruction, to be executed after REP has finished.

REP will terminate when a JMP 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
		add D, S

		[…]

count	long	5

Comments

Sign In or Register to comment.