Shop OBEX P1 Docs P2 Docs Learn Events
Storing an array of longs in main memory — Parallax Forums

Storing an array of longs in main memory

Hello,

Im quite new to Propeller, so please excuse my stupid question:

How can i store a array of 48 longs in main memory? I want to calculate some values in Spin, afterwards the should be red in a assembly function.

Thanks for any help!

Comments

  • kwinnkwinn Posts: 8,697
    edited 2016-07-09 14:55
    VAR
      byte  val
      word  temp1
      long  array[48] 'like this
    
  • Area variables in The VAR block stored in Main Memory? Or only variables in The DAT block?
  • VAR variables are stored in hub memory and are initialized to zero on reset. DAT variables also begin in hub memory but can be transferred to cog memory if they are included in a 496-long block of data subjected to a cognew or coginit. DAT variables are not initialized to zero on reset and can be initialized to any values by the programmer in their definition.

    -Phil
  • csae8126 wrote: »
    Area variables in The VAR block stored in Main Memory? Or only variables in The DAT block?

    Short answer is yes.

    All of your code data and variables you define in your source will end up in hub memory after loading or starting your program.

    The difference is that in DAT you can define a initial value at startup (like for strings or PASM code or predefined 'vars') and in VAR blocks you just define a later on used memory location, but the initial value will be 0 at load/start time.

    VARs take less space in the saved binary on the disk file. (Not so really impotent nowadays)

    After your main program is loaded into HUB memory often the main program code will start other COGS with code out of some DAT Sections (even of SUB-Objects)

    It will copy the code from the HUB DAT Section into the COG Memory and start the COG.
    At that time the COG is running with his own copy of the code in the DAT Section in HUB Ram.
    And the original code in the DAT Section is mostly not needed until reboot, so often re-used as Buffer or something else. Usually COGs get loaded at Program start and again at reboot so the valuable HUB Memory space can (and often is by Objects) be reused...

    much fun with the propeller.

    Mike

  • Thanks a lot for the quick answers!
    I think i got it now, and after watching the memory contents in gear for a while i see how it works.

  • One other thing I didn't see mentioned already - if you create an object, and use that object multiple times in your code, VAR section variables are created for each instance of your object, whereas DAT variables are created once, and shared by all instances of that object.

    So, for example, if I create a thermometer object, and internally it maintains a "temperature" VAR value, that value would be unique to each thermometer object I create. If I created a "FarenheitOrCelsius" value in the DAT section, it would apply to all instances of the thermometer object.

    Welcome to the forums!
Sign In or Register to comment.