>> Is it not possible to prewrite the stack with known data and then >> examine it explicitly or implicitly after running the program or on >> diagnostic occasions during operation to see how close it has come to >> its bounds, or whether it has exceeded them. > On a couple of systems I have worked on, the diagnostic code did exactly = that. > Preset the stack memory with a known data pattern. As part of the timer t= ick routine, the stack is looked at to check just for overflow - takes a co= uple of reads to do. As part of low priority diagnostics task, the stack us= age is calculated - can be done with a successive approximation scheme to m= inimise the number of reads needed. This code would check all the task stac= ks. .... > >From the data sheet, "The PC is PUSHed onto the stack when a CALL instru= ction is executed or an interrupt causes a branch. The stack is POPed in th= e event of a RETURN, RETLW or a RETFIE instruction execution." If you could= instrument call, interrupt and return events to increment and decrement a = counter, you should be able to keep track of the stack. I was thinking of setting up the stack in a manner such that the footprints of the original setup were still visible. When you start you have the system under explicit control and can produce stack writes of known content. Subsequently it may be possible to perform some action which depends on the stack having the original value. Tasks which "run out the door" when popped may be able to be trapped almost immediately by a timer interrupt. If "the stack wraps silently, as noted, it may be possible to work it down to "empty" and then pop again to "wrap silently" so you are at the top of the stack and working down. Calls with original data in would pop to locations which were known. When you got a pop that did something different you'd know the original value had been overwritten. You may have one chance in 2^stack_address_bits of missing a corruption if popping single addresses. Russell --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .