Shop OBEX P1 Docs P2 Docs Learn Events
Prop Spin to ASM compare table — Parallax Forums

Prop Spin to ASM compare table

mikedivmikediv Posts: 825
edited 2009-12-07 16:33 in Propeller 1
Hey guys I am trying to put together a table that would show the Prop Spin code on one side an the comparable Prop ASM code on the other, so you look at the Spin code say {dira} and the equivalent to the right ASM code I don't know what that is right now..
My question is does this already exist in any form?? If not where could I get the information to help me along I think it would be an easier way to learn ASM if I could see what the Spin code to ASM would be
Thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-24 23:49
    I don't think there are any tables like what you're suggesting.· You might look at Bean's SX/B compiler for the Propeller.· SX/B is limited to essentially one operation per line of Basic and translates it into assembly.· He's posted some early versions in a thread and that might give you some ideas.
    ·
  • heaterheater Posts: 3,370
    edited 2009-11-25 00:00
    Setting pin directions in PASM is:
        mov  dira, #pattern
    
    


    if pattern is a fixed number that fits in 9 bits. Or
        mov dira, pattern
    
    


    if pattern is held in a LONG. Similar for outa.

    One could say that assignments (eg A := B) look like:
       mov A, B
    
    


    Or that operators (e.g A := B + C) look like:
       mov A,B
       add A,C
    
    


    Or that conditions ( eg if A = B) look like:
        cmp A,B wz
    if_nz jmp skip
        'Do something here if A = B
    skip
    
    



    Best thing is to get your head into the manual and study the PASM section. Try out the examples flashing LEDs and such.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2009-11-25 00:16
    Although you can do a certain amount of line by line translation you really do have to code in a slightly different way but as you can see from Heater's examples there is nothing to fear much of the time.

    Graham
  • nohabnohab Posts: 96
    edited 2009-11-25 11:14
    Even if the coding differs a bit(!) I think it could be helpful for guys like me, who begins to feel comfortable with SPIN (no expert though...) but still looking att PASM with a mix of curiosity and hesitation.

    In the beginning, "BS2 Functions" helped me to go from Basic Stamp to the Propeller, and some basic SPIN functions translated to PASM couldn't harm.

    Heater did a good start and here is an idea of some more:

    REPEAT WHILE ...
    REPEAT x FROM 0 TO 10
    IF ina[noparse][[/noparse]0] or [noparse][[/noparse]0..7]
    WAITCNT[noparse][[/noparse]...]
    ctra[noparse][[/noparse]30..26] := %00100 'NCO mode

    Also some BS2 functions that could be handy in PASM:

    RCTIME
    PULSIN
    PULSOUT
    SERIN
    SEROUT
    SHIFTIN
    SHIFTOUT
  • BeanBean Posts: 8,129
    edited 2009-11-25 12:26
    Here are a few examples from PropBASIC. Hopefully they will get you started in the right direction.

     
    ''  *** COMPILED WITH PropBasic VERSION 0.00.31  11/24/2009 ***
    
    CON                                                          'DEVICE P8X32A, XTAL1, PLL16X
      _ClkMode = XTAL1 + PLL16X                                 
      _XInFreq =   5000000                                       'FREQ 80_000_000
    
    ' MyPin    PIN 7                                             'MyPin    PIN 7
    ' DATPin   PIN 8                                             'DATPin   PIN 8
    ' CLKPin   PIN 9                                             'CLKPin   PIN 9
    
    ' temp     VAR LONG                                          'temp     VAR LONG
    
    PUB __Program                                                'PROGRAM Start
      CogNew(@__Init, @__DATASTART)                             
                                                                
    DAT                                                         
                    org         0                               
    __Init                                                      
                    mov         dira,__InitDirA                 
                    mov         outa,__InitOutA                 
                    jmp         #Start                          
    
    Start                                                        'Start:
     
                    mov         __temp1,MyPin                    '  RCTIME MyPin, 0, temp
                    andn        dira,__temp1                    
                    mov         temp,#0                         
                    mov         __temp2,cnt                     
                    adds        __temp2,#80     ' ClkFreq / 1_000_000                 
    __L0001                                                     
                    adds        temp,#1                         
                    waitcnt     __temp2,#80                     
                    and         __temp1,ina NR, WZ              
        IF_Z        jmp         #__L0001                        
     
     
                    mov         __temp1,MyPin                    '  RCTIME MyPin, 1, temp
                    andn        dira,__temp1                    
                    mov         temp,#0                         
                    mov         __temp2,cnt                     
                    adds        __temp2,#80     ' ClkFreq / 1_000_000                     
    __L0002                                                     
                    adds        temp,#1                         
                    waitcnt     __temp2,#80     ' ClkFreq / 1_000_000                     
                    and         __temp1,ina NR, WZ              
        IF_NZ       jmp         #__L0002                        
     
     
                    mov         __temp1,MyPin                    '  PULSIN MyPin, 0, temp
                    andn        dira,__temp1                    
                    mov         temp,#0                         
                    waitpeq     __temp1,__temp1                 
                    waitpne     __temp1,__temp1                 
                    mov         __temp2,cnt                     
                    adds        __temp2,#80     ' ClkFreq / 1_000_000                     
    __L0003                                                     
                    adds        temp,#1                         
                    waitcnt     __temp2,#80     ' ClkFreq / 1_000_000                     
                    and         __temp1,ina NR, WZ              
        IF_Z        jmp         #__L0003                        
     
     
                    mov         __temp1,MyPin                    '  PULSIN MyPin, 1, temp
                    andn        dira,__temp1                    
                    mov         temp,#0                         
                    waitpne     __temp1,__temp1                 
                    waitpeq     __temp1,__temp1                 
                    mov         __temp2,cnt                     
                    adds        __temp2,#80     ' ClkFreq / 1_000_000                     
    __L0004                                                     
                    adds        temp,#1                         
                    waitcnt     __temp2,#80     ' ClkFreq / 1_000_000                     
                    and         __temp1,ina NR, WZ              
        IF_NZ       jmp         #__L0004                        
     
     
                    or          dira,MyPin                       '  PULSOUT MyPin, temp
                    xor         outa,MyPin                      
                    mov         __temp2,cnt                     
                    adds        __temp2,#80     ' ClkFreq / 1_000_000                     
                    mov         __temp3,temp                    
    __L0005                                                     
                    waitcnt     __temp2,#80     ' ClkFreq / 1_000_000                     
                    djnz        __temp3,#__L0005                
                    xor         outa,MyPin                      
     
     
                    mov         __temp1,DATPin                   '  SHIFTIN DATPin, CLKPin, MSBFIRST, temp
                    andn        dira,__temp1                    
                    mov         __temp2,CLKPin                  
                    or          dira,__temp2                    
                    mov         __temp3,#0                      
                    mov         __temp4,#8                      
                    mov         __temp5,cnt                     
                    add         __temp5,#511                    
    __L0006                                                     
                    and         __temp1,ina NR, WC              
                    rcl         __temp3,#1                      
                    xor         outa,__temp2                    
                    waitcnt     __temp5,#511                    
                    xor         outa,__temp2                    
                    waitcnt     __temp5,#511                    
                    djnz        __temp4,#__L0006                
                    rev         __temp3,#8                      
                    mov         temp,__temp3                    
     
     
                    mov         __temp1,DATPin                   '  SHIFTOUT DATPin, CLKPin, MSBPOST, temp
                    or          dira,__temp1                    
                    mov         __temp2,CLKPin                  
                    or          dira,__temp2                    
                    mov         __temp3,temp                    
                    mov         __temp4,#8                      
                    mov         __temp5,cnt                     
                    add         __temp5,#511                    
    __L0007                                                     
                    shr         __temp3,#1 WC                   
                    muxc        outa,__temp1                    
                    waitcnt     __temp5,#511                    
                    xor         outa,__temp2                    
                    waitcnt     __temp5,#511                    
                    xor         outa,__temp2                    
                    waitcnt     __temp5,#511                    
                    djnz        __temp4,#__L0007                
     
     
                    mov         __temp1,MyPin                    '  SERIN MyPin, T115200, temp
                    andn        dira,__temp1                    
    __L0008                                                     
                    and         __temp1,ina WZ, NR              
        IF_Z        jmp         #__L0008                        
    __L0009                                                     
                    and         __temp1,ina WZ, NR              
        IF_NZ       jmp         #__L0009                        
                    mov         __temp4,_bitDelay               
                    shr         __temp4,#1                      
                    add         __temp4,cnt                     
                    add         __temp4,_bitDelay               
                    waitcnt     __temp4,_bitDelay               
                    mov         __temp3,#8                      
                    mov         __temp2,#0                      
    __L0010                                                     
                    and         __temp1,ina WZ, NR              
        IF_Z        andn        __temp2,#256                    
        IF_NZ       or          __temp2,#256                    
                    waitcnt     __temp4,_bitDelay               
                    shr         __temp2,#1                      
                    djnz        __temp3,#__L0010                
                    mov         temp,__temp2                    
     
     
                    mov         __temp1,MyPin                    '  SEROUT MyPin, T115200, temp
                    mov         __temp2,temp                    
                    or          __temp2,#256                    
                    shl         __temp2,#1                      
                    mov         __temp3,#10                     
                    mov         __temp4,_bitDelay               
                    add         __temp4,cnt                     
                    or          dira,__temp1                    
    __L0011                                                     
                    shr         __temp2,#1 WC                   
                    muxc        outa,__temp1                    
                    waitcnt     __temp4,_bitDelay               
                    djnz        __temp3,#__L0011                
     
     
                    jmp         #$                               'END
     
    '**********************************************************************
    __InitDirA       LONG %00000000_00000000_00000000_00000000
    __InitOutA       LONG %00000000_00000000_00000000_00000000
    MyPin            LONG 1 << 7
    DATPin           LONG 1 << 8
    CLKPin           LONG 1 << 9
    _bitDelay        LONG 694                   ' ClkFreq / Baudrate
    
    __remainder      RES 1
    __temp1          RES 1
    __temp2          RES 1
    __temp3          RES 1
    __temp4          RES 1
    __temp5          RES 1
    __param1         RES 1
    __param2         RES 1
    __param3         RES 1
    __param4         RES 1
    __paramcnt       RES 1
    temp             RES 1
     
    FIT 492
     
    CON
      LSBFIRST                         = 0
      MSBFIRST                         = 1
      MSBPRE                           = 0
      LSBPRE                           = 1
      MSBPOST                          = 2
      LSBPOST                          = 3
     
    DAT
    __DATASTART
    
     
    


    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Does that byte of memory hold "A", 65, $41 or %01000001 ?
    Yes it does...


    ·
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2009-11-25 14:06
    I'm warming to the idea if it is used in the right way. I have added spin inspired comments

    one way to do REPEAT x FROM 0 TO 10

              mov count,loops       'count := loops
              mov x,#0              'count := 0
    :loop     'Put some code here   'Will do this code 100 times
              'some more code here
              add x,#1              'x := x + 1
              djnz count,#:loop     'count:=count - 1, if count <> 0 jump to :loop
    
    
    count     long   0
    loops     long   100
    x         long   0
    
    

    Post Edited (Graham Stabler) : 12/7/2009 4:39:55 PM GMT
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2009-11-25 14:25
    Waitcnt:
            mov      time,cnt      'time := cnt
            add      time,delay    'time := time + delay
            waitcnt  time,delay    'waitcnt(time), time := time + delay
                                   ' you can leave the second argument as #0
                                   ' or use it as a fast way to create a
                                   ' second delay target
    
    



    Setting CTRA
            or ctra,mode         'sets bits high in mode to be high in CTRA
            
    long    mode      %00100 << 26   ' this is done before it is loaded into propeller so uses some spin
    
    
  • mikedivmikediv Posts: 825
    edited 2009-11-25 15:46
    Thank you guys. nohab sir I could not have stated it better than you. That is exactly where I am at, I am getting comfortable reading and understanding spin " no expert either" but I am very interested in learning ASM even if its just to enhance my Spin code.
    ,,,, Thanks again guys I am going to use your examples and start my conversion table I understand now there will not always be a code to code conversion so I think I will use examples when I have to showing Spin code to comparable ASM code
    If anyone wants to continue to join in I will post the completed list here when its more complete and maybe people would liek to add to it. Thanks again ,, Happy holidays to everyone have a safe and happy thanksgiving
  • heaterheater Posts: 3,370
    edited 2009-11-25 16:59
    As you see there is no one-to-one Spin to PASM possibilities. That is the point of compilers, you write one line of code that you understand and the compiler generates a bunch of instructions that you don't have to understand. The generated sequence may not even be the same for each occurrence of the same source line depending on context. Never mind that Spin is not actually compiled to PASM anyway.

    Still, you have a valid point, a bunch of PASM examples demonstrating common programming constructs could be useful to many. Loops, conditionals, etc.

    Some one please put up an example of the tricky one in PASM, array indexing !

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2009-11-25 17:33
    Here you go heater, it just adds up all the values held in a small array:

                  mov     index_,#0                        ' These two lines not required for example but may be required if you loop this
                  mov     elements_,#10
                  mov     index_,#lookup_                  ' Put address of the lookup table in the index
                                                           ' this is the address of the first element
    :loop         movs    :inline,index_                   ' Move the address into the place holder (0-0) of add command at label :inline
                  nop                                      ' You need a command (any) between the movs and :inline to give it time to modify the code 
    :inline       add     total,0-0                        ' Add contents of array element to total                        
                  add     index_,#1                        ' Increment index                          
                  djnz    elements_,#:loop                 ' Decrement elements_ and jump to :loop if still not zero                                                                                                          
                  
    lookup_       long    1,2,3,4,5,6,7,8,9,10
    total_        long    0
    index_        long    0
    elements_     long    10
    
    

    Post Edited (Graham Stabler) : 11/26/2009 9:18:12 AM GMT
  • BeanBean Posts: 8,129
    edited 2009-11-25 17:44
    Graham,
    I think you loop is adding the #lookup_ offset each time through the loop. I think the :loop label should be on the next line down.
    Also, you need an instruction between the "movs" and the instruction that it is affecting. This is a cache issue.


    [noparse][[/noparse]Edit] Graham has fixed the above code. Looks good Graham.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Does that byte of memory hold "A", 65, $41 or %01000001 ?
    Yes it does...




    Post Edited (Bean (Hitt Consulting)) : 11/26/2009 2:50:55 PM GMT
  • heaterheater Posts: 3,370
    edited 2009-11-25 19:04
    Like I said "the tricky one in PASM" [noparse]:)[/noparse]

    You for sure need an instruction after the movs.
    Could probably move the "add index_,#1 " into that position instead of using a NOP.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.

    Post Edited (heater) : 11/25/2009 7:10:15 PM GMT
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2009-11-25 23:15
    quite right, I'll fix it in the morning (no ptoptool on the media PC and easier to edit it in that). The lack of nop was because I ripped it from the fader thread and I was using another command to act as the filler for pipelining.

    I'm annoyed I did not check it more carefully, in some code I'm working on right now I'm reading from a hub array and writing to a cog array, that really was confusing but it worked first time! Well second [noparse];)[/noparse]

    Graham
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2009-11-26 09:17
    I have corrected it, I used nop rather than the increment to make the point as clearly as possible because you don't always have a command that needs to be run.

    Graham
  • nohabnohab Posts: 96
    edited 2009-11-26 14:39
    Thanks for all contributions sofar!
    I do think step-by-step documented (spin-style was nice!) templates is a good kickstart into the PASM world.
  • photomankcphotomankc Posts: 943
    edited 2009-12-07 06:40
    I'm going to need the speed of PASM for my planned CNC driver so this will be of great interest to me. I'll need to be able to capture, process, and output signals from the PC to the coil drivers as fast as possible while maintaining positional indications. I was thinking of roughing out the process in SPIN and then working to convert it to PASM. PropBASIC would be another nice option to figure out basic code structures.
  • jazzedjazzed Posts: 11,803
    edited 2009-12-07 16:33
    mikediv said...
    Hey guys I am trying to put together a table ....
    @mikediv, If you attach your table in the top post, we could help "fill in the blanks" and suggest more "blanks to fill".
Sign In or Register to comment.