Shop OBEX P1 Docs P2 Docs Learn Events
LONG instruction — Parallax Forums

LONG instruction

@cgracey If I use pnut34s to build the following code:
DAT
        org
loop    jmp     #loop

        orgh
b1      byte    "Testing", $0, $1[2], word $3, long $4[5]
w1      word    $0, $1[2], long $3, long $4[5]
l1      long    $0, $1[2]

The last four longs are not long-aligned. The P1 documentation states that they should be, and it appears that the other alignment-related modifiers (e.g. "b1 byte word $3") are still valid. On the other hand, the abbreviated syntax at the end of the P2 document doesn't indicate alignment any more. And we now have the ALIGNW/ALIGNL directives. So, on the P2 is it now always byte-align, and you use the directives to force word or long alignment?

Comments

  • RaymanRayman Posts: 14,646
    I think this is correct. Longs no longer have to be long aligned.

    Although, I think there are certain cases where it has to be long aligned with ALIGNL directive...
    Think something about XCONT and the streamer is one case...
  • If that's the case, then I suggest removing support for the old P1 extended syntax.
  • SeairthSeairth Posts: 2,474
    edited 2020-06-23 03:36
    As a followup (because I started to second-guess my own recommendation), I played around a little with variations. So, without the extended syntax, the code would look like:
    DAT
            org
    loop    jmp     #loop
    
            orgh
    b1      byte    "Testing", $0, $1[2]
            word    $3
            long    $4[5]
    w1      word    $0, $1[2]
            long    $3, $4[5]
    l1      long    $0, $1[2]
    

    which is certainly no less readable (and a definitely less complicated).

    Then it occurred to me that maybe there was a use case for the extended syntax in a cog-mode section. But it turns out that's not the case either. The only requirement is that the label is long-aligned. Otherwise, everything is just packed in exactly the same as in hub memory. So, for the same block above to compile with a "orgh" commented out, you would need to add an "alignl" in front of "l1". But all of the binary prior to that would be identical to the "orgh" version.

    So, this is all just to say: remove the extended syntax. Its additional complexity does not outweigh its benefits. This keeps the rules simple:
    • All sequential BYTE, WORD, and LONG data are packed (i.e. byte-aligned) regardless of cog or hub mode.
    • To force word alignment, use ALIGNW.
    • To force long alignment, use ALIGNL.
    • In org-mode blocks, all labels must be long-aligned.
  • Additionally hub addresses must be long aligned if using the sreamer with block wrapping.
  • ozpropdev wrote: »
    Additionally hub addresses must be long aligned if using the sreamer with block wrapping.

    Though this topic was primarily about the BYTE, WORD, and LONG directives, that's good information to know. I think it's already captured in the P2 doc, but it's somewhat subtle (the 2 lsb's are '00' in the S-field syntax). I've made a small edit to make that fact a bit more explicit.

  • Cluso99Cluso99 Posts: 18,069
    IIRC, hubexec does not need to be long-aligned either.
  • Cluso99 wrote: »
    IIRC, hubexec does not need to be long-aligned either.

    Again, the thread was about BYTE, WORD, and LONG.
    But, yes. That would make sense, as the fifo doesn't require alignment unless wrapping, based on what I see in the P2 docs.
Sign In or Register to comment.