Shop OBEX P1 Docs P2 Docs Learn Events
Self modifying quirk — Parallax Forums

Self modifying quirk

Jack BuffingtonJack Buffington Posts: 115
edited 2010-04-11 22:28 in Propeller 1
This one has been plaguing me for the past few days. I'm going to chalk it up to a bug in the silicon or the assembler. Not sure which. In my code, I need to do a computed jump. I have finally figured out what the issue is but it seems strange that I would have to do it this way. I'm just putting this up for others to reference. This is some sample code that does nothing like my real program but exhibits the same quirk. In short, if I modify this instruction, things don't work:
test01     jmp   0-0



If I try to modify this instruction, things work:

test01     jmp   #BB



Any thoughts on why this is happening?

-Jack
PUB Start(address)
    cognew(@test00,address)    
DAT

test00
              mov       dira,#255
              mov       temp,#0
              mov       jumpPoint,#8
              add       jumpPoint,#BB          'contains the correct address

              movs      test01,jumpPoint
              nop
        
test01        jmp       #BB     'BB is replaced with the correct address and it works      
              'jmp       0-0     'doesn't work.  Never makes it to the code below

BB            add       temp,#1
              add       temp,#1
              add       temp,#1
              add       temp,#1
              add       temp,#1
              add       temp,#1
              add       temp,#1
              add       temp,#1                 

              add       temp,#1                 ' should jump to here
              add       temp,#1
              add       temp,#1

              mov       outa,temp               ' should display 3 

              jmp       #test00


temp          res       1
jumpPoint     res       1

Comments

  • BeanBean Posts: 8,129
    edited 2010-04-11 20:56
    You need the # so the immediate bit gets set.

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
  • MagIO2MagIO2 Posts: 2,243
    edited 2010-04-11 21:21
    As Bean already figured out, you have to set the immediate bit, as you calculate the address and 'inject' it to the jump instruction. You inject the real address and not the address of a register that contains the address. That's the same as with all other instructions:

    mov tmp, #0
    mov tmp, 0

    do different things.

    My question ... you already reserved a variable to calculate the address. So, why do you do a movs at all? You can also jump to an address stored in a variable:

    jmp jumpPoint

    This way you don't need the movs and the nop!
  • Jack BuffingtonJack Buffington Posts: 115
    edited 2010-04-11 22:28
    Bean, got it. I just tried using this per your suggestion:

                  jmp       #0-0   
    
    


    and it works. I thought that I had tried that.



    MagIO2,

    It hadn't occurred to me that I could do it that way. That's great. It reduces the complexity and increases the speed of my program! I'm definitely going to do it that way now!


    -Jack
Sign In or Register to comment.