Shop OBEX P1 Docs P2 Docs Learn Events
Help with long-alinging a byte array in VAR — Parallax Forums

Help with long-alinging a byte array in VAR

LewisDLewisD Posts: 29
edited 2007-05-02 02:37 in Propeller 1
Is there a way to tell the compiler to long-align a byte array in VAR?




'This is example code...
'Watch address $006C in main memory
'It gets over writen when the assembly runs the wrlong
'This is because buffer[noparse][[/noparse]] is not long-alinged in main memory


var

  long  temp
  byte  temp2
  byte  buffer[noparse][[/noparse]2048]

pub main

cognew(@StartASM, @Buffer)

temp2 := 1

repeat
  repeat temp from 0 to 2047
    buffer[noparse][[/noparse]temp] += temp2 * 2

DAT

              org       0

StartASM      mov       timer,cnt
              add       timer,tick
              mov       Buffer_Pointer,par
              mov       Buffer_Pointer_Counter,End_Of_Buffer


:loop         waitcnt   timer,tick
              wrlong    Data,Buffer_Pointer
              add       Buffer_Pointer,#4
              djnz      Buffer_Pointer_Counter,#:loop
              jmp       StartASM
              
              

Data          long      $55555555
tick          long      5_000
End_Of_Buffer long      512

timer                     res   1
Buffer_Pointer            res   1
Buffer_Pointer_Counter    res   1




Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-05-02 01:50
    You need to do the alignment yourself. The compiler organizes variables in the following order: first all LONGs appear in the order they are declared, second WORDs in thier order of appearance, finally BYTEs in thier declared order. To long align bytes you need to keep track of if there are an odd number of declared words and how many declared bytes preceeding then rearrange your bytes or declare a dummy array of bytes to pad the region you want to be long aligned.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • LewisDLewisD Posts: 29
    edited 2007-05-02 02:07
    Not what I was hoping to hear....

    Thank you Paul for you quick response...

    I will rearrange my variables.....
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-02 02:37
    You can also declare the buffer as a long array and access individual bytes with the .BYTE[noparse][[/noparse] x ] suffix.
Sign In or Register to comment.