Shop OBEX P1 Docs P2 Docs Learn Events
MOV or RDLONG — Parallax Forums

MOV or RDLONG

T ChapT Chap Posts: 4,223
edited 2009-08-17 20:15 in Propeller 1
I am trying to understand the difference.

Are these the same?


MOV temp1, accel

RDLONG Temp1, accel

accel RES 1 'local to asm, Why are not local variables specified as long, word, byte etc. I assume you ONLY have longs in ASM.


So far I think that for Longs set in the Main program (the caller of the ASM method), you would pass the address of the long in main
to the method with a parameter. Then if that variable needs to be accessed, you RDLONG the pointer to acceess the 'outside world'. But if you are working with local
declared variables in the ASM object/method, you just mov them.

Post Edited (TChapman) : 8/17/2009 5:15:10 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-08-17 17:07
    MOV moves a 32-bit word from one cog location to another. "MOV temp,accel" moves the contents of "accel" to "temp", both cog locations.

    RDLONG moves a 32-bit word from a hub memory location to a cog memory location. The source operand value specifies the hub address. In your case, "RDLONG temp,accel" takes the hub address contained in cog location "accel" and uses that to read a 32-bit long from hub memory into cog location "temp".

    In ASM there are only 32-bit memory locations. You can pack 16-bit words and 8-bit bytes into these locations using the assembler, but there are no instructions to directly manipulate them. It's all 32-bit values.
  • T ChapT Chap Posts: 4,223
    edited 2009-08-17 17:30
    Thanks Mike. It is a bit confusing to me, in Spin you just have variables. You set the variable to whatever you want, read them as needed.

    A real world scenario, are these the same?


    
    PUB  moveX
         motorr(0, @X, @Xcurrent, 1, 0, @Xdone)
    
    PUB motorr( ipinstart, ipos, icurrent, iforward, ireverse, iID )
      [noparse][[/noparse]  ... ]
      newposition := ipos
      currentposition := icurrent
      return COGNEW( @cogstart, @ipinstart )   
    
    
    DAT
                        ORG     0
    cogstart
                        JMP     #cogstart0
    pinstart         LONG    0               ' input parameters
    radr              LONG    0
    forward         LONG    0
    reverse         LONG    0
    ID                LONG    0
    cogstart0                                 
    
    
    [noparse][[/noparse] ... ]    skipping code
    
    repeat1
                    'if  LONG[noparse][[/noparse]newposition] < LONG[noparse][[/noparse]currentposition]   
                    RDLONG  ctmp1, newposition            
                    MOV     ctmp2, currentposition          
                    RDLONG  ctmp2, ctmp2          
                    CMPS    ctmp1, ctmp2    WC        'if newpos < current, set C flag to 1
        IF_C   JMP     #endif2                'jmp to #endif2 (if c flag is 1) 
                    MOV     rep3cnt, C1000     
    
    'versus
    
    repeat1
                 CMPS    newposition, currentposition    WC    'if newpos < current, set C flag to 1
     IF_C   JMP     #endif2         ' jmp to #endif2 (if c flag is 1) 
    
    ctmp1           RES     1               ' PASM variables
    ctmp2           RES     1 
    run               RES     1  
    
    
    
    

    Post Edited (TChapman) : 8/17/2009 5:49:36 PM GMT
  • T ChapT Chap Posts: 4,223
    edited 2009-08-17 17:57
    I just tested the alternative short version above and it worked fine what what I can tell. Seems you can do CMPS on global variables just like locals.
  • henry99henry99 Posts: 67
    edited 2009-08-17 18:46
    I'm not a super expert at asm but:
    RDLONG ctmp1, newposition
    MOV ctmp2, currentposition
    RDLONG ctmp2, ctmp2
    CMPS ctmp1, ctmp2

    Why don't you just write
    RDLONG ctmp1, newposition
    RDLONG ctmp2, currentposition
    CMPS ctmp1, ctmp2

    Also this statement:
    CMPS newposition, currentposition WC

    Will compare only the pointer locations and not the values from Hub memory.
  • T ChapT Chap Posts: 4,223
    edited 2009-08-17 18:57
    OK I got it. You always first read the values from the locations via pointers into temp local variable and then do your processes.

    RDLONG temp1, pointer1 'get the values into local vars
    RDLONG temp2, pointer2 'get the values
    CMPS temp1, temp2 compare
  • mparkmpark Posts: 1,305
    edited 2009-08-17 20:15
    Also, it'll probably help if you stop thinking in terms of local vs. global variables ('cause that's not the difference here) and focus on cog vs. hub memory.
Sign In or Register to comment.