Shop OBEX P1 Docs P2 Docs Learn Events
Question about REP (instruction repeating) — Parallax Forums

Question about REP (instruction repeating)

tomcrawfordtomcrawford Posts: 1,126
edited 2019-01-22 22:25 in Propeller 2
Can you have instructions that are skipped within a REP block?

Try as I might I cannot get this to work
REP @.Hex8End, #8
something, something
IF_LE  add Ascii, #$31    '0..9
if_GT  add Ascii, #$46    'A..F
something, something
.Hex8End

It only goes through the block one time whether I let the assembler decide what D is or if I count instructions myself.

If I use a counter and djnz, it works.

AdThanksVance

Edit: Answered my own question. "Any branch within....block will cancel REP activity." Naturally, I have a CALL #TxByte in the block.

Comments

  • I'm pretty sure conditional execution works inside REP blocks -- fastspin is careful to avoid branches inside REP, but it will generate IF_xxx, and I haven't seen any problems with that yet. In fact it definitely works in a simple case; in the attached code foo.bas and its translation foo.spin2, there's a loop:
    	rep	@LR__0002, #8
    LR__0001
    	sar	local01, #1 wc
     if_c	add	local02, #1
     if_nc	add	local03, #1
    LR__0002
    
    and the final values of local02 (count of ones) and local03 (count of zeros) are correct.
  • I was wondering why you left the actual code out and said "something, something" because the something something could be the important bit, which it seems it was. The only other thing I couldn't tell was whether this was executed from cog or hub since REP doesn't work in hubexec.

    BTW, the routine seems a bit odd, normally I'd convert a nibble to ASCII by always adding $30 and then adding 7 if result >$39, although I'm not sure quite what you are doing.
  • The only other thing I couldn't tell was whether this was executed from cog or hub since REP doesn't work in hubexec.
    REP works at least sometimes in hubexec (see my example above).

    The docs say that REP does work in hubexec, but doesn't really save you any time because it executes an internal jump. I guess that's what you meant?
  • ersmith wrote: »
    The only other thing I couldn't tell was whether this was executed from cog or hub since REP doesn't work in hubexec.
    REP works at least sometimes in hubexec (see my example above).

    The docs say that REP does work in hubexec, but doesn't really save you any time because it executes an internal jump. I guess that's what you meant?

    Ahem, ahem...... yes :)
    I just don't use it in hubexec but I must have forgotten the reason. I think at one time it actually didn't but then Chip made it so that it would just for compatibility's sake, although there was no advantage in speed. That's it.

    I find that as soon as hubexec involves looping, it slows it right down, but for non-branching and cordic, it is hardly much slower than cog.

  • tomcrawfordtomcrawford Posts: 1,126
    edited 2019-01-23 17:08
    BTW, the routine seems a bit odd, normally I'd convert a nibble to ASCII by always adding $30 and then adding 7 if result >$39, although I'm not sure quite what you are doing.

    Two precisely equivalent ways, assuming the nibble is in Ascii, all nice and isolated.
    add   Ascii, #$30
         cmp   Ascii, #$39  wcz
    if_GT  add  Ascii, #7      correct A..F
    
    cmp  Ascii, #9   wcz
    if_LE  add  Ascii, #$30
    if_GT add Ascii, #$37
    

    Three instructions each, same time to excute, same amount of cog space. But I think the second is more "Prop-ish".

  • Cluso99Cluso99 Posts: 18,069
    The second one uses both flags. Means the same routine doesn’t have the Z flag available for something else.
  •          rdlut  Ascii, Ascii
    
    If you've got space in the LUT ram...
  • evanhevanh Posts: 15,915
    Cluso99 wrote: »
    The second one uses both flags. Means the same routine doesn’t have the Z flag available for something else.
    		cmp     char, #10       wc    'test if below 10, C = borrow of (D - S)
    if_c		add     char, #"0"            'ASCII encode 0-9
    if_nc		add     char, #"a"-10         'ASCII encode a-f
    
    
  • evanhevanh Posts: 15,915
    Mark_T wrote: »
             rdlut  Ascii, Ascii
    
    If you've got space in the LUT ram...

    Ah, GETBYTE would be more compact:
    		ALTGB	char, #asc16tab
    		GETBYTE	char
    
Sign In or Register to comment.