@ operator in Spin
David Betz
Posts: 14,530
Can someone remind me of the rules for using the @ operator. I think I'm getting in trouble by trying to pass the address of variables to PASM code. Does that work? Or do I need to put those variables in a DAT section?
VAR
long foo
DAT
bar long 0
PUB test | x
x := @foo ' do I get a hub address here?
x := @bar ' do I get a hub address here?

Comments
Yes to both questions. Only @ usage in DAT sections needs special care.
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 #0 OP_RESULT OP_ADD OP_SUB OBJ pkt : "packet_driver" VAR long type long buffer[4] long length PUB main | sts outa[18..16] := %100 dira[18..16] := %111 pkt.start(31, 30, 115200) repeat length := 16 sts := pkt.rx(@type, @buffer, @length) if sts == 0 case type OP_ADD: outa[17..16] := %01 buffer[0] := buffer[0] + buffer[1] OP_SUB: outa[17..16] := %10 buffer[0] := buffer[0] - buffer[1] other: outa[17..16] := %11 buffer[0] := $deadbeef else outa[23] := 1 dira[23] := 1 pkt.tx(OP_RESULT, @buffer, length)Makes sense in a way. So we need to see some more.
You probably using @ again inside it, though the var you passed to it was the @address.
So attach the complete zip file
pkt.zip
Can you explain what the structure and data you are trying to pass to cog and I will try show how I would do the mailbox.
Length is lower 9 bit so you can use it in the pasm as is, with movs.
pkt.zip