Explanation Please
rpraver
Posts: 19
Based on the following code snipit can someone explain
why I had to use the LAB2 line to correctly store the address,
where as the LAB1 line is off by 16 bytes
Does it have to do with the 16 byte initializtion I see when I compile.
if so please explain why LAB1 does not work.
Should not the compiler produce the correct value for the LAB1 line
automatically?
why I had to use the LAB2 line to correctly store the address,
where as the LAB1 line is off by 16 bytes
Does it have to do with the 16 byte initializtion I see when I compile.
if so please explain why LAB1 does not work.
Should not the compiler produce the correct value for the LAB1 line
automatically?
DAT LAB1 word @LAB1 LAB2 word @LAB2 + $10
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Help to build the Propeller wiki - propeller.wikispaces.com
Please, please understand that @XXX in the DAT section are neither HUB nor COG adresses, but numbers to be used with the @@ operator.
When the compiler compiles an object, it doesn't know where the object goes yet. All the addresses are relative to the start of the object's hub memory. A later phase of the compiler shuffles everything around, combines multiple copies of the code and DAT areas. When the Spin @ operator executes, the relative address is made into an absolute address. That can't be done for constant @ operators in DAT constants like what you show. As a result, there's the @@ operator which adds the address of the start of the object at run-time. Note that this only affects Spin code.
In assembly code, there are two issues ...
1) The cog is long word addressable rather than byte addressable, so none of these constant byte addresses are valid
2) The assembly code is copied into the cog before execution and you can have more than one cog program in a Spin object. The assembler/compiler keeps two separate program counters, one is in bytes (for Spin use) and the other is in long words (for assembly use). When labels are used in assembly instructions, the assembly program counter is used. When labels are used in Spin, the Spin program counter is used. In constants, since they're intended mostly for use for tables in Spin, the Spin program counter is used.
Maybe there ought to be some variant of the LONG statement that forces the use of the cog program counter in expressions.
is valid assembly code that also honours the ORGs. It must in fact, as the numerical value of "label" has to be known from the beginning...
DAT
ORG 5
NOP
LABEL LONG LABEL
The compiler stores LABEL in the symbol table with a value of the number of bytes from the start of the object in which these statements occur.
Then, where LABEL is used as the expression of the LONG statement, the compiler uses the value (LABEL - START_OF_OBJECT)/4 + CURRENT_COG_ADDRESS.
So in this example, LABEL LONG LABEL compiles as the long value 6. (ORG 5 gives you 5, plus 1 for the NOP instruction)
Whereas LABEL LONG @LABEL would compile as the value in bytes of the offset of this statement from the start of the object.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Help to build the Propeller wiki - propeller.wikispaces.com
Post Edited (CardboardGuru) : 7/29/2007 4:06:24 PM GMT
3.5 to 3 wks into this environment.
I am only asking answers to observations that I have experienced.
Everytime I compile I have noticed that the DAT section reguardless of the location in the source
is always at the head of the output, it is always $10 (16 bytes offset from $0000. I just was wonder the meaning.
there my workarounfd was stating nothing more then
LABEL WORD @LABEL + $10
Works fine thats all.
LABEL WORD @LABEL
then execute WORD[noparse][[/noparse]@LABEL] += $10 before using it, or you could compute the entire value at runtime.
What you are observing is that the header of every program is 16 bytes in length, but programing the Propeller in the manner in which it was intended to be programmed, you should never have to account for this header in your calculations. What you observe is only true when compiling a single object. Once you have more than one you cannot count on the 16 byte relation between the object offset and memory location.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 7/30/2007 2:43:03 AM GMT
Praver, I answered ALL your questions some days ago in your other thread; sorry, that I must have got the impression, you were not really listening....