PASM and local variables...
Chris_D
Posts: 305
Hi everyone,
I am confused about variables within a PASM program.·· There was a recent post that, while at first seemed to clarify the situation, ended up confusing me more.
Here is what I am doing...
I have a PASM object that needs to be loaded into 3 different COGS (eventually 4 COGs).· Within that object, there are a number of "local" variables that are used in calculations etc.· I need to make sure that these variables are exclusive to that COG so that the other COGs running the same oject don't change the values.
Currently, I am declaring variables two ways within my PASM object...
Method #1
··· SlowVel················ Long··· 600_000
··· McmReady·············Long··· 99· 'Default to not ready
··· mSecDelay············ Long··· 80_000 'equals one millisecond
Method #2
··· mSecElapsed··········· Res···· 1
··· mSecPrevCnt··········· Res···· 1
··· mSecIntCnt············· Res···· 1
I suspect I could use either method, with Method #1s advantage being that I can preset the value at the time of declaration.· However, it would be very easy to use Method #2 and simply set the variable to a preset value at the start of the program.
As mentioned, the gray area is the "protection" of these variables from being changed by other COGs running the same code.· Furthermore, is using one type of variable declaration faster (during program execution) than the other?·
Chris
·
I am confused about variables within a PASM program.·· There was a recent post that, while at first seemed to clarify the situation, ended up confusing me more.
Here is what I am doing...
I have a PASM object that needs to be loaded into 3 different COGS (eventually 4 COGs).· Within that object, there are a number of "local" variables that are used in calculations etc.· I need to make sure that these variables are exclusive to that COG so that the other COGs running the same oject don't change the values.
Currently, I am declaring variables two ways within my PASM object...
Method #1
··· SlowVel················ Long··· 600_000
··· McmReady·············Long··· 99· 'Default to not ready
··· mSecDelay············ Long··· 80_000 'equals one millisecond
Method #2
··· mSecElapsed··········· Res···· 1
··· mSecPrevCnt··········· Res···· 1
··· mSecIntCnt············· Res···· 1
I suspect I could use either method, with Method #1s advantage being that I can preset the value at the time of declaration.· However, it would be very easy to use Method #2 and simply set the variable to a preset value at the start of the program.
As mentioned, the gray area is the "protection" of these variables from being changed by other COGs running the same code.· Furthermore, is using one type of variable declaration faster (during program execution) than the other?·
Chris
·
Comments
LONG is used to have an initialized constant, RES for a not initialized (means it will contain the garbage hat follows for DAT section or the rest of it when copied to cog memory. So do not place any value in a RES defined variable (because it is only a placeholder, a trick for the compiler: there is no space reserved in HUB memory).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit some of my articles at Propeller Wiki:
MATH on the propeller propeller.wikispaces.com/MATH
pPropQL: propeller.wikispaces.com/pPropQL
pPropQL020: propeller.wikispaces.com/pPropQL020
OMU for the pPropQL/020 propeller.wikispaces.com/OMU
I guess what had me confused is the other thread made mention of Full Duplex Serial not being able to run in two COGs, wasn't sure I understood why.· But I susect it was because of the addressing used back to the hub memory variables.
Thanks!
Chris
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Composite NTSC sprite driver: Forum
NTSC & PAL driver templates: ObEx Forum
OnePinTVText driver: ObEx Forum