How do you pass a global variable long to DAT block assembly code???
AmateurJack
Posts: 4
Hey everyone, I'm just starting out with the Propeller package and I am indeed impressed. Have hit a MAJOR SNAG, I can't succesfully read global variable value in a dat block assembly operation. I have tried addressing and read the manual, but can't figure it out. Example:
VAR
long time
PUB MAIN
cognew(@start, 0)
repeat
time := time +1
DAT
long t, @time ???????
RDLONG t, @time ??????
waitcnt clkfreq, t
QUESTION: How does one read what the value of time is in the main function at a certain point in time, from the DAT block , in ASSEMBLY? How do you put it in registers? I've tried specifying specific registers, like $1EF and thing like that, but cant get it to work. Can someone please help or point me in the correct direction? It would be much appreciated. Thanks,
-Jack
VAR
long time
PUB MAIN
cognew(@start, 0)
repeat
time := time +1
DAT
long t, @time ???????
RDLONG t, @time ??????
waitcnt clkfreq, t
QUESTION: How does one read what the value of time is in the main function at a certain point in time, from the DAT block , in ASSEMBLY? How do you put it in registers? I've tried specifying specific registers, like $1EF and thing like that, but cant get it to work. Can someone please help or point me in the correct direction? It would be much appreciated. Thanks,
-Jack
Comments
PUB MAIN
cognew(@start, 0)
repeat
time := time +1
DAT
long t, @time
:start RDLONG t, @time
waitcnt clkfreq, t
2) You're using ":start" which is a local label. This is used only where you need a label (like for a jump) that is only defined for a few lines of code (between two regular labels). It shouldn't be usable outside the DAT block. Use a regular label (without the ":").
3) The label in the COGNEW statement is that of the first memory location to be loaded into the cog AND the first location to be executed. The "long" that you have at the beginning of the DAT effectively doesn't exist to the cog routine.
4) The PAR register is intended to be used to pass the address of a parameter or parameter block to a cog. For an example like this, it's really easiest to use it. Remember that the low order 2 bits are always zero, so it must be the address of a long.
Heres the rule of thumb you should follow:
If you have a value you want to pass to a cog, and it will not be further updated after the cog has already started, declare it in the DAT section after the code for the cog (but not more than 496 longs after it's start), and assign it's value prior to calling cognew. After the cog starts running, it can directly access the local copy of the passed value without having to do a hub access.
If you have a value which needs further updating, declare it in the VAR section and pass a pointer to it and use hub access operations to get up to date copies of the value.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
-Jack