Shop OBEX P1 Docs P2 Docs Learn Events
working with data arrays in PASM for P2 — Parallax Forums

working with data arrays in PASM for P2

If you have an array of data in the data section in PASM (such as)


Dat

temp  long $C9,$C2,$09,$40,$07


And you want to read each data (value) one by one into a variable to perform some calculation…such as sum the five numbers together. How do you do that for the P2?  It looks that the movs and movd instructions have been removed from the P2 architecture.  

Comments

  • Cluso99Cluso99 Posts: 18,069

    If you use PTRA or PTRB then you can do this

    mov ptra,##temp

    rdbyte xxx,ptra[n]

    where n can be an offset IIRC -31 to +32 (might be -15 to +16 so you need to check). There’s also ptra++ option too.

  • Thank you for the quick reply, but I was thinking about an array (or pointer addressing) in COG ram not HUB ram. Sorry for the confusion

  • AribaAriba Posts: 2,682

    For indirect read from cog memory, you should use ALTS and ALTD to modify the source or destination address of the next instruction (see manual).

    MOVS and MOVD are still avalable but have changed there names to SETS and SETD, I think. But you should not use them, the ALTx methode is faster and works also with hubexec.


    Andy

  • KaioKaio Posts: 253
    edited 2021-01-28 22:17

    There was already a thread about clarification of the ALTx instructions (https://forums.parallax.com/discussion/172803/p2-pasm-syntax-clarifications-altx).

  • evanhevanh Posts: 15,220

    Packed byte arrays in cogRAM can be dealt with using ALTGB prefixing of GETBYTE, and ALTSB prefixing of SETBYTE. Documented in the Register Indirection section of hardware doc.

  • thank you for the help! Are there any examples of the getbyte instruction being used in the programs that come with the propeller tool ide. I have better luck working through examples

  • evanhevanh Posts: 15,220
    edited 2021-01-29 13:42

    The hardware doc has snippets that are helpful.

    Here's one from my own debug code that prints hexadecimal out the serial port:

    'Integer (32-bit) to ascii hexidecimal and emit
    '  input:  pa
    ' result:  (none)
    'scratch:  pa, pb, bcdi
    '
    itoh
            mov    bcdi, bcdlen        'most significant nibble first (zero extended)
            sub    bcdi, #1
    .emit
            altgn    bcdi, #pa        '(instruction prefix)
            getnib    pb            'retrieve next hex digit from pa register:  pb = pa[bcdi]
            cmp     pb, #10        wcz    'test if below 10, C = borrow of (D - S)
        if_c    add    pb, #"0"        'ASCII encode 0-9
        if_nc    add    pb, #"a"-10        'ASCII encode a-f
            call    #putch
            djnf    bcdi, #.emit
            ret            wcz    'restore C/Z flags of calling routine
    
    
    

    Excuse the messed formatting. The forum software needlessly auto replaced the tabs.

  • JonnyMacJonnyMac Posts: 8,945
    edited 2022-09-28 14:24

    I converted a Spin program to PASM -- it uses a table. In this case, I'm extracting nibbles from a byte table, but working with other sizes just takes an instruction change.


    pri main2(base, tix) | pinfield, offset, t, hipin, lopin    ' runs forever!


     org

            mov    pinfield, #7             ' create pin field for 8 pins

            shl    pinfield, #6

            or    pinfield, base


            mov    offset, #0              ' initialize offset

            getct   t                   ' initialize led timer

                  

    .loop      altgn   offset, #.lut             ' point to low pin

            getnib  lopin                 ' read it

            add    lopin, base              ' adjust for base pin

            add    offset, #1              ' bump to high pin for this led 

            altgn   offset, #.lut             ' point to high pin  

            getnib  hipin                 ' read it

            add    hipin, base              ' adjust for base pin 

            incmod  offset, #111             ' increment with rollover

            fltl   pinfield               ' clear last led

            drvl   lopin                 ' light current led

            drvh   hipin

            addct1  t, tix                ' update timer

            waitct1                     ' let it expire

            jmp    #.loop

             


    .lut      byte   $01, $02, $03, $04, $05, $06, $07, $10

            byte   $12, $13, $14, $15, $16, $17, $20, $21

            byte   $23, $24, $25, $26, $27, $30, $31, $32

            byte   $34, $35, $36, $37, $40, $41, $42, $43

            byte   $45, $46, $47, $50, $51, $52, $53, $54

            byte   $56, $57, $60, $61, $62, $63, $64, $65

            byte   $67, $70, $71, $72, $73, $74, $75, $76    


     end

Sign In or Register to comment.