All right boys and girls we are back for two more commands.
Today we're going to be looking at return and temporary end.
So without further ado let's go ahead and get everything up and running.
Our S links emulate.
We're going to load this thing up and that's going to be our return temporary.
And so when you have all your sample programs if you want to go through this that's what you're looking
for.
Set that station up to 1 and let's get this thing running.
And once we're running Let's go ahead and go on line with emulate we are connected.
Let's make those bigger so we can see.
And let's start going through this.
OK this looks bigger.
This looks more complicated.
And I've even created a subroutine here which looks more complicated and all of that is just to demonstrate
to instructions.
OK.
Right now you're thinking bummer.
There's a lot going on here.
Really this isn't as bad as it looks.
Don't worry.
Let me explain how this thing is for starters.
We've got these two less than competitors.
Don't worry about these the values we're looking at here in seven one and in seven to.
Those are just going to be storing results of our test.
So we're going a store in 7:1 at the beginning of our execution.
We're going to store in 7:2 at the end of our execution.
And these are always going to be less than ninety nine ninety nine.
So the only reason these two instructions are here is just to show us what in seven one in in seven
to our without having to come down here and go through data tables and things like that.
So these are just here's a convenience and this action really doesn't need to be here but it's really
just resetting in seven zero back to zero value which is where we wanted pretty much all the time.
Now we're going to be doing three different tests.
We're going to be testing the routine all the way through.
We're going to be testing the routine using a return.
And then we're going to be testing the routine using a temporary end and each of these is on one shot
because whenever we toggle one of these switches we only want the routine to execute one time not two
or three or four one time then we've got our trigger bits over here.
These are what's going to carry our one shot actions over into this point where we actually execute
our set routine which is this ladder three right here.
And it's also where we're going to store our start of execution value.
So in 7 0 at the start of execution should always be zero.
So we're always going to have zero stored in in 7:1 but in in 7:02.
At the end of execution we should have different values depending on how our cycle works.
So the subroutine is what's going to be modifying the 7:2 value.
So let's check it out and see what's happening in there.
When we come into the subroutine we are seeing this is the common operation we're doing in here.
We're going to be moving some source value whether it's 100 or 200 or 300.
We're going to be moving that to in 7 0 and then we're going to be copying or moving in 7 0 2 7 2.
And remember in 7:2 is what we're looking at at the end of execution because we want to see what it
ends up at.
So what this program what the set routine tries to do is move 100 to in 7 0 and then store that into
in 7:02.
Then when it comes down to rank 2 it wants to move 200 into in 7 0 and then store that to in 7:2 and
then we come down here.
It wants to move 300 into in 7 0 and store that in 7:02.
That's the end of the routine.
So if we run this routine what we should end up with is 300 in in 7:02.
So let's find out if that happens.
I'm going to toggle this to test complete routine and as soon as i do we can see at the start of execution
in 7:01 was stored at 0 that came from in 7 0.
And sure enough there are three hundred in in 7:2 at the end of execution.
So we effectively moved the values 100 200 and 300 respectively into in 7 0 and then stored that into
in 7:02.
And as we expected at the end it wasn't 100 it wasn't 200.
It was 300.
But now we've got a couple of different instructions which can change the way that a program executes.
The first one we're going to look at is this return.
So when we go back into Ladder 3 if we happen to start this routine with the test return trigger then
what's going to happen is from rung 3 it should return to the subroutine which called this one.
So in this case we used our GSR and ladder 2.
So when we use a return from Ladder 3 when we come back we're going to come back to this next run which
is the end.
But if we had nested subroutines let's say we used the GSR and ladder two to jump to Ladder 5 then we
jumped to Ladder 7 and then we jumped to Ladder 3.
When we return we're going to go back to 7 because that's the one that actually called Ladder 3.
But in this case our GSR is on rung 4 and ladder 2.
So we're going to be returning with rung five on ladder too.
So anyway when we return from here we notice there's still another line there still another rung beneath
our return.
And that's where we set the value to three hundred.
So presumably if we test return we should come into this routine.
We should move 100 into an 7:02.
We should move 202 in 7:02 but we should never see 300.
So at the end we would expect to see 200.
And let's try that.
I'm going to go ahead and reset our end value.
And in seven zeros always kept the zero our start values should always be zero.
Let's test that return.
And sure enough we ended up with 200 because we got here and returned so we never got to execute this
300.
Well one last thing we want to test in this program is this temporary end.
This guy is different from our return because return just goes back to the subroutine that called it.
It goes right back to the GSR.
That led us here in the first place.
T n d on the other hand completely terminates that scan of the program.
So it doesn't matter if we come back into ladder 2 it doesn't matter if after here there were 10 different
rungs with other jump to subroutines it doesn't matter that there was a whole giant mountain of program.
Once we hit a T and D we go back to ladder to rungs 0 and we start back from there.
So it completely terminates the scan.
And if we do this if we TMD here we expect we will never see 200 we'll never see 300.
We should end up with 100 as our final value.
So again let's reset everything and let's go ahead and test our TNT.
And sure enough we ended with 100.
So we got in here.
We set the value to 100.
We hit TNT and then the show is over.
We never executed anything else here.
We if there were more lines here we wouldn't have looked at those lines.
We would have just come back to here and tried to start a new scan.
And this program unless you have one of these toggled for one scan it doesn't do anything so right now
it's basically just scanning this over and over again and waiting for me to do something to tell it
to take an action.
But that's how ARYEETEY return and T and the temporary end work return goes back to the GSR that called
the subroutine containing return temporary end ends the whole scan brings it to an abrupt halt and returns
back to latter to run zero to begin the next scan.
So that's it.
Two more intermediate level commands that you can use and work with and incorporate into your own programs
going forward.
See you next lecture.