Neon Example
Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or
Already have an account? Sign In »

Video Transcription
00:02
Hello. This is Dr Miller, And this is Episode 12.2 of Assembly.
00:07
Today, we're going to give an example using vector registers.
00:11
So here's our vector example. So what is our problem? To be solved.
00:15
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.
00:26
All right,
00:28
so I've already created the project,
00:37
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
00:47
to find our strings here at the top will call him input.
00:54
We're just asking values, and we'll put a percent d in here
00:58
and then output
01:00
okay,
01:02
is gonna be the value
01:06
IHS.
01:11
All right.
01:11
And then
01:14
we over using print f and
01:19
scana,
01:22
and then we're gonna define our our variables. Organise So we have a is an end
01:36
Theisen ent.
01:42
See? Isn't it
01:44
so given values? We could look at him in the bugger, which is something that I think it would be useful,
01:51
but we'll go ahead and get started so we'll put our start putting our code in here.
01:56
So a couple things that we're gonna want to do so actually, in this we're gonna wanna save our frame pointer,
02:04
and then we we get down here, we want us to restore it.
02:08
So we're gonna actually modify our frame pointer in here, so we might as well save it.
02:13
So here, we're going to set the frame pointer, toe out of frame pointers
02:16
I'm supposed to be.
02:19
So
02:21
it's gonna be the stack pointer plus for
02:25
and then we'll allocate some speakers on the stack.
02:31
We'll allocate
02:34
10 on there
02:37
and then for the scan if we're gonna actually, um,
02:40
use the frame pointer in order to point to some memory. So
02:46
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,
02:53
we will
02:54
take the frame pointer and subtract eight. So down four is going to be an old version. So we'll go down eight
03:01
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.
03:15
There are zero to point to this format string, so we'll give that input
03:23
well,
03:23
and then we'll call scan if
03:24
the branch with link to scanner.
03:28
So I put a comment here.
03:30
Freed burst number.
03:35
Okay, so once we've read it now, frame Pointer
03:39
minus eight is going to point to that location, and so we're going to
03:45
basically want to save that, so we'll go ahead and load into the register. Are zero
03:51
the value at frame pointer
03:53
minus
03:57
clary,
03:58
number minus eight.
04:00
So what a load. The value that we reading from the user.
04:05
Maybe they need to load the address that we want to say that.
04:09
So we're gonna save that into a
04:16
okay,
04:17
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
04:28
for a
04:30
and then
04:32
we want to load these into the vector registers. So do L. D. R.
04:39
Are zero
04:42
the address of a
04:44
and then we'll use the LD R
04:46
de So it's gonna load. Two registers are, too
04:50
the value at our
04:54
zero. So we got the address
04:57
and then we go ahead and,
05:00
um,
05:00
load that into R two and R three
05:04
and then when we do a vector move,
05:10
remove a 32 bit integer from S Z into s zero from our two and slide a load R two and R three
05:18
And then because I'm gonna do larger multiplication,
05:21
I will go ahead and
05:26
said s one
05:30
to the value of zero.
05:32
So this will clear out. Basically, it'll set
05:36
that data into D zero,
05:44
expanding those registers here. We did a zero Phil, which is probably the best thing to do.
05:51
So then when we need to do is we need toe load the second number.
05:56
So once again, we need to set our registers like we did here.
06:02
So I'm going to copy this. Why? Why?
06:05
Why three? Why will copy three lines, Envy I
06:12
And if I do, ah p for put, it will copy those three lines.
06:15
So we're gonna do the same thing when we scan that, and then we can actually copy these three lines
06:24
to be able to save our value, except instead of saving into a we're going to save them to be
06:31
so go ahead and load our register.
06:33
We load the location of B into our one, and then we're in a store are zero back into our one
06:40
on our skin off was the same,
06:42
so there's no difference there.
06:46
All right, so now we need to go ahead and load our values. So LD r r zero
06:55
We're gonna load be
06:58
L d r d to load a d word are too
07:01
value at our zero
07:05
be move
07:10
just loading imagers. So energy or 32
07:13
s to
07:15
hard to
07:17
siloed r two and r three and toe s to
07:29
and then set s three
07:31
to the number zero.
07:34
So here we are
07:38
setting the one
07:43
with
07:44
B I should put up here This is B This is a so I got a and we gotta be
07:50
So we have d zero and d one and we're going to go ahead and multiply those together
07:59
so we can use thievy mole
08:03
32
08:07
to multiply
08:09
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,
08:18
The result to get stored in d two.
08:22
So then we can go ahead and try and save that to see
08:24
so they can load, register are zero
08:28
see? And then
08:31
to save it into that, we have to do the V store register.
08:35
We're in a store register D to
08:39
into the value at our zero.
08:43
So now we've saved it to see
08:46
the last thing we want to do is we went to print it off.
08:50
They will put a comment.
09:05
The last thing to do is print so we can go ahead and node register are zero
09:09
The pointer to see
09:13
L. D R
09:15
are won by are zero
09:22
and then we'll load are
09:24
a type of there.
09:30
So, well,
09:31
load,
09:33
load register
09:35
are zero
09:35
the output string
09:39
membranes with link
09:41
grant f.
09:43
So this will load that into our one. So we're just gonna load a 32 bit integer from
09:50
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
10:05
and then at the end, ah, to fix the stack because we did
10:09
do some modification. We can say sub
10:13
SPF be the number four. So
10:18
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.
10:26
So we can just do that. And then our pop should work.
10:37
I have a typo here, So Line 46. Helpful hint in V. I said Cole and the line number you want to go to
10:45
go right there?
10:48
So it should be the mole
10:50
I 32.
11:05
Well, I think I put the wrong character there. That should be equal zero.
11:13
Here we go.
11:15
Now, one thing that I did do in the make files.
11:20
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
11:31
neon desh VF PV four. So I looked on the raspberry pi and this is the version of the floating point that is included.
11:41
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.
11:50
So I had ad that bolt to the assemble command and the GCC command,
11:54
and you can see it when I right when I ran Make
11:58
that it's using those options. So that was modified. So that way it will work.
12:09
So here we entered 10 and then 20. And then you multiply them together using the neon, and you get the result of 200.
12:20
So today we talked about using the UN registers for some inner energy operations. We also use print, F and scan. If enorme
12:31
and so in the future will look at floating point in neon and then s I m. D and neon.
12:37
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.
Up Next
Similar Content