Shop OBEX P1 Docs P2 Docs Learn Events
Documenting self modifying code. — Parallax Forums

Documenting self modifying code.

BasherBasher Posts: 25
edited 2013-12-01 11:18 in Propeller 1
Are there any conventions or standards for documenting selfmodifying code?

I tried searching the web but all I seem to find are warnings that selfmodifying code is bad practice.

Any tips on making selfmodifing code understandable to others, and to myself when I come back to code I wrote a while ago?

Comments

  • potatoheadpotatohead Posts: 10,261
    edited 2013-11-29 10:25
    On the Prop, we like to use 0-0 as an argument for instructions we modify. Combine that with a label on the instruction and a comment detailing the modification added with the instruction doing the modifying and it's not bad.
         add        that, this
         MOVS       mod1, index        'this instruction writes index to mod1
         nop
         nop
    mod1 add        sum, #0-0        'source modified by MOVS above…
    
    
    
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-11-30 08:01
    i have been trying to sort out that #0-0 for a few months now.... Finally .... I do admit I should have just asked, but I've had enough other things to ponder as well.
  • tonyp12tonyp12 Posts: 1,951
    edited 2013-11-30 08:10
    #0-0 is just for human eyes to make this un-important value stand out (zero minus zero = 0)
    #128 or 1-1 or anything will work as it will be over written by a line of code before PC reaches there.
    If you are pointing to look-up table in cog ram etc.,
    you don't use a # as overwriting the lower 9 bits (with a movs) does not change the instructions i-flag (located at bit22)

    You could actually use a initial value,
    but most of the time it turns out that you do have a master loop outside this and need to reset it anyway.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-12-01 09:11
    Well, #0-0 taken literally kind of put me into a mental tailspin with the code I was reading. It makes sense now. It sent me back to reliving a rather traumatic start with algebra in juniior high school... about 50 year ago ;-0 But I have already recovered.

    The @@@ is another daunting bit of PASM for the new user, but I got past that.
  • potatoheadpotatohead Posts: 10,261
    edited 2013-12-01 11:01
    I never used @@@ as that was in Brad's tool.
  • Heater.Heater. Posts: 21,230
    edited 2013-12-01 11:10
    I thought @@@ made it into the Open Source Spin Compiler. And hence into SimpleIDE now.
    Isn't also in mparks HomeSpun compiler?
  • potatoheadpotatohead Posts: 10,261
    edited 2013-12-01 11:18
    Maybe. I just never used it.
Sign In or Register to comment.