0:01
This morning’s webinar will be on the indirect move instruction.
0:06
So we’ll go into the presentation and as usual if you have any questions put them into the bar and we can get to them at the end.
0:11
Hello and welcome to today’s webinar. Today we will look at the indirect move instruction.
0:17
We will start with a review of move instructions. Then we will cover what exactly the indirect move instruction is.
0:26
Then, we will look at how it can be used as well as its use with structured variables.
0:34
There will be demonstrations throughout, and to finish, there will be a Q &A session at the end.
0:41
What are move instructions?
0:43
Move instructions are a class of instructions which allow programmers to move data in a variety of ways.
0:50
For example, you could set a variable to a constant value, set a variable array to a series of values, copy a value from one variable to another, and so on.
1:04
Let’s now take a closer look at move instructions within Cscape 10.
1:09
Here we are in Cscape.
1:11
Here on the right, in our toolbox, we have all of our move instructions.
1:15
We’re going to take a look at each of these one by one.
1:18
First, the move single.
1:20
This is the simplest move command.
1:23
It allows you to move either a constant into a variable, or move data from one variable to another.
1:30
Next, we have the block move.
1:33
This allows us to move multiple values.
1:36
In this demonstration, we are going to move 10 values from temperature readings 1 through 9 into temperature history.
1:44
Next, we have the fill block.
1:46
This allows us to take a single value, in this demonstration 0, and copy it into multiple variable locations.
1:56
Next we have the constant move.
1:58
This allows us to move any number of constants, which we input into this field here, and fill those values into a variable array.
2:08
We are not going to go into detail on these today, but we also have a shift register instruction and a rotate instruction. These have already been covered in more depth in previous webinars.
2:21
You can find these webinars on our channel.
2:26
What is the indirect move instruction?
2:29
The indirect move instruction is similar to the block move, but with one key difference.
2:35
The indirect move instruction allows the source location or the destination location, or both, to be a variable pointer instead of an absolute location.
2:48
To explain this let’s now take a closer look at the indirect move instruction within Cscape 10. Here we are in Cscape.
2:58
Let’s go through some examples of indirect moves.
3:02
For our first example we have 100 set points for our machine and the specific set point we want will depend on which part we are currently running.
3:11
In this example each part we could be running has an index from 1 to 100 that matches to the corresponding setpoint.
3:20
Let’s look at how we would use an indirect move to match the machine setpoint value from its variable array to the machine part index.
3:33
In the source field, we first set the address to our machine setpoint variable array.
3:39
Then we set our offset to the part index, which, in this example, already matches each setpoint in the array. So part index 50 requires machine setpoint 50.
3:55
For our destination we are simply moving the value into our current machine setpoint variable.
4:02
We have successfully shown how to copy from a variable source to a constant destination.
4:08
In our second example we are going to look at a mirrored situation.
4:13
How can we move from constant source into a variable destination.
4:19
In this example, temperatures are being recorded and we are moving them to a different location, depending on the station number that is being operated.
4:29
Let’s look at how we use an indirect move for this.
4:35
Firstly, we can notice that our source is set to direct mode, as opposed to based indirect, like in the previous example, and our source is reading from a variable address, not an array.
4:49
For our destination, we want to move this value somewhere into the temperature readings array based on the offset of the current station number.
4:59
As mentioned earlier, these examples are mirrors of each other, and so our instruction looks very similar.
5:07
Those are two simple examples of indirect moves in Cscape.
5:13
Now, let’s look at a scenario that is closer to a real-world use case.
5:20
Here, we have some more advanced use cases for indirect moves.
5:24
We are going to inspect the first one, where we want to call a subroutine on-demand to calculate the average from a list of 20 integer values.
5:34
Let’s take a closer look at the subroutine.
5:39
First, at the top of the loop, we use an indirect move block to retrieve a value from the list, and add it to the sum.
5:48
Then we increment the index until every value has been retrieved, and we can calculate the average.
5:58
This is how you might use indirect moves in larger programs.
6:03
As you have seen, there are many use cases for indirect moves, but can we use indirect moves on structured variables?
6:11
A structure, in this case, is a user-defined data type that allows grouping of multiple related variables of different types under a single name.
6:22
Here we have an example structure named Motor, with seven variables grouped inside of it of different types.
6:30
With this structure created, we can then create variables that use this structure.
6:36
As seen in the image below, the variables mainMotor, fanMotor, and motorHistory all use the motor structure.
6:47
Note that motorHistory is an array variable with a dimension of 100.
6:54
To access the variables within one of these structures, we add a full stop, and the name of the variable within the structure we are trying to access.
7:04
For example, main underscore motor dot current underscore rating accesses the current rating of the main motor structure, and so on. There are 12 words within this structure.
7:19
We can also use this same structure with arrays. Motor history is an array with a dimension of 100.
7:27
We can still access the variables inside the structure in the same way.
7:34
The biggest change with this example is that main motor contains a hundred times the words of our simple variable example.
7:44
Returning to our original question, can we use indirect moves with structured variables?
7:50
Let’s imagine we want to store the current value of main motor somewhere in motor history.
7:57
The position we want to store the value at is based on a part index.
8:04
To set this up, we would first create an indirect move block.
8:08
This will look very similar to our simple examples from earlier, but we need to be wary of a few key differences.
8:17
First, for our source, we need to ensure that our address is set to mainMotor.CurrentRating, because this is the first variable in our structure.
8:30
Then, for our destination, we set the address to motorHistory0.currentRating.
8:37
This is the first variable in the first structure of our array.
8:41
Then, for our offset, we do not just use our partIndex, but rather a new variable called historyLocation, which is our partIndex multiplied by 12.
8:54
During our setup we are always being careful to take note of the 12 word length of each structure.
9:02
Without this our variables will be stored in the wrong locations within motor history. And finally we set our count to 12.
9:12
We have just shown you how to successfully use indirect moves with a structured variable. That concludes our webinar for today.
9:21
Thank you so much for listening and the Q &A session will begin shortly.
9:33
Okay, we’ll be following on with another data sorting function block webinar next week.
9:40
So the link is there if you would like to attend that.
9:44
I don’t see anything in on this one.
9:46
So I think that’s covered for today.
9:49
So yeah, the registration link is on the website or it will have been in the newsletter that went out about the webinars so you can also get the registration link there.
9:59
Other than that, thank you all for joining us this morning and I will see you next time.