So I've been tweaking and cleaning up some code, and now I come to a question about stack operations.
The code in question originally had several places like so:
I didn't like the idea of the "emergency exit" from the subroutine (especially as it wouldn't translate well to higher level languages), so I adjusted the code like so:
So far, so good. Just wanted to give some background.
Now then, the second instruction the code executes after a power-up or reset is an instruction to reset the stack pointer: (LDS #$00FF)
I could see the need for this instruction in the original code, given that the code actively messes with the stack pointer, but now that I have eliminated all the INS instructions, do I even need to bother with manually resetting the stack pointer at the start anymore?
The code in question originally had several places like so:
Code:
(subroutine code)
(check for error condition)
(error condition detected)
INS
INS
JMP (error trap routine)
(no error, continue with subroutine)
RTS
Code:
(subroutine code)
(check for error condition)
(error condition detected)
LDA #error
STA error_num
RTS
(no error, continue with subroutine)
RTS
.
.
.
(main routine immediately following JSR instruction)
TST errornum
BEQ no_error
JMP (error trap routine)
no_error (continue with main program)
Now then, the second instruction the code executes after a power-up or reset is an instruction to reset the stack pointer: (LDS #$00FF)
I could see the need for this instruction in the original code, given that the code actively messes with the stack pointer, but now that I have eliminated all the INS instructions, do I even need to bother with manually resetting the stack pointer at the start anymore?