Hello. This is Dr Miller, And this is Episode 12.2 of Assembly.
Today, we're going to give an example using vector registers.
So here's our vector example. So what is our problem? To be solved.
So what we'd like to do is be able to read into imagers and then do multiplication using neon and then print off the result.
so I've already created the project,
so let's begin. So first of all, we're going to do some reading in using scan if and we're also going to do some printing using print F. So we're gonna
to find our strings here at the top will call him input.
We're just asking values, and we'll put a percent d in here
is gonna be the value
we over using print f and
and then we're gonna define our our variables. Organise So we have a is an end
so given values? We could look at him in the bugger, which is something that I think it would be useful,
but we'll go ahead and get started so we'll put our start putting our code in here.
So a couple things that we're gonna want to do so actually, in this we're gonna wanna save our frame pointer,
and then we we get down here, we want us to restore it.
So we're gonna actually modify our frame pointer in here, so we might as well save it.
So here, we're going to set the frame pointer, toe out of frame pointers
it's gonna be the stack pointer plus for
and then we'll allocate some speakers on the stack.
and then for the scan if we're gonna actually, um,
use the frame pointer in order to point to some memory. So
the place that we need to store that is gonna be in our one because we're going to make a function call to scan. If so,
take the frame pointer and subtract eight. So down four is going to be an old version. So we'll go down eight
and then for scan F. So we have our zero is the pointer to where we're going to store the data as per input and then we need to use our one.
There are zero to point to this format string, so we'll give that input
and then we'll call scan if
the branch with link to scanner.
So I put a comment here.
Okay, so once we've read it now, frame Pointer
minus eight is going to point to that location, and so we're going to
basically want to save that, so we'll go ahead and load into the register. Are zero
the value at frame pointer
So what a load. The value that we reading from the user.
Maybe they need to load the address that we want to say that.
So we're gonna save that into a
and then we need to save the data. So store register, we're gonna start are zero into the location at our one. So now we've just saved our value
we want to load these into the vector registers. So do L. D. R.
and then we'll use the LD R
de So it's gonna load. Two registers are, too
zero. So we got the address
and then we go ahead and,
load that into R two and R three
and then when we do a vector move,
remove a 32 bit integer from S Z into s zero from our two and slide a load R two and R three
And then because I'm gonna do larger multiplication,
to the value of zero.
So this will clear out. Basically, it'll set
that data into D zero,
expanding those registers here. We did a zero Phil, which is probably the best thing to do.
So then when we need to do is we need toe load the second number.
So once again, we need to set our registers like we did here.
So I'm going to copy this. Why? Why?
Why three? Why will copy three lines, Envy I
And if I do, ah p for put, it will copy those three lines.
So we're gonna do the same thing when we scan that, and then we can actually copy these three lines
to be able to save our value, except instead of saving into a we're going to save them to be
so go ahead and load our register.
We load the location of B into our one, and then we're in a store are zero back into our one
on our skin off was the same,
so there's no difference there.
All right, so now we need to go ahead and load our values. So LD r r zero
L d r d to load a d word are too
just loading imagers. So energy or 32
siloed r two and r three and toe s to
and then set s three
B I should put up here This is B This is a so I got a and we gotta be
So we have d zero and d one and we're going to go ahead and multiply those together
so we can use thievy mole
and say so we're gonna save the result in D two. We're gonna multiple I d one and D zero. So, do you want Andy? Zero get multiplied together,
The result to get stored in d two.
So then we can go ahead and try and save that to see
so they can load, register are zero
to save it into that, we have to do the V store register.
We're in a store register D to
into the value at our zero.
So now we've saved it to see
the last thing we want to do is we went to print it off.
They will put a comment.
The last thing to do is print so we can go ahead and node register are zero
and then we'll load are
So this will load that into our one. So we're just gonna load a 32 bit integer from
from sea because that's what we defined, See, as and here we did the store to save to it. So here's our print off
and then at the end, ah, to fix the stack because we did
do some modification. We can say sub
SPF be the number four. So
we had added to the frame pointer. Four bites at the very top and so we can subtract from the frame pointer to restore the stack toe where it was.
So we can just do that. And then our pop should work.
I have a typo here, So Line 46. Helpful hint in V. I said Cole and the line number you want to go to
So it should be the mole
Well, I think I put the wrong character there. That should be equal zero.
Now, one thing that I did do in the make files.
So because we're using, um, the FBU we needed tell GCC what type of instructions to generate for that. So we use the minus mfp u equals
neon desh VF PV four. So I looked on the raspberry pi and this is the version of the floating point that is included.
You have to check if you're doing it on a different device. If you have a different floating point specifications that you can compile it too.
So I had ad that bolt to the assemble command and the GCC command,
and you can see it when I right when I ran Make
that it's using those options. So that was modified. So that way it will work.
So here we entered 10 and then 20. And then you multiply them together using the neon, and you get the result of 200.
So today we talked about using the UN registers for some inner energy operations. We also use print, F and scan. If enorme
and so in the future will look at floating point in neon and then s I m. D and neon.
If you have questions, you can contact me, Miller, MJ at you and Katie to you. You can find me on Twitter at no house 30.