Shop OBEX P1 Docs P2 Docs Learn Events
[resolved][puzzle] PASM beginners: NOP, The — Parallax Forums

[resolved][puzzle] PASM beginners: NOP, The

kuronekokuroneko Posts: 3,623
edited 2010-09-09 18:54 in Propeller 1
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!
  • 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!
Answers as bad as an uncommented PASM fragment are fine. Just make sure they are working and give the correct result (that excludes hard-wired values). If it's done on the demoboard it would be nice if the result is shown on the LED bar. Otherwise storing it somewhere is just fine.

If this is too easy:
  • Pick an instruction of your choice which has non-constant timing.
  • Establish its min/max timing (if applicable).

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-09-02 21:49
    Hey, kuroneko, ease up on yourself, man! :) I didn't think the beginner puzzle was a disaster at all.

    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
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2010-09-03 00:41
    Ditto what Phil says... he's the one that usually keeps me on my toes with the golf challenges. It's good on the brain no matter what skill level you are, and for me at least, they are hard to pass up.

    I encourage anyone to at least try them when they come up.
  • AleAle Posts: 2,363
    edited 2010-09-03 01:03
    I always think of myself as very good at PASM... not true :). The last challenge made me think quite a bit.
    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 :).
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-09-03 03:26
    Kuroneko: By no means was it a disaster. It was a bit more complicated for a real beginner who just wants to learn how to do something. At that point in time, to do it successfully is all that is required. It is really easy to forget where we started out, particularly for me - its just on 40 years ago which was before the advent of microprocessors.

    Your puzzles are great, especially the counter based ones used to trick/fool the instruction set.
  • kuronekokuroneko Posts: 3,623
    edited 2010-09-03 03:37
    By popular demand I defused the wording in the first posting. It was never meant that serious. But it was kind of a mess :)

    BTW, we have the first entry for this challenge.
  • ihmechihmech Posts: 179
    edited 2010-09-03 06:58
    kuroneko,

    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?!
  • bill190bill190 Posts: 769
    edited 2010-09-03 17:01
    Clue: There is a clue to this puzzle lurking before your very eyes...

    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...)
  • tonyp12tonyp12 Posts: 1,951
    edited 2010-09-03 18:11
    I don't think I'm a beginner, but here it goes.
    To not confuse I will not use: neg Time1,cnt
    
    code deleted for now, as i saw above to not tell the answers here..........................
    
  • kuronekokuroneko Posts: 3,623
    edited 2010-09-05 07:52
    Just back in from the w/e (brother-in-law's wedding). And all I find is a second entry in this competition. From a self-proclaimed non-beginner :)
  • kuronekokuroneko Posts: 3,623
    edited 2010-09-09 18:54
    It's been a week. Let's put this worm back in the can.

    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     before, cnt
      [COLOR="Red"]nop[/COLOR]
      mov     after, cnt
      
      sub     after, before
      [COLOR="Blue"]sub     after, #4[/COLOR]           ' instruction overhead
      
    • mov/sub/abs/sub
      mov     mark, cnt
      [COLOR="Red"]nop[/COLOR]
      sub     mark, cnt           ' start time lost
      
      abs     mark, mark
      [COLOR="Blue"]sub     mark, #4[/COLOR]            ' instruction overhead
      
    • neg/add/sub
      neg     mark, cnt
      [COLOR="Red"]nop[/COLOR]
      add     mark, cnt           ' start time lost
      
      [COLOR="Blue"]sub     mark, #4[/COLOR]            ' instruction overhead
      
    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:
    neg     mark, #5
    waitcnt mark, #0
    [COLOR="Red"]nop[/COLOR]
    mov     mark, cnt
    
    And with a cog counter (LOGIC:always, frqx = 1):
    neg     phsa, #2
    [COLOR="Red"]nop[/COLOR]
    mov     mark, phsa
    

    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.
Sign In or Register to comment.