Need help with a code

Did it work?
 
START and END are usually instructions for compilers and editors and not program opcodes.
 
When your code stops use END. Your subroutine is still code. I don't think the PLC interpreter adheres to this standard very well and allows non-standard practices.
 
The CPU may execute past the end of your main program and through the subroutine until it encounters the RET. Then it  will cause it to crash by using a random RET address you did not install with a GOSUB. The gosub/ret  stack will also be out of sync.
 
When PLC sees END, it will move to execute next instruction which is START.
If you using CALLSUB, it is better to use matching RET.  In this way, stack pointer can be maintained without problem. Because each time a CALLSUB called, a pointer is being saved, when RET called, it will pop up that address for RET. The space to store the original pointers has its own limitation.  If you don't care about using RET, then it is better using GOTO, BZ, BNZ,
 
Back
Top