[resolved][puzzle] PASM beginners: NOP, The
kuroneko
Posts: 3,623
Disclaimer: Just an idea I had after breakfast, maybe it works out maybe it doesn't. It probably doesn't give you a warm fuzzy feeling. It's to force you to find out what's available, how can it be used and use it to solve a particular task.
OK, let's try something else (after the first beginner puzzle disaster, I was grinning while writing this). There will be questions later to which I would like answers by PM initially. I don't mind helpful discussions in this thread but please keep solutions out of it until I say so. Now free for all.
The propeller data sheet tells us that a nop just elapses 4 clocks (while doing nothing). Proof it!
If this is too easy:
OK, let's try something else (after the first beginner puzzle disaster, I was grinning while writing this). There will be questions later to which I would like answers by PM initially. I don't mind helpful discussions in this thread but please keep solutions out of it until I say so. Now free for all.
The propeller data sheet tells us that a nop just elapses 4 clocks (while doing nothing). Proof it!
- What resources can be used/are available to measure cycles?
- How can those resources be applied to measure instruction timing?
- Devise at least two different ways to measure a nop!
If this is too easy:
- Pick an instruction of your choice which has non-constant timing.
- Establish its min/max timing (if applicable).
Comments
When I was a beginning Perl programmer, for example, I entered Perl "golf" challenges regularly. I never came close to winning one, but just trying them and reading (and attempting to decipher) the winners' code honed my Perl skills more quickly than any amount of "book larnin'" ever could.
These challenges are a great way to learn new programming techniques, and I would encourage anyone -- beginner and expert alike -- to try your hand at solving them.
BTW, I consider kuroneko-san to be the Zen Master of PASM programming. His hacks of the Propeller instruction set are cunningly brilliant, if not downright diabolical!
-Phil
I encourage anyone to at least try them when they come up.
I think that things like "how can you reduce this code" are very nice challenges (or how do I make it faster!). As well as understanding the cleverness of the Spin interpreter... that is a feat .
Your puzzles are great, especially the counter based ones used to trick/fool the instruction set.
BTW, we have the first entry for this challenge.
I found your puzzle very interesting, It's too much for me right now...I just started learning spin. Although I do want to learn pasm someday. It's nice to know there are many people out there that know it! You guys amaze me!
Wow! I'm now a Senior Member...does that mean I know something?!
It is a sticky at the top and called: "The Propeller Q&A Index Online!"
(Takes a while to load, but all good things must wait...)
To not confuse I will not use: neg Time1,cnt
The general idea everyone came up with was to sample a clock (cnt/phsx) before and after the code fragment, get the difference and adjust for instruction overhead.
- mov/mov/sub/sub
- mov/sub/abs/sub
- neg/add/sub
Depending on what you want to achieve (single delay, chained delays) each method has its (dis)advantage(s). Personally I stick with the first (which is not the reason it's listed first). Anyway, but wouldn't it be nice to get rid of the overhead adjustment? Think about those fragments:And with a cog counter (LOGIC:always, frqx = 1):
What's left? Yes, I asked for at least two ways of measuring the delay. Fat chance! I'll attach the source for an indirect method. Basically, I start an NCO counter and manually create an inverse wave on the same pin by using a basic loop. I picked clkfreq/64 which means we have 32 cycles for a half period, modifying outa and jumping takes up 8 cycles which leaves us 24 for 6 nops. If a nop does take 4 cycles then both waves cancel each other out or rather produce a solid high level on the output pin. If not (e.g. 5) then you'll see low pulses on the output which are caught by a NEGEDGE counter and displayed on the demoboard LED bank.