Help! Odd cog behavior
in Propeller 1
This program starts up a cog that doubles a number and writes it to hub memory. The output on the serial terminal is "246" followed by exclamation points, one per second. Not very interesting but at least it's what I expect.
What I don't understand is why, if I change the jmp destination to #wait1, the terminal shows "24@" and no exclamation points. I don't understand why it should make any difference. Can someone explain what's going on?
What I don't understand is why, if I change the jmp destination to #wait1, the terminal shows "24@" and no exclamation points. I don't understand why it should make any difference. Can someone explain what's going on?
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
serial : "FullDuplexSerial"
pub Main
serial.start(31, 30, %0000, 115_200)
waitcnt(cnt + clkfreq * 2)
serial.dec(Start(123))
repeat
waitcnt(cnt + clkfreq * 1)
serial.tx("!")
pub Start(m)
n := m
cognew(@entry, @result)
waitcnt(cnt + clkfreq * 1)
dat
org
entry mov ptr, par
add n, n
wait1 wrlong n, ptr
wait2 jmp #wait2 ' change to #wait1
n long 0
ptr res 1

Comments
It's because result goes out of context after Start returns, but your wrlong is still writing to the stack.
-Phil
It's safer to do
cognew(@entry, @n)
referring to the global variable n, and then,
serial.dec(n)