Passing constants and addresses to assembler
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
and references (addresses) from Spin to assembler without the
use of the PAR variable ?
Scott
Comments
- 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.
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 >
I think "Start" = "SetUp" ?
Edit: An additional advantage is that you can sometimes trade expensive COG space against cheap HUB space:
will save you 3 COG instructions..
Post Edited (deSilva) : 9/26/2007 10:49:05 PM GMT
much easier to read than:
mov t1,par
rdlong a,t1
add t1,#4
rdlong b,t1
...
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
I should Read the Funny Manual
Thanks !