On Fri, 25 Apr 1997 08:15:27 -0600 Ed Todd writes: >I use the push down nature of the CALL stack quite a bit to optimize >code >space. It sounds like you are relying on stack wrap-around, right? It seems dangerous to me to leave stuff on the stack since I don't really keep track of who's calling what from where. If there's some extra garbage on the stack and I do a return... watch out! >For example, I have a timeout procedure, called from several >locations on different pages. The structured programming method of >doing >this would be: > CALL TIMEOUTPROC > IF (FLAG1) > GOTO RETRY // timeout, resend message > IF (FLAG2) > GOTO JAMMING // signal jamming error recovery > IF (FLAG3) > GOTO SLEEP // no traffic, go back to >sleep >Duplicating this logic gets expensive in code space. It is even worse >if >the test is made during a call: Instead of setting flags, how about returning a unique state number, then using a jump table. JumpTable movlw high(JumpTable) movwf pclath ; Set up high PC latch for jump movfw SystemState ; Get state (0..3) andlw 0x03 ; Mask leaving 2 lsb addwf pcl,1 ; Add to PC goto NoError ; State 0 - No error, so continue goto Retry ; State 1 - Go retry goto Jamming ; State 2 - It's jammed NoError ; State 3 - Here same as state 0, no error sleep Harold