SimpleIDE CogC Stack and Sub routines
greybeard
Posts: 65
in Propeller 1
I have been working with developing COGC routines and can get them to work passing a data structure and running everything inside the main routine. However, code is much more efficient if a sub-function or sub-routine can be called to do some data manipulation. I think I need a stack in the COGC to call these sub-functions or sub-routines and a methods to make these functions visible to the main.
Anyone have some advise??
Anyone have some advise??
Comments
And then pass &par.m to cognew. See for example the toggle/cog_c_toggle demo; it does set up a stack, even though in fact the toggle_fw.cogc file doesn't need one.
Another option is to declare functions as _NATIVE. Then they will use the PASM calling convention (storing return address directly in the jump that ends the subroutine) and so won't need a stack for subroutine return addresses. They may still need a stack for data storage though, so it's always best to provide a small one.
Perhaps the documentation needs to be updated. It should say that all of the functions in a COGC file are compiled together and loaded into the same COG, so it's safe for them to call each other. They cannot call functions that are in another COG, including the main COG. What was your understanding?
I assumed that it would not be possible to call function not in the COGC file and all communication with the HUB goes through the passed PAR structure data passed to the cog. The same as spin.
BTW. The par structure used in the toggle example is defined but not used. It only passes the mailbox structure. A part of my confusion.
My basic understanding the propeller code architecture is lacking and I'm not sure that what I think I understand is correct....but all that is for another post.
Thanks for the re;ply
https://github.com/parallaxinc/propgcc-docs/blob/master/doc/InDepth.md
Makes sense now.
That link got a bit messed up. Here it is: https://github.com/parallaxinc/propgcc-docs/blob/master/doc/InDepth.md