reps #16,@:loop ?
rjo__
Posts: 2,114
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
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
Look in on it that way
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
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.
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
#n number times
#i Instructions to loop
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:
Andy
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.
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