RET instruction

40mpg

Member
Join Date
Dec 2021
Location
Oakland, CA
Posts
82
I am looking at the source code for a very old project and I noticed that the programmer added a RET instruction without any parameters to the end of every routine.


I don't understand what this is for, a RET without parameter, does anyone have a guess on why a RET instruction is added to every routine?

Capture2.jpg
 
That would tell me that every routine is a sub program
someplace there should be a main program to call at least one of the routines
then each routine would call another as needed
 
RET is the end-of-block instruction for many controllers. Some require it explicitly, some it only shows up in the source code.
 
Probably because it was a requirement of the brand of PLC and programming software, a detail which you failed to provide.


Whoops sorry.

This is a ControlLogix L55. RSlogix 5000 version...pretty old, I don't remember exactly but I think it is 15

They are just standard routines , in the same Program.

It is just odd that I find this and was thinking if I can just leave it out when I upgrade. Leaving the RET at the end out, same code, in Studio Emulate doesn't seem to affect anything.
 
If there is no RETurn instruction and a program (or subroutine) executes to the end of its code block, then I suspect there is no difference between that implicit exit of the code block, and having a RETurn as the last rung execute an explicit exit of the code block.
 
RSLogix 5, 500, and 5000 don't require a RET instruction unless you are passing parameters with it, but you can use it if you want to.

Likewise, the SBR instruction at the beginning of a ladder routine is optional when you are not passing parameters.
 
Sometimes a programmer will include the RET for clarity so that anyone looking at that code will know that the logic will return back from where it was called.

There are some uses for the RET without parameters.

  1. When testing the logic in your subroutine you might add the RET part way through your code so that it will only test the code above that point. Then move the RET further down to test more of the code. Keep doing that until it is at the bottom and you've tested all your code. Usually at that point you remove it.
  2. Add a condition ahead of the RET and place the logic part way down in your subroutine. If the condition is true, then return now and do not execute the rest of the code in the routine. If the condituon is false, then we run through the rest of the code.
That first example could also be a Temporary End (TND).

OG
 

Similar Topics

Hello, I have been tasked to create routines that has a JSR with zero return parameters to go to a routine with a RET with zero parameters. Is...
Replies
2
Views
1,343
Hi everyone, I have a series of 8 or 9 subroutines that are not in the main program file (File 2)..they are all consecutively placed in Ladder 11...
Replies
8
Views
379
I'm looking for a way to use the Audit Value for the controller to detect changes made programmatically. This link lays it out pretty cleary (page...
Replies
7
Views
2,662
On site and another Programmer is getting a Major Fault when downloading code that I gave him to interface withour machines. I have JSRs that...
Replies
3
Views
863
Posted just because it's has an Allen Bradley keyed selector switch https://www.youtube.com/watch?v=YeFevEGoPF0 LockPickingLawyer
Replies
6
Views
2,672
Back
Top Bottom