The only difference to "normal" interrupts is the mechanism to trigger the routine.
Wait a minute.
A function call is nothing like an interrupt diverting CPU attention. A function has parameters an interrupt does not. A function has return values an interrupt does not. A function happens when I want it to not at some random time as I run.
A function call is nothing like a different process running on a different CPU. A function returns a process may not. For example.
A function call guarantees availability of a result the moment the program, interrupted by the function, resumes.
That makes me wonder. If a cognew'd function returns (stopping the cog), can you find its result somewhere in its stack? This depends on which flavor of anchor is used, so I doubt it will work but will try to find out now.
stack[3] is not the return location -- it's just the scratch area on the stack where the value of 1234567 was loaded temporarily. A return value is loaded on the stack only if the calling method requires a return value. This is indicated by a bit in the stack frame. I suspect the default stack frame that is used does not specify loading a return value. You could return a value through the RESULT variable, which is located at stack[2]. The following program demonstrates how that would work.
con
_clkmode = xtal1+pll16x
_clkfreq = 80000000
obj
ser : "FullDuplexSerial"
dat
stack long 0[20]
pub main
waitcnt(clkfreq*3+cnt)
ser.start(31, 30, 0, 115200)
cognew(sub1, @stack)
repeat until stack[2]
ser.str(string("result = "))
ser.hex(stack[2], 8)
ser.tx(13)
waitcnt(clkfreq/10+cnt)
pub sub1
result := $deadbeef
Cool! I'm still stuck trying to figure out what the RUN (opcode $15 = %0101_01 = j5 nz_and_nc) PNUT bytecode does and how it has anything to do with strcomp.
Comments
Wait a minute.
A function call is nothing like an interrupt diverting CPU attention. A function has parameters an interrupt does not. A function has return values an interrupt does not. A function happens when I want it to not at some random time as I run.
A function call is nothing like a different process running on a different CPU. A function returns a process may not. For example.
That makes me wonder. If a cognew'd function returns (stopping the cog), can you find its result somewhere in its stack? This depends on which flavor of anchor is used, so I doubt it will work but will try to find out now.
The result is returned on stack[3]
-Phil
-Phil