Announcement

Collapse
No announcement yet.

Data block question.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Data block question.

    Could someone explain why this is happening? When referenced directly it is word aligned like it should be but when I pass the address on it seems to be byte aligned. Is this how the code should work or is this a bug? Works correctly when I just define an array.

    #platform "uLCD-28PT" #DATA word dataArray 0x1111,0x2222,0x3333,0x4444#END func main() gfx_ScreenMode(LANDSCAPE); //var dataArray[]:=[0x1111,0x2222,0x3333,0x4444]; var singleVar; singleVar:=dataArray; print([HEX]dataArray[0]," ",[HEX]dataArray[1]," ",[HEX]dataArray[2]," ",[HEX]dataArray[3],"\n"); print([HEX]singleVar[0]," ",[HEX]singleVar[1]," ",[HEX]singleVar[2]," ",[HEX]singleVar[3],"\n"); repeat forever endfunc

  • #2


    Yeah, RAM is word aligned, FLASH (where data lives) is byte aligned.

    When the compiler sees a reference to flash, it knows what to do to get the correct data.

    However, once you stick the address of that flash into a variable it becomes 'just a pointer in variable', it has no way of indentifying the 'type'.

    So you need to multiply the indexes by 2 when you use code in that way.
    Mark

    Comment


    • #3


      Okay, so why does it act the same when I load the program into RAM? Does it still put constants in FLASH?

      Comment


      • #4


        Um, yeah, and ah no.

        Gee, how to describe it easily?

        The constants are stored in the same 'area' as the program and hence addressed the same way. So it doesn't matter if your program is running from RAM or FLASH, the #DATA is accessed the same way.
        Mark

        Comment


        • #5


          Is that documented? Maybe it should.

          Actually, I personally feel that a section on memory management in the doc would be useful.

          Comment

          Working...
          X