Shop OBEX P1 Docs P2 Docs Learn Events
"Aliasing" in PASM question — Parallax Forums

"Aliasing" in PASM question

K2K2 Posts: 693
edited 2014-04-25 01:20 in Propeller 1
Can't seem to get my head around Beau's use of phx in Sinewave_v2.1 The value is just an ADD instruction with specific S and D values, yet he does math on it. Say what?! Is that location simply being recycled, in lieu of REServing another long at the end of the DAT section?

Second question: How does one edit the title of a thread?

Comments

  • Heater.Heater. Posts: 21,230
    edited 2014-04-24 23:14
    I have not looked at the code but it sounds like he is doing some "self modifying code".

    For example in an instruction like:
        ADD  X, Y
    
    Y is the address form which the number to be added will be fetched. The source.
    If you look in the Propeller manual you will see that the source field of the add instruction is in the lower 9 bits.

    So, what happens if you add one to the ADD instruction itself?
    It will, when executed next time, add a different number to the Y. The next number up in COG memory from the last one it used.

    You can imagine using this for adding up arrays of numbers and so on.

    "Self modifying code" is a very common technique in Propeller PASM as it's the only way to make "indexed addressing" for when you want to step though arrays and such.

    Do note that you have to put an instruction or two (1 or 2?, I forget) between the instruction being modified and the one doing the modifying to let the change have time to take effect before it gets executed.


    Edit: Of course it could also simply be that the instruction you are talking about is only executed once at start up and then that space can be used as a variable afterwards.
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2014-04-24 23:18
    "Is that location simply being recycled, in lieu of REServing another long at the end of the DAT section?" - For the most part yes, the phx reads the current phsa, and then determines the delta to adjust the duty cycle before updating ctrb ... ctra runs a square wave of the desired frequency, ctrb runs a resulting sine wave by syncing to ctra's phsa register.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2014-04-24 23:34
    I can point back to ancient history, SPIN-CODE-EXAMPLES-FOR-THE-BEGINNER. There the phx variable was REServed. Beau's version put a nice interface on it. Clever trick to recycle one of the setup registers. It could have been any of them that are not in the main loop.
  • K2K2 Posts: 693
    edited 2014-04-25 01:20
    Many thanks, gentlemen! There is an interesting archaeological aspect to all your great contributions of the past. I'm intrigued by everything that happened before my birth on Planet Propeller. :)

    BTW, I note that Ahle2 carried on this register reuse tradition with 'out' in his nifty PropellerSignalGenerator.spin.
Sign In or Register to comment.