How to get VAR block starting address for and object.
So, I'm writing a SPIN object and like would like to be able to longfill the VAR section of the object really easily.
Right now I'm just using the address of the first element in the VAR block and longfilling from that. But I would rather have some address that references the whole VAR image instead...
Any easy way of doing this? I know what the size of the array is and that will remain constant.
Right now I'm just using the address of the first element in the VAR block and longfilling from that. But I would rather have some address that references the whole VAR image instead...
Any easy way of doing this? I know what the size of the array is and that will remain constant.
Comments
vbase := word[addr][4] dbase := word[addr][5] numbytes := dbase - vbase - 8 bytefill(vbase, 0, numbytes)
Your first long variable is at the first address you'd clear. Your last byte variable is at the last address you'd clear.
-Phil
Here's an example:
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 VAR long first_var[0] 'Put first. long longa, longb, longc 'Anything can go here, in any order. word worda, wordb[14] byte bytea, byteb byte last_var[0] 'Put last. PUB Start bytefill(@first_var, 0, @last_var - @first_var)
-Phil
con _clkmode = xtal1+pll16x _clkfreq = 80_000_000 obj ser : "FullDuplexSerial" var long firstvar pub main ser.start(31, 30, 0, 115200) PrintVbase pub PrintVbase ' Print the address of the first VAR variable ser.str(string("@firstvar = ")) ser.hex(@firstvar, 4) ser.tx(13) ' Print word 4 from the program header ser.str(string("word[0][4] = ")) ser.hex(word[0][4], 4) ser.tx(13) ' Print the vbase in the call frame ser.str(string("word[@result][-3] = ")) ser.hex(word[@result][-3], 4) ser.tx(13) ' Print the vbase from cog address $1ec in the Spin interpreter WriteVbaseRegAddr ' Overwrite the vbase register address in next instruction result := ina ' Read vbase instead of ina ser.str(string("Cog address $1ec = ")) ser.hex(result, 4) ser.tx(13) pub WriteVbaseRegAddr | retaddr retaddr := word[@result][-1] ' Get return address byte[retaddr+1] := $8c ' $1ec - vbase
Thanks both of you!