Shop OBEX P1 Docs P2 Docs Learn Events
define a variable in PASM-DAT-section and assign values in a SPIN-methodh with ":=" ? — Parallax Forums

define a variable in PASM-DAT-section and assign values in a SPIN-methodh with ":=" ?

StefanL38StefanL38 Posts: 2,292
edited 2011-08-25 12:07 in Propeller 1
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
DAT
...
Pin                             long            0-0
What 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 := |< inpin
Now 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-number
as 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-0
still 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 := |< inpin
Is 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

  • Cluso99Cluso99 Posts: 18,069
    edited 2011-08-25 00:56
    Spin can access the DAT variable space residing within hub ram. This is why it works.

    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.
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-08-25 12:07
    A label in HUB RAM is a label in HUB RAM for SPIN. It does not matter if it's defined in a VAR or in a DAT section.

    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.
Sign In or Register to comment.