Shop OBEX P1 Docs P2 Docs Learn Events
reps #16,@:loop ? — Parallax Forums

reps #16,@:loop ?

rjo__rjo__ Posts: 2,114
edited 2013-09-07 21:50 in Propeller 2
I have been looking through various posted code sources and the unofficial P2 documentation.

in the P2 documentation I find: "REPS #n,#i - execute 1..64 instructions 1..16384 times, requires 1 spacer instruction *


the line: reps #16,@:loop comes from ozpropdev's space invader game. http://forums.parallax.com/showthread.php/149825-PROP2-Invaders-1-Cog

Does this line repeat the entire :loop 16 times or repeat the first instruction found at :loop? ... or something entirely different?

Thanks

Comments

  • SapiehaSapieha Posts: 2,964
    edited 2013-09-07 09:49
    Hi rjo

    Look in on it that way

    rjo__ wrote: »
    I have been looking through various posted code sources and the unofficial P2 documentation.

    in the P2 documentation I find: "REPS #n,#i - execute 1..64 instructions 1..16384 times, requires 1 spacer instruction *


    the line: reps #16,@:loop comes from ozpropdev's space invader game. http://forums.parallax.com/showthread.php/149825-PROP2-Invaders-1-Cog

    Does this line repeat the entire :loop 16 times or repeat the first instruction found at :loop? ... or something entirely different?

    Thanks
  • rjo__rjo__ Posts: 2,114
    edited 2013-09-07 09:56
    Jag f
  • SapiehaSapieha Posts: 2,964
    edited 2013-09-07 10:01
    Hi rjo.

    Look on colours that mark instruction in My first post.
    That answer what part are for how many instructions after spacer are repeated and second colour how many times that loop are executed.

    Men jag f
  • rjo__rjo__ Posts: 2,114
    edited 2013-09-07 11:03
    Yes. Now I understand what you said.

    I have now reversed that in my head twice.
    So,
    #n=16 (number of instructions)
    but
    #i=@:loop... ? (what is the number of times?) I don't understand that.
  • tonyp12tonyp12 Posts: 1,951
    edited 2013-09-07 11:54
    From one example I seen:
    REPS #20_000,#4 'execute 4 instructions 20,000 times (but max is 16k?)

    So it's "REPS #n,#i - execute [n]1..16384 times for 1..64 instructions

    so the @:loop will calculate how many instructions, so you don't have to adjust if every time you delete or add a line in the loop.
    Dett var inte s
  • SapiehaSapieha Posts: 2,964
    edited 2013-09-07 12:09
    I se now I have reversed Values ---- Sorry

    #n number times
    #i Instructions to loop
    Sapieha wrote: »
    Hi rjo

    Look in on it that way
  • rjo__rjo__ Posts: 2,114
    edited 2013-09-07 12:58
    I think we are getting there but not quite:)

    Where is the documentation for how @:loop will be interpreted in this circumstance? How does it become a number? it looks like a pointer to an address.
  • cgraceycgracey Posts: 14,151
    edited 2013-09-07 14:06
    In a single-task program, REPS needs one spacer instruction. If it's getting every other time slot, it doesn't need a spacer. I forgot about this the other day in the interpreter. See prop2docs.txt.
  • AribaAriba Posts: 2,690
    edited 2013-09-07 17:39
    rjo__ wrote: »
    I think we are getting there but not quite:)

    Where is the documentation for how @:loop will be interpreted in this circumstance? How does it become a number? it looks like a pointer to an address.

    >How does it become a number?
    The Assembler calculates something like: #:loop - $ - 1 and uses that for the instruction count.
    The use of @ is a bit ugly because that character has already so many different meanings.

    It is not officially documented, but you can find it in some of Chips PASM codes. I don't know if this will make it into the final P2-Assembler, with that character. And as Chip said the calculated number must be different with more than 1 task. But how can the Assembler know at compile time if you use more than 1 task (this can change at run time)?
    So maybe it's a good thing that it is not documented - if you use it, use it at your own risk.

    Actually you can do the same with:
    ' 1 Task
     reps #times,#:loop-$-1
     spacer instr
          looped instr1
          looped instr2
    :loop looped instr3
    
    ' 2..4 Tasks
     reps #times,#:loop-$
          looped instr1
          looped instr2
    :loop looped instr3
    

    Andy
  • rjo__rjo__ Posts: 2,114
    edited 2013-09-07 19:11
    OK... was hoping for something a little less prosaic... but prosaic is fine with me.

    I like the @ in this case and I personally wouldn't change a thing.

    a little document... "Before you use @... readme:)" would be sufficient.

    I really hate it when Chip responds to my posts. I really don't want to waste his time.

    You guys need to step up a little faster:)
  • cgraceycgracey Posts: 14,151
    edited 2013-09-07 21:12
    rjo__ wrote: »
    OK... was hoping for something a little less prosaic... but prosaic is fine with me.

    I like the @ in this case and I personally wouldn't change a thing.

    a little document... "Before you use @... readme:)" would be sufficient.

    I really hate it when Chip responds to my posts. I really don't want to waste his time.

    You guys need to step up a little faster:)

    No worries, please. Earlier this week when I was working on the interpreter and I tested it under multitasking, the whole thing blew up and I couldn't figure out why. I eventually narrowed to my use of REPS and REPD. It was repeating my spacer instruction, and not the one after it (REPS situation). I was thinking I must have discovered an awful hardware bug. I went to look at the Prop2Docs.txt, and lo and behold, I had already documented that in a multitasking context, there may be ZERO spacer instructions needed. I had no recollection of this matter. I hope I get all this done before I can't remember anything.

    The use of @ is a little misguided, I agree. It works for single-task programming, but not for multi-tasking. I'll probably get rid of it and show how to do 'end'-'start' labels, instead.
  • ozpropdevozpropdev Posts: 2,792
    edited 2013-09-07 21:50
    cgracey wrote: »
    I went to look at the Prop2Docs.txt, and lo and behold ....

    Chip

    May I suggest placing the Prop2Docs.txt file in a "sticky" at the top of this forum.
    I stumbled on this document by accident buried in a post somewhere.
    This was weeks after starting on the FPGA route.
    Just an idea.

    Cheers
    Brian
Sign In or Register to comment.