Hello. This is Dr Miller, and this is Episode 11.9 of Assembly.
Today we're gonna talk about armor raise and arm indexing.
there are a lot of different methods of creating array. And what an array is is just a consecutive sequence of bites.
So it's a bunch of bites that are all in order, and we can't sort of break them up.
And so here we got a couple of different examples. So here we can use the dot skip, and then we can use a little bit of math,
so this would be 13 words. So 13 times four
gives us whatever that number is. It will allocate that much space.
We also technically, when we use an array of bytes for a string, so its array of characters So that's also an array. So it's defined as each one of these has an index or an offset.
Um, and they all take up size one for each one of those.
And additionally, we can define array by using the dot word so I can call it an array. And Aiken, define what the values are for each one of those We have
an array of words that has values 135
So when we have an array, we have to be able to index or go somewhere into that array. And so if we haven't array here that again has size 13 times four,
we can use LD R to get the address of that array, and then we can use, in addition, in order to get a particular offset.
So this would be our zero plus four, which would be index one. So if you deal in a high level language,
you would use a bracket one if they were all imagers. I'm here. We have to actually calculate how far that ISS So if we're using words that be offset for
and then we're just picking a value to movinto are too
And so you can see here the brackets denote that were de referencing that as a pointer. So there's a pointer. You had four to the pointer and then you get the value of that.
Now, additionally, you can directly use an offset. So instead of me having to add it, I can say are zero and then Oh, by the way, add the number four in there.
So again it gets the same value. So this would be offset. One offset zero. You would add zero but offset one. You would add four
again if we're using words inside of our ray.
So arm indexing. So arm has additional index modes that we can take advantage of
on the two additional modes, other than just normal indexing are pre index and post index.
So pre index, the offset is added before you try and access that element and then post indexes after you, um, access that element or either read or write that piece of data.
So here we got a couple different examples showing all the different types of indexing. So we got pre indexing and post indexing and normal.
So this is what we saw in the first example. So we have. Our two has our address of our array, and then here we are, adding eight to that offset,
and so are zero gets the value of R two plus eight. So it's getting going to offset to if, for these air, these are words. So each one of them takes up four slide be offset to
at the end right R two has not changed in this example.
Now we have pre indexing, which means that we're going to take our to and we're gonna add it. Add eight to it before we do the access.
um, when we're all done, our too, then ends up being updated by eight. So it's getting the thing at at our two plus eight. Um, when we are trying to access set
and here you can see that the bang, that means that it is pre indexed.
So it's gonna add the offset before gets the access. So in this example, if we have a ray, the value that's going to get loaded into our zero is going to be,
um, are zero plus eight. So here's both zero plus four plus eights are zero is going to get the value two or three.
Now if we look in the post indexed. So here we are taking our two, and we're gonna add eight to it at the end. So we're adding eight to update the pointer,
but the value that gets stored in r zero is going to be the value that's at are two. So are, too, has a base of our race. So the value that it's going to get is the number one right, So it's going to get offset zero.
So that's you can see the difference doing pre index imposed Index in. Both of them were updating our to to say that we've moved,
um, forward some amount.
But, um, it just depends on when it reads the value. If it reads it, I you, um after or before
and then we can look at an example here. So here we are, defining an array that has 100 elements in it.
So we're skipping 100
and then we're going through here, and we are We go ahead and load that address into our two. We load our counter into our three it we set it at zero,
and then we can see here we are doing a store register. So are three is are offset. Are too is the beginning of the ray and our three. So we're basically writing the offset into the array.
There's just so that we would get some different values. And then here we are, manually updating our three. So here we are actually doing the update of the index,
um, for this one. And then we're comparing it to 100 times for so we see if there's
we go through 100 elements inside this array and try and do that, and then we loop around,
um, with this branch less unequal, the top, and then when we're all done loading the array, we go ahead and read a number from the user.
we are assuming that each one of these is four bites. So we're figuring out what are offset is going to be. So we have to multiply the number that we have read from the user by four, because each element takes up four bytes is what we're assuming in this example.
And then it will go ahead and it will load the array. And then again, use that offset are one which was the star R E R zero, which is the offset and are one which is the array to load that number and printed.
All right, so if they enter the number zero, they would get the number zero. If they enter one they would get, um, before I believe
right. So it goes through and does that now we can change this
so that we add the post right back.
So here we again are we have are three gets the number zero.
And so when we do the store, we're going to, um
right, right. The value to our to
So our two has our array.
So we're writing to that pointer, and then we're at when we're all done, we're adding for so we removed a necessary step, right? So that it we put it all in one command because we're post writing back.
And here I'm adding one toe are three so that we can go through 100 times.
Um, that allows us to to write the number 01234 So subtle, right? A little bit different numbers to the array.
And if want, you can type this in and you contest that and see, um if it does, we do you think it does, right? And again, we are multiplying by four. Because the user each one of these is imagers. And then we'll go ahead and do a
a load of that number and printed off for the uses they can see.
Um, what number? That was in the area at that location.
So we can use these when we are using loops so that we don't have to do multiple commands weaken Basically do due to operations in one command.
So today we talked about arm arrays and arm indexing.
I'm looking forward, will do an example using an array will code that live. And then we will look at, um the multiple load in store. And so there are additional functions that we can look at.
So, given the array above, so are too is our array. How do we offset the array at offset Are too with the right back of plus four.
So here we go ahead and access it, and then we are going to add for right. We wanted a
ah post post right back here.
So if you have questions, you can email me, Miller MJ at you and Kate I e to you. And you can find me on Twitter at Milhouse 30