Shop OBEX P1 Docs P2 Docs Learn Events
Propeller Memory Configuration — Parallax Forums

Propeller Memory Configuration

Vega256Vega256 Posts: 197
edited 2011-06-22 13:53 in Propeller 1
Hey,

If the Propeller deals in 32-bit longs, then if I declare two bytes next to one another, does the Propeller allocate two longs and just use the first eight bits of them or allocate two successive bytes within one long?

Comments

  • potatoheadpotatohead Posts: 10,261
    edited 2011-06-22 12:50
    All addresses are aligned to byte, word and long boundaries for HUB addressing.

    For a long, the least two significant bits are assumed to be zero. For a word, the least significant bit is zero. For bytes, all bits are significant.

    In the COG, there is only LONG addressing.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-06-22 12:56
    I'm pretty sure this is mentioned in the manual.

    The variables are arranged long, word, byte at compile time. There aren't empty bytes between each byte variable. In your example the two bytes are within one long.

    Individual bytes are addressable in hub RAM. Cog RAM is addressable only by longs.

    Edit: PHead bet me to it. And did a better job explaining things.
  • Vega256Vega256 Posts: 197
    edited 2011-06-22 13:09
    I see, so then, let's suppose that I have a parameter list of two variables. The first parameter is a long, the second is an array of bytes. I want to use these as shared data between a SPIN program and a PASM program, so I pass in the address of the first parameter by way of par. What are the addresses of each element in the byte array with respect to the address of the long?
  • Mike GreenMike Green Posts: 23,101
    edited 2011-06-22 13:53
    There's not enough information in what you describe. First of all, there's no implicit notion of a parameter list between a SPIN program and a PASM program. Second, you can't pass an array of bytes from one SPIN method to another. You can pass the address of an array.

    If you want to pass a long value and the address of an array of bytes (another long value), you could do something like:
    VAR byte byteArray[5]
    
    PUB main
       startUpAll( $1FFFF, @byteArray)
    
    PUB startUpAll( myLongValue, myAddressValue)
       COGNEW( @pasmStuff, @myLongValue)
       WAITCNT( CLKFREQ / 10000 + CNT )
    
    DAT
                     org 0
    pasmStuff         rdlong asmLongValue,par  ' Get first parameter value
                     mov asmPointer,par  ' Get address of 2nd parameter
                     add   asmPointer,#4
                     rdlong bytePointer,asmPointer  ' Now get parameter (byte array address)
    hangHere           jmp  #hangHere
    
    asmLongValue res 1
    asmPointer res 1
    bytePointer res 1
    
    This way, myLongValue and myAddressValue are both longs and follow each other in memory. The WAITCNT is there to make sure the COGNEW has a chance to finish before startUpAll exits and the local variables are used for something else. It takes around 100us for a new cog to be started.
Sign In or Register to comment.