Contradictory information in Propeller Manual?
Wossname
Posts: 174
I'm confused about how PASM code is loaded into a Cog. The manual seems to contradict itself
Huh?
Can someone draw a picture for me? In crayon preferably.
This code was artificially pushed into upper Cog RAM space by the ORG statement, causing the code to overlap the first special purpose register ($1F0) and causing the FIT directive to cause a compile-time error when the code is compiled.
ORG only affects symbol references; it does not affect the position of assembly code in the cog itself. When assembly code is launched via a COGNEW or COGINIT command, the destination cog always loads the code into its RAM starting at address 0.
Huh?
Can someone draw a picture for me? In crayon preferably.
Comments
I think the first quote should have been worded "The assembly pointer for this code was artificially adjusted, causing the pointer to indicate a Cog RAM location that would overlap the first special purpose register ($1F0) and . . ."
Now, let's look at the first example: Now, if you were foolish enough to use ORG 492 (without the FIT) and do a coginit( @Toggle, 0 ), then the mov dira, Pin would get stored in register 0 and be executed first. But the source value would be retrieved from register 496 (PAR), not Pin which would be stored in register 4. The code would execute until it hit the jmp #:Loop and then it would continue execution with register 493, which would be loaded with whatever data was in HUB RAM 495 longs after Toggle.
I almost wrote a post (I actually just wrote it but I didn't submit it) asking for a second opinion.
So the Prop Tool uses the "ORG" to fill in the appropriate cog address for the labels within the PASM code?
But the code is loaded starting in long #0 no mater what value is used with "ORG"?
Turbosupra's thread about direct addressing has recently got me thinking about this.
ORG only affects the symbol address pointer used by the assembler during source code processing. It does not affect where the code actually gets loaded into the cog, as it mistakenly implies; PASM code launched with COGINIT or COGNEW always get's loaded into Cog RAM starting with address 0. The code example wouldn't do anything useful if the ORG was other than 0, unless the developer had specific reason, and took specific measures in the way it was written, to make it take advantage of the non-0 symbol-addressing created by ORG >0.
Duane: Yes, the Propeller Tool uses ORG to determine where the next assembled symbol address will be logically placed in Cog RAM (but does not affect the actual placement of executable code, symbolically defined longs, or reserved longs. And, yes, the code is loaded starting at long #0 regardless. The developer can use ORG other than 0 for some advanced uses, such as assembling code that will be physically moved into the correct registers during run-time, for instance.
Yes, non-zero ORGs probably require some additional clarification, including when it would be used. I think part of the problem is assemblers for other processors use the ORG (and RES) directive to change where code is stored in memory so that's what people expect.
Right, and indeed it stumped me at first when I was testing it out for the first (or second) time.
One of nice things that Org can use other address that 0 is possibility to write code blocks for on fly loading in desired address.