define a variable in PASM-DAT-section and assign values in a SPIN-methodh with ":=" ?
StefanL38
Posts: 2,292
Hi,
the magic_ir_demo from gadget gangster uses the magicir_010-object-file.
inside the file magicir_010.spin a variable "pin" is defined as a label for a long
to assign a value with the ":="-syntax and not with an adressoperator
My understanding of DAT-sections is:
I can define labels in a DAT-section as a global shared variable and then I can access this DAT-variable in SPIN via the "@"-operator.
If a DAT-section contains PASM-code, are labels like
when a cognew (@PASM-label,...) is executed. The DAT-section is copied to the COG-RAM
In the case above before the cognew is executed pin is assigned a new value
Why does it work with the ":="-syntax? I thought I'm forced to use the "@"-syntax for accessing DAT-variables, but the compiler does not complain.
Do I conclude right that if this works it offers a second method to tell PASM-code certain HUB-RAM-locations?
(First method is to use the second cognew-parameter that stores the value of the second cognew-parameter into PAR)
To trace down all the code details I attach the object to this posting.
Any explanations that help clearing this are much appreciated.
best regards
Stefan
the magic_ir_demo from gadget gangster uses the magicir_010-object-file.
inside the file magicir_010.spin a variable "pin" is defined as a label for a long
DAT ... Pin long 0-0What makes me wonder is that this label "pin" is used in the SPIN-method storecode
to assign a value with the ":="-syntax and not with an adressoperator
PUB storecode(inpin, codeptr, lengthptr) | i ... Pin := |< inpinNow does this work with any values or is this just working because in the DAT-section "pin" is assigned 0-0 and with calling the method
magicir.storecode(0, @code1, @code1len) ' first parameter is the IO-pin-numberas the value is zero too.
My understanding of DAT-sections is:
I can define labels in a DAT-section as a global shared variable and then I can access this DAT-variable in SPIN via the "@"-operator.
If a DAT-section contains PASM-code, are labels like
DAT ORG 0 pasm-commands .... ... Pin long 0-0still stored and accessible the same way as without PASM-code?
when a cognew (@PASM-label,...) is executed. The DAT-section is copied to the COG-RAM
In the case above before the cognew is executed pin is assigned a new value
PUB storecode(inpin, codeptr, lengthptr) | i ... Pin := |< inpinIs this working because the assignment is before the cognew(@PASM-label)?
Why does it work with the ":="-syntax? I thought I'm forced to use the "@"-syntax for accessing DAT-variables, but the compiler does not complain.
Do I conclude right that if this works it offers a second method to tell PASM-code certain HUB-RAM-locations?
(First method is to use the second cognew-parameter that stores the value of the second cognew-parameter into PAR)
To trace down all the code details I attach the object to this posting.
Any explanations that help clearing this are much appreciated.
best regards
Stefan
Comments
However, pasm cannot directly access the hub space. If the variable is within the DAT section, but is part of a pasm object, then that code gets loaded into cog ram via the cognew command. That is why pasm can now access the variable within its own cog ram.
BUT, remember spin cannot access the cog and pasm can only access the hub indirectly. So therefore, the variable would not be identical if both pasm and spin were to access the same variable, as they really reside in different spaces.
And yes, that's a way to configure a PASM code. Before you start the PASM you simply fill some DAT variables with actual values and then start the PASM. That's propably a better way to configure a PASM which has no need to be reconfigured after it has been started because you save the PASM instructions for reading from HUB-RAM.