> >> I almost thought I could do this with the 18 series, but as I look >> closer, >> I'm thinking not. Is there a way to copy data on and off the stack? > looking at the 452 data sheet under memory organisation we see a section > labeled return address stack, this contains the following. > > "The stack space is not part of either program or data > space. The stack pointer is readable and writable, and > the address on the top of the stack is readable and writable > through SFR registers. Data can also be pushed > to, or popped from, the stack using the top-of-stack > SFRs. Status bits indicate if the stack pointer is at, or > beyond the 31 levels provided." > > so now i head off to the special function registers section under data > memory, this directs us to pages 37 and 38 where we find a description of > the special function registers that relate to the stack. > > there seems to be enough information here to write code to save/restore > the stack. > > The code to save the stack would be something like > > short long [32] savedstack; > //since the first entry in the stack is in slot 1 > //we may as well use slot zero in the array for the > //stack pointer > savedstack[0] = STKPTR&0x1f; > while ((STKPTR&0x1f) != 0) { > savedstack[STKPTR&0x1f] = TOS; > _asm POP _endasm > } > > and the code to restore it would be something like > > STKPTR=0 > while ((STKPTR&0x1f) != savedstack[0]) { > _asm PUSH _endasm > TOS = savedstack[STKPTR&0x1f]; > } > I think this would work if push and pop did what I think they should. But, as I read the manual, push pushes the current PC (or maybe PC+2) onto the stack, not the TOS registers. Further, it appears POP does not put the contents in the TOS register, but throws them out. Actually, it appears TOS would be updated, so we could recover data off the stack from there. But, how do we put data (other than the PC) on the stack? Harold -- FCC Rules Updated Daily at http://www.hallikainen.com - Advertising opportunities available! -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist