Shop OBEX P1 Docs P2 Docs Learn Events
In Praise of the Puzzlers — Parallax Forums

In Praise of the Puzzlers

CounterRotatingPropsCounterRotatingProps Posts: 1,132
edited 2009-08-26 16:53 in Propeller 1
Was originally going to post this as a reply to Steve's puzzler here:
http://forums.parallax.com/showthread.php?p=833552
but thought it might get lost in the thread...

Puzzles and·examples of this kind·can be very useful, IMO, for NOOBS like me and for Near-NOOBS (N-NOOB :) too.

These ideas are often lacking in the basic and general literature, e.g. the well-written Prop manual.· That material normally doesn't have the luxury of printed·space to address what we can learn by drilling down into a specific detail or problem. Having read a reasonable amount of Prop literature so far, I'd say that there's lack of intermediate - to advanced- level examples in the paper-written world of Beeniedom.· (I like consise things I can sit in a corner and read.)

The generousity of our wonderful forum members does well to fill the need.· But it would be nice to have a textbook on· 'Advanced Propeller Techniques'... until then... more puzzlers please, Mr. and Mrs.·Wizards!

Suggestions and rational:
  • Counter and PLL puzzlers - the counters seem to be in the 'arcana' area for intermediate to advanced
  • PASM to SPIN and back - I recall only one thread on calling SPIN from PASM - advanced?
  • PASM to HUB - e.g. cog mem to hub mem, cross-cog data sharing (locks, semaphores, etc. and inter-cog calls ?) - intermediate to advanced, and related:
  • Simple Memory Management·- yes, there's a ton happening with LMM and the various compilers and debuggers folks are working hard at - but the shear amount is overwhelming for N-NOOBs. Something·more byte-sized if you please.
  • " Breaking out of the box " - cool or unusual techniques --- the ones that leave you grabbing for the Excedrin Extra Strength bottle, or ones that make you say "Gee, I wish I'd thought of that!"·
  • Naughty Stuff:· self modifying code and code obfusication. The former is probably ok 'cause we have to do it in the limited mem. space; the latter might be a bad idea because it could inspire bad coding habits. (But usually the things that are bad for you are also the most fun devil.gif )
  • Very Specific methods - e.g. creative use of conditionals w/flags, shifting to multiply/divide, using the ROM math tables (seems to be a repeating topic.)
  • "shadow registers" - advanced
Cheers and thanks!
-· Howard

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


Post Edited (CounterRotatingProps) : 8/23/2009 9:35:36 PM GMT

Comments

  • jazzedjazzed Posts: 11,803
    edited 2009-08-22 18:26
    One of the nicest PASM examples to look at for ideas is Chip's spin interpreter/booter/runner code. Can't find the thread just now.
    I hope others embrace the puzzle idea. This weekend finds many Propeller users in an Ohio Gym, so responses may be thin for a while.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • kuronekokuroneko Posts: 3,623
    edited 2009-08-23 02:03
    OK, lets make a start. The usual disclaimer about usefulness applies [noparse]:)[/noparse] Condition of interest is NC && Z. What does this code fragment do?

    mov     cnt, value
    sub     cnt, #1 wc
    test    cnt, value wz
    
  • KyeKye Posts: 2,200
    edited 2009-08-23 03:11
    Nothing because you forgot to comment it. Right now its magic.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • SRLMSRLM Posts: 5,045
    edited 2009-08-23 03:25
    @kuroneko

    SPOILER! (Maybe)
    I'll try. My assumption is that the cnt register is updated every time, so writing to it (even though technically it's read only according to the manual but not the assembler) doesn't do anything long term. So the first line is to throw us off. The next line writes the C flag if the cnt is 0, otherwise it doesn't write the C flag (effectivly, !bool(cnt)). The final line tests to see if value and cnt share any bits set in the same places, and if there are shared location set bits, then the flag is set.

    That is my analysis.
  • kuronekokuroneko Posts: 3,623
    edited 2009-08-23 03:33
    SRLM said...
    My assumption is that the cnt register is updated every time, so writing to it (even though technically it's read only according to the manual but not the assembler) doesn't do anything long term. So the first line is to throw us off. The next line writes the C flag if the cnt is 0, otherwise it doesn't write the C flag (effectivly, !bool(cnt)). The final line tests to see if value and cnt share any bits set in the same places, and if there are shared location set bits, then the flag is set.
    Your assumption about cnt is - unfortunately - wrong. If it's used as destination register it behaves like any other (normal) register. So imagine I used temp instead (I'm just lazy and use pre-defined registers where possible). As for the rest, your observations are correct but what exactly does NC && Z mean for a given value? I'm not suggesting a full 4G range evaluation but try and apply this for e.g. [noparse][[/noparse]0..42].

    Post Edited (kuroneko) : 8/23/2009 3:43:30 AM GMT
  • KyeKye Posts: 2,200
    edited 2009-08-23 04:03
    Hmm, I thought read only registers had real problems when used for the desination.

    For example:

    tjz phsa, #loop

    That instruction will always jump even if phsa starts accumlating. If a wanted it to work properly I would need to do:

    mov buffer, phsa
    tjz·· buffer, #loop



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • kuronekokuroneko Posts: 3,623
    edited 2009-08-23 04:38
    phsa and phsb are not designated read-only registers (only par, cnt, ina and inb are). The effect you're seeing is that while writing to phsx updates shadow copy AND counter register, reading from them will give you either the shadow copy (destination slot) or counter register (source slot).
  • he1957he1957 Posts: 58
    edited 2009-08-23 07:43
    Since CNT is the global system counter used by all routines to determine delays and the like, your code will either hang any procedures that are using the counter because you are subtracting the count it gets updated by on each cycle, or, if the CNT gets incremented by each clock cycle and you are only subtracting one, then this would just cause a skew in timings, provide false results for counter related activities and I guess would screw up serial communications and other timeing critical activity.

    OK, so haw far did I miss by?


    HarryE.
  • kuronekokuroneko Posts: 3,623
    edited 2009-08-23 08:04
    he1957 said...
    OK, so haw far did I miss by?
    Quite a bit [noparse]:)[/noparse] cnt - as used for timing stuff (i.e. waitcnt) - is read-only. It can't be changed programmatically. Period.

    I mentioned before that if cnt is used in the destination slot of an instruction it behaves like a normal register (shadow copy). I really shouldn't have written it like this [noparse]:([/noparse] OK, for people who never encountered shadow registers the following version might be easier to understand:

    mov     temp, value
    sub     temp, #1 wc
    test    temp, value wz
    
    temp    res     1
    


    It has the same affect as the original fragment (apart from requiring one more register).

    Edit: There is one hint I'm prepared to give but I don't think it's that time yet.

    Post Edited (kuroneko) : 8/23/2009 8:12:11 AM GMT
  • ericballericball Posts: 774
    edited 2009-08-23 12:26
    Carry will be set if value is zero. Zero will be set if value was zero or had only a single bit set.

    I guess we can add "shadow registers" to the list of advanced topics.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Composite NTSC sprite driver: Forum
    NTSC & PAL driver templates: ObEx Forum
    OnePinTVText driver: ObEx Forum
  • kuronekokuroneko Posts: 3,623
    edited 2009-08-23 12:49
    ericball said...
    Carry will be set if value is zero. Zero will be set if value was zero or had only a single bit set.
    I can live with that explanation, NC && Z indicates that value is a power of two. Well done [noparse]:)[/noparse]
  • KyeKye Posts: 2,200
    edited 2009-08-23 14:14
    Okay I got one,

    What does this code do?
                        mov     buffer,               value                
                        xor     buffer,               XORMask                        
                        and     buffer,               ANDMask               
                        shr     buffer,               #1                         
                        or      value,                buffer 
     
    ANDMask             long    $AAAAAAAA                                       
    XORMask             long    $FFFFFFFF                                        
     
    buffer              res     1
    value               res     1
    

    The input is value and the output is the new modified value.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • CounterRotatingPropsCounterRotatingProps Posts: 1,132
    edited 2009-08-23 21:35
    ericball said...
    Carry will be set if value is zero. Zero will be set if value was zero or had only a single bit set.

    I guess we can add "shadow registers" to the list of advanced topics.
    > I guess we can add "shadow registers" to the list of advanced topics

    Done!

    Nice work eric!

    and thanks kuroneko·for the·puzzle!

    - H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • SRLMSRLM Posts: 5,045
    edited 2009-08-24 06:51
    @Kye

    It makes even numbers odd by adding one, and keeps odd numbers.
  • KyeKye Posts: 2,200
    edited 2009-08-24 11:46
    Close but not quite. Think a bit harder. smilewinkgrin.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • jazzedjazzed Posts: 11,803
    edited 2009-08-24 15:00
    Looks like part of a convolution encoder (a type of ECC) used for increasing reliability of data transfers. No doubt there is a simpler explanation though.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve

    Propeller Tools
  • KyeKye Posts: 2,200
    edited 2009-08-24 23:38
    Mmm, well it promotes every %00 to %01. Very helpful for doing graphics related stuff if you need to force the color space from 4 colors to 3.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • jazzedjazzed Posts: 11,803
    edited 2009-08-25 00:58
    Ok [noparse]:)[/noparse]

    This is very simple.
    1) what does "getit" do?, 2) what does mask do?, 3) give "alternative spellings" for "and".

    getit
      mask  long   $3
      and   mask,  ina  nr,wc,wz
    getit_ret ret
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve

    Propeller Tools
  • jazzedjazzed Posts: 11,803
    edited 2009-08-26 01:59
    No takers?

    1) It returns Z set if nothing is on pin P0 or P1 and C set if either but not both pins are set.
    2) mask is a nop instruction as is any long with the conditional bits clear.
    3) "and mask, ina nr,wc,wz" is long hand for "test mask,ina wc,wz" ... the compiler translates it for you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve

    Propeller Tools
  • KyeKye Posts: 2,200
    edited 2009-08-26 12:22
    This post I think is dead.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • CounterRotatingPropsCounterRotatingProps Posts: 1,132
    edited 2009-08-26 16:53
    Hi Kye,

    often we get distracted by life and work [noparse]:)[/noparse]) Several of our resident PASM gurus are on vacation too. I've not had time the last few days to study your puzzler or Steve's last... looking forward to it this weekend (even if the puzzles are solved [noparse]:)[/noparse].

    Keep in mind too please that folks can come back to these threads even years later for info.

    @ALL:

    One thing I've noticed is that it may get confusing to have the puzzles, guesses, hints, and answers interleaved in the same thread here. I'm not suggesting that we start separate threads for each new puzzle... that would get out of control quick.· Having them all in one mambo thread here is probably much better, do you think?· Perhaps the original puzzler poster could give their new puzzle a nickname and then we refer to it that way --- numbering probably would be a pain because you'd have to look back at count it right.
    What do you all think we can do to keep things separated better?

    {{ 
      PUZZLE Name: LazyBoy 
      What does it really do and is it legal code?
    }}
     
    :loop   NOP
            jmp #:loop
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sign In or Register to comment.