Shop OBEX P1 Docs P2 Docs Learn Events
Passing constants and addresses to assembler — Parallax Forums

Passing constants and addresses to assembler

scottascotta Posts: 168
edited 2007-09-26 23:31 in Propeller 1
I was wondering if anyone has figured out a way to pass constants
and references (addresses) from Spin to assembler without the
use of the PAR variable ?

Scott

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2007-09-26 21:44
    There is nothing to figure out smile.gif
    - You can use constants "as is". They are fully integrated into the Propeller Tool concept.
    - You can set or preset any address you want in a DAT cell loaded up with the COG code. See the examples in my Tutorial.
  • scottascotta Posts: 168
    edited 2007-09-26 22:30
    The following code shows what I have been doing.

    I think its easier than using PAR, and uses the same code
    space and execution time (as PAR).

    Note how the LCDx_BAUD variable is being changed
    from spin (in Main method), on a separate cog. The
    assembler LCD object dereferences this on the fly.

    I have used this technique for simple assembler interfaces
    with 1 variable to 40 incoming references and
    (about) 10 pre-set constants.


    <
    *************************
    ****    MAIN.spin FILE   
    *************************
    OBJ
        LCD1     : "LCD"
        LCD2     : "LCD"
    
    VAR
        long LCD1_BAUD
        long LCD2_BAUD
    
    PUB Main
        LCD1_BAUD:=9600
        LCD2_BAUD:=19200
    
        LCD1.Start(1,@LCD1_BAUD)
        LCD2.Start(2,@LCD2_BAUD)
    
        repeat
             LCD1_BAUD:=LCD1_BAUD+10 
             LCD2_BAUD:=LCD2_BAUD+10
        
             DoMoreStuff(....)
    
    
    
    *************************
    ****    LCD.spin FILE   
    *************************
    PUB Setup(lcd_pin_, lcd_baud_)
      lcd_pin               := lcd_pin_             'copy constant to assembler space
      lcd_baud_ref      := lcd_baud_ref_     'copy reference to assembler space
      cognew(@Run, 0 )
     
    
    DAT ORG 0
    RUN
    'setup lcd_pin as a mask (note: lcd_pin is a constant and will never change)
         mov t1,#1
         shl   t1,lcd_pin
         mov lcd_pin,t1
    
    'read the baud rate, compute bit-ticks on the fly
         rdlong t1,lcd_baud_ref
         call #do_bit_ticks
    
    'more program
    ....
    
    
    t1 long 0
    lcd_pin long 0
    lcd_baud_ref long 0
    
    
          
    
    
    >
    
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-26 22:41
    Many people do it that way. Fine you give this additional example.

    I think "Start" = "SetUp" ?

    Edit: An additional advantage is that you can sometimes trade expensive COG space against cheap HUB space:
      lcd_pin               := |< lcd_pin_
    


    will save you 3 COG instructions..

    Post Edited (deSilva) : 9/26/2007 10:49:05 PM GMT
  • scottascotta Posts: 168
    edited 2007-09-26 22:53
    Parallax should do an example on this method, its
    much easier to read than:

    mov t1,par
    rdlong a,t1
    add t1,#4
    rdlong b,t1
    ...
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-26 23:01
    DeSilva did smile.gif On page 11.

    But the PAR method is much more systematic and can have advantages in case of MANY parameters.
    Also, when you want to load many COGs with the same code a PAR parametrisation avoids the waiting for the end of loading of each of those COGs....

    The main pitfall is, that when using VAR variables as target, the mixing of LONGs, WORDs, and BYTEs can lead to much confusion
  • scottascotta Posts: 168
    edited 2007-09-26 23:31
    [noparse]:)[/noparse]

    I should Read the Funny Manual

    Thanks !
Sign In or Register to comment.