Question on ORG and PASM

I see this a lot in PASM code:
org 0
blah....
blah....
blah...

org 0
blah...
blah...
blah...

Basically, setting the code to start at address 0 (org 0) but then, later on...doing it again.

So, what is the purpose of that? I assume it's for space optimization or something like that.

Thanks.

Comments

  • 6 Comments sorted by Date Added Votes
  • I would do that if I had two different PASMs that were going to run in two different cogs.
    Re-inventing the wheel is not a waste of time if, when you are done, you understand why it is round.
    Cool, CA, USA 95614
  • When a cog is started, it begins execution at location 0, so PASM code intended for loading into a cog starts with ORG 0. If you have several pieces of code, each to be loaded into a cog, you'd start each with ORG 0. ORG resets the code origin in the assembler to the address given. There's a different pointer that specifies where in hub memory the code will be loaded. Look in the Propeller Manual for the sections on DAT and ORG for examples.
  • Like a lot of things ORG works a little bit different in PASM as in other assemblers.

    So if you do a - say ORG 20 - it will NOT start your code at COG address 20 but will assemble it as if it would sit at address 20 but still load it at address 0 into the COG.

    This sounds stupid, but is - as usual with @chip - a interesting feature.

    Some of @chips video drivers did that, so that is where I found, stumbled upon, and smiled about it.

    So in general you should always use ORG 0 in your PASM code.

    But if you want to assemble PASM that will be relocated inside of a COG (like @chip does in his code) you can use ORG whatever to assemble the code as if it sits at whatever and move it inside your program to the real location, where then the code assembled to run at is working correct.

    Enjoy!

    Mike
    I am just another Code Monkey.

    A determined coder can write COBOL programs in any language. -- Author unknown.

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this post are to be interpreted as described in RFC 2119.
  • Just to clarify ... ORG n will assemble the following code as if it were loaded at location n, but it has no effect on where the code actually loads. The COGINIT/COGNEW instruction specifies the starting hub address for the code which always loads starting at cog location 0. This starting hub address may or may not be the long word with the ORG 0 in front.
  • Yeah, not easy to formulate, not sure if your "This starting hub address may or may not be the long word with the ORG 0 in front" is clearer then my stumbling words about it.

    But it is what it is...
    Enjoy!

    Mike
    I am just another Code Monkey.

    A determined coder can write COBOL programs in any language. -- Author unknown.

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this post are to be interpreted as described in RFC 2119.
  • Could someone link to a simple example?
    I Am One With the Forth and the Forth Is With Me
Sign In or Register to comment.