Shop OBEX P1 Docs P2 Docs Learn Events
RDLONG and indexing — Parallax Forums

RDLONG and indexing

I think we had this discussion before, some time ago.

Why does

           mov    temp,buffAdr
           add    temp,rdIndex
           rdlong temp,temp       ' get buffer[rdIndex]

work but

           alts   buffAdr,rdIndex
           rdlong temp,buffAdr    ' get buffer[rdIndex]

does not? 🤔

Another trap: rdlong x,ptra[index] seems to work for single reads but does not for block reads with preceding setq. Theese special cases should be documented in the manuals.

Comments

  • cgraceycgracey Posts: 14,153
    alts   buffAdr,rdIndex
    rdlong temp,buffAdr    '
    


    It's because ALTS is only modifying the S field of the RDLONG instruction. It winds up replacing buffAdr with the contents of buffAdr plus the contents of rdIndex. That sum will become the register which is used as S in RDLONG.

  • Doh 🤦‍♂️

    I had the same problem as sjgallagher2 in the "P2 PASM Syntax Clarifications" thread. The concept of immediate or indirect addressing modes is clear to me. But if one instruction modifies the next it's easy to get confused. I thought I had understood what should happen but I haven't... ALTS doesn't modify the final source operand (the hub address) but the input to the instruction (the register address).

    Thanks for pointing this out.

  • I don't get it.


    bufferAdr = 0x100 = ['A' 'B' 'C' 'D' 'E' 'F']

    rdIndex = 5

    bufferAdr + rdIndex = 0x105 = 'F'

    So rdlong temp, bufferAdr would me temp = 'F'.


    Mike

  • The code might still be confusing. For a byte array it should read "rdbyte" instead of "rdlong". For longs rdIndex must be shifted left by two bits because the array pointer increments by 4 for each element. I just stripped any extra code because it's not relevant for showing the ALTS problem.


    So rdlong temp, bufferAdr would me temp = 'F'.

    No. temp=='F' is what I expected but the ALTS version reads a random register at the wrong cog adrress and therefore the hub ram adress is also wrong. The mov/add version with rdbyte temp,temp works as expected.

  • rdlong reads from HUB memory, not COG memory. ALTS changes the COG address in the instruction (which in rdlong's case is the register to use to get the HUB address -- it's like a double indirection).

Sign In or Register to comment.