{{ Tutorial on how to pass a number variable and perform subtraction with the sub directive from spin to pasm and back, this works for numbers from 0 to 256, bigger numbers in a later tutorial}} CON _clkmode = xtal1 + pll16x '_xinfreq = 6_250_000 'MY BOARD AT 1OOMHZ DIFFERENT CRYSTAL _xinfreq = 5_000_000 'QUICKSTART 80 MHZ NORMAL CRYSTAL obj pst:"parallax serial terminal" var 'global variables long datavar long answervar long subvar pub main datavar:= 25 'assign a value to datavar subvar := 12 pst.start(115000) 'start the serial terminal object waitcnt(clkfreq*5 +cnt)'hold five sec to open the cognew(@asm,@datavar) ' open a new cog for pasm. where it starts "asm" and ' the address of the first variable waitcnt(clkfreq+cnt) ' hold for a second ' print routine pst.str(string("results:")) pst.newline pst.dec(answervar) pst.newline dat asm org 0 'This is the starting point for PASM {{ The first item is to move the address of the parameter register "PAR" into a temporary variable and assigne it to the variable in which we will read the in this case the value of datavar in the spin method. }} mov temp_var, par {{ Now we are going to assign the pasm variable, data_var, the address of datavar in the spin method. }} mov data_var, temp_var {{ Now we have to move over to the next long to get the address of answervar in the spin object and assign it to answer_var in the pasm code.}} add temp_var, #4 {{ Now assign this address to answer_var. }} mov answer_var,temp_var add temp_var,#4 'move over to the next long and get the subtraction variable address mov sub_var, temp_var 'assign the address to the variable rdlong sub_var,temp_var 'read the value in that address {{ Next read the value of datavar (spin object) into the pasm data_var. }} rdlong data_var, par 'go back and get the value from the data variable that is in the par register sub data_var,sub_var ''perform the subtraction data-subvar= xxx {{ Finaly write it to the answer_var which is spin's answervar for printing. }} wrlong data_var, answer_var {{ Reserved variables reserved for PASM's use. }} sub_var res 1 data_var res 1 answer_var res 1 temp_var res 1