Shop Learn P1 Docs P2 Docs Events
Looking for sample codes from spin to assembly — Parallax Forums

Looking for sample codes from spin to assembly


I am a beginner of both spin and assembly, and needing to make a conversion on a piece of assembly code to spin. I've gone through parts of the manual but yet to be proficient enough to correctly utilize each command in practice.

Are there any existing sample codes that I can reference for basic commands and operations from one to and other?

Any pointer or tips would be greatly appreciated!



  • That's a little vague, assembly code in pasm?, post a sample of your assembly code. Here is a simple example

  • evanhevanh Posts: 14,637

    Usually it's in assembly for a reason. Speed usually. Converting it back to spin will then make the code too slow.

  • Thanks for the response!

    Yeah, this was originally designed to run in assembly in a designated cog, but we run out of cog to use for this feature on a new device.
    Therefore, we thought we could merge that into the main loop in spin, given that the procedures in the assembly don't require high speed.

    here is a small piece of the code. I understand that it is pointer arithmetic in assembly, moving address, performing read, write and math eventually store back in each address. But I am very confused on how to do that in spin.

                           wrlong     t1, regbase             'save raw value
                           mov          t3, regbase
                           add           t3, #4                     
                           rdlong      t2, t3          wz      
              if_nz     mov          t2, #0
              if_nz     wrlong      t2, t3                 
                           add           t3, #28                 
              if_nz     wrlong      t1, t3               



    'rxdata contains the raw value

    tmp1 := @rxdata
    tmp1+= 4

    I'm not even sure if i am on the right path :(

  • See if this helps

      long[regbase] := t1        '         wrlong  t1, regbase
      t3 := regbase + 4          '         mov     t3, regbase
                                 '         add     t3, #4     
      t2 := long[t3]             '         rdlong  t2, t3          wz       
      if (t2)                    ' if_nz   mov     t2, #0   
        t2 := 0
        long[t3] := t2           ' if_nz   wrlong  t2, t3        
        t3 += 28                 '         add     t3, #28          
        long[t3] := t1           ' if_nz   wrlong  t1, t3

    I could see the correlations now.

Sign In or Register to comment.