Shop OBEX P1 Docs P2 Docs Learn Events
Beginner Assembly Arrays problem — Parallax Forums

Beginner Assembly Arrays problem

bikejunkybikejunky Posts: 33
edited 2014-04-03 10:41 in Propeller 1
I’m trying to teach myself Propeller Assembly. I bought Harpits book, it has helped get me moving a little.
I’ve been converting some of the example programs from the PE kit labs to assembly. Mostly just flashing led patterns from the Parallax Serial Terminal. Now I would like to put an array/table in a cog light the leds and display the pattern on the PST. I am using a Quickstart board. (I hacked up Chuck McManis code from a post on MOVS, MOVD, MOVI and MOV). It is below. I would appreciate any help and I am sure I will be asking more questions on this program even when it works.
con
_clkmode = xtal1 +pll16x
_xinfreq = 5000000

Obj
  pst:"Parallax Serial Terminal"
var
 long alongV
 long cog
 long temp

Pub Main
''array in assembly in cog Parallax Serial Terminal
pst.Start(115_200) ' might have to be slower for raspberry pi
pst.Char(pst#CS)      'Clear Screen

cog:=cognew(@myArray,@alongV)
repeat
     pst.Bin(alongV,8)
     pst.Str(String(pst#NL))

DAT
        org 0
myArray mov hubaddress,par
entry   MOV     temp3, #Index   ' Load the address of Index into temp3
           MOVS   :loop, temp3      ' Modify the instruction at label :loop to point at Index (Note 1)
           MOV     temp1, #32        ' Create a 32 iteration loop
:loop      MOV     temp2, Index     ' Load a value into Temp2
           MOV     temp3, :loop      ' Load the instruction from :loop into temp3 
           ADD     temp3, #1          'Now temp3 has the instruction but its pointer has been incremented
           MOVS   :loop, temp3       'Now the instruction at :loop has been modified to load the next long (Note 2)
           wrlong temp2,hubaddress
           nop
           mov     myTemp,temp2      '... do something with temp2 ... '
           shl     myTemp,#16       ' your program uses the value from the array  
           mov     dira, myTemp
           mov     outa, myTemp
           call    #pause
           mov     myTemp,#0
           DJNZ    temp1, :loop      ' Now loop back to :loop and get the next value

pause      mov del_time, delay
:mloop      djnz del_time,#:mloop
pause_ret  ret

hubaddress res 1
myTemp  res 1
del_time res 1
delay long 10_000_000

temp1  LONG    0
temp2  LONG    0
temp3  LONG    0
Index   LONG  %1111          ' Value of array at [0]
        LONG  %1110        '              ...     at 
        LONG  %1101
        long  %1100
        long  %1011
        long  %1010
        long  %1001
        long  %1000
        long  %0111
        long  %0110
        long  %0101
        long  %0100
        long  %0011
        long  %0010
        long  %0001
        long  %0000
        long  %11111111
        long  %0000 
        long  %0001
        long  %0010
        long  %0011
        long  %0100
        long  %0101
        long  %0110 
        long  %0111 
        long  %1000 
        long  %1001
        long  %1010 
        long  %1011 
        long  %1100
        long  %1101 
        long  %1110 
        long  %1111         ' ...     at 
                 '... repeated for 29 more values ...
           FIT      ' Make sure everything fits

Comments

  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-04-03 08:56
    These are the routines I use in my own PASM template for read and writing cog arrays.
    ' basepntr = address of array/table
    ' idx = index of element to read
    ' value = value that is read
    
    read                    mov     r1, basepntr
                            add     r1, idx
                            movs    :rdval, r1
                            nop
    :rdval                  mov     value, 0-0
    read_ret                ret
    
    
    ' basepntr = address of array/table
    ' idx = index of element to write
    ' value = value to write
    
    write                   mov     r1, basepntr
                            add     r1, idx
                            movd    :wrval, r1
                            nop
    :wrval                  mov     0-0, value
    write_ret               ret
    


    I suggest that you give your array a more meaningful name that Index. Remember that the address operator in PASM is # (versus @) in Spin. You might do something like this (note that this code is NOT complete)
    show_patterns           mov     basepntr, #Lights               ' point to patterns
                            mov     idx, #0                         ' start at beginning 
    :loop                   call    #read                           ' get Lights[idx]
                            shl     value, #16                      ' align for LEDs
                            mov     outa, value                     ' update LEDs
                            call    #delay                          ' hold
                            add     idx, #1                         ' increment index
                            cmp     idx, #10                wc, wz  ' at end?
            if_b            jmp     #:loop                          ' if no, run again
    


    If I may... have a look at this line from your program:
    :loop      MOV     temp2, Index     ' Load a value into Temp2
    


    Note how the comment is a slap-in-the-face obvious? The instruction says what it's doing -- no need to put that in a comment. If you're going to add comments, they should explain in context, not spell out what we can plainly see, anyway.
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-04-03 09:58
    Another problem you have in your code is that you have LONG values after RES value -- you must have the LONGs first. Put your table above your variables
  • bikejunkybikejunky Posts: 33
    edited 2014-04-03 10:41
    I garbage canned that original and hack up your routines. Now, I have something that is now lighting the leds.
    Thanks, I think I'm on my way
Sign In or Register to comment.