Shop OBEX P1 Docs P2 Docs Learn Events
PASM noob question — Parallax Forums

PASM noob question

Bobb FwedBobb Fwed Posts: 1,119
edited 2009-02-06 03:56 in Propeller 1
I have some PASM programs with a few #:loop's in it, and I was wondering how the program know which :loop to go to? Is it the closest one? I've found it seems to work fine going to a close :loop below the JMP or above. I'm sure there is a simple answer.

Comments

  • KyeKye Posts: 2,200
    edited 2009-02-04 20:03
    The : is for people who can't think of another name for a loop...

    Basically the compilier assigns the jmp to the closest :loop.

    Becareful with this. I would strongly reconmend you do not use the : and strech your brain a bit to give your loops good labels.

    Assembly is not good for debuging, if a problem comes up it takes a great deal of errort to fix it.

    If you want to use the : use it only once or twice far apart in the program.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Mike GreenMike Green Posts: 23,101
    edited 2009-02-04 20:03
    The scope of the local label (":loop") is from one ordinary label to the next ordinary label and has nothing to do with closeness.
    FirstLabel
    
    :loop
       jmp  #:loop       ' Refers to the :loop in the same "block" of code ... between FirstLabel and SecondLabel
    
    SecondLabel
       jmp  #:loop       ' Refers to the :loop in the same "block" of code ... between SecondLabel and ThirdLabel
    :loop
    
    ThirdLabel
    

    I think local labels are very useful for some things.· There are always jumps that go somewhere close and the actual label used really doesn't make any difference in understanding the program.· Those are the places where local labels are very useful.· If I have a short subroutine, maybe 10-20 instructions, that includes a loop or some jumps associated with a test, local labels work great.· In the rest of the program, who cares what label I use within the short subroutine.· Larger subroutines or more complex code is a different story.· Again, local labels are great over a short span, maybe 10-30 instructions.

    Post Edited (Mike Green) : 2/4/2009 8:10:39 PM GMT
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2009-02-04 21:17
    Thanks, so local labels only apply to JMPs within other "standard" labels. That make life a little easier.
  • TreeLabTreeLab Posts: 138
    edited 2009-02-05 02:39
    Ok, I am astonished now! I had no idea that the PASM assembler would even accept multiple uses of the same label. I am with Kye on this one : use unique labels for unique destinations. In any other environment this would be called a bug ...

    Cheers!
    Paul Rowntree
  • Mike GreenMike Green Posts: 23,101
    edited 2009-02-05 02:46
    It's not a bug ... It's a feature ... and a useful one that you can completely ignore if you don't like it.
  • potatoheadpotatohead Posts: 10,261
    edited 2009-02-05 04:36
    It's a local label.

    One way to use it is to always use the same kind of label for the same kind of program flow or data construct. Then use the unique labels to identify other areas in the program that are going to be specific to that program.

    If you want to do that, one pleasant side effect is being able to cut 'n paste code without having to worry about a label conflict. Another is when you do see a conflict, and it's local, then you've got a flow issue.

    Either it's useful, or it isn't. Depends on your style really.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
    Chat in real time with other Propellerheads on IRC #propeller @ freenode.net
    Safety Tip: Life is as good as YOU think it is!
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2009-02-05 07:06
    to agree with potatohead, I use :loop for common loops, especially when I use DJNZ. I also commonly use :skip if there is a portion of conditional code that may not need to be run, and I use :wait if I am running a loop that will terminate after a certain amount of time (used when something is being executed while "waiting", rather than just a waitcnt).
    Now that I am confident on how local labels work, they are very useful and doesn't force me to come up with labels that wouldn't be very portable to other programs.
  • AleAle Posts: 2,363
    edited 2009-02-05 09:29
    My money is in... unique labels!. No local labels for me smile.gif. Not that using loop_1 to loop_500 is less confusing... but they are unique smile.gif.
  • JasonDorieJasonDorie Posts: 1,930
    edited 2009-02-05 09:36
    I couldn't resist: Always remember that you're unique, just like everyone else. [noparse]:)[/noparse]

    Local labels are not really much different than local variables. Do you uniquely name all of those as well? [noparse];)[/noparse]

    Jason
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2009-02-05 10:52
    Mike Green said...
    It's not a bug ... It's a feature ...

    I Have always loved that line ! ..

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Necessity is the mother of invention'

    Those who can, do.Those who can’t, teach.
  • KyeKye Posts: 2,200
    edited 2009-02-05 14:52
    Hmm, for me I find that everything has an unique name, its just up to you to find it. Its kinda of like a good mental challenge when you force yourself to name and label everything.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Paul RowntreePaul Rowntree Posts: 49
    edited 2009-02-06 03:56
    Kye said...
    I find that everything has an unique name, its just up to you to find it

    This is almost Zen-like! Does anyone remember a short story by Arthur C Clarke, "The Nine Billion Names of God"?

    Cheers!
    Paul Rowntree
Sign In or Register to comment.