Hello, this is Dr. Miller, and this
is Episode twelve point two 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 integers and then
do multiplication using Nean
and then print off the result.
All right,
so I've already created the project.
So let's begin.
So first of all, we're going to
do some reading in using
ganef and we're also going to do
some printing using print.
So we're going to define our strings
here at the top.
I'll call them input
and just ASCII values and we'll put
a D in here
and then output.
It's going to be the value
is.
All right, and
then.
We will be using print F
and
SCANA and
then we're going to define our of
our variables that we're going to
use. We have a as an end.
He is an end.
See, isn't it
so good advice, we could look at
them in the debugger, 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 of things that we're
going to want to do. So actually in
this, we're going to want to save
our frame pointer.
And then when we get down here,
we want to restore it,
so we're going to actually modify
our frame pointer in here so we
might as well save it.
So here we're going to set the frame
pointer to what a frame pointer is
supposed to be.
So
it's going to be the stack pointer
plus four.
And then we'll allocate some
speakers on the stack.
We'll allocate
10 on there
and then for the scan,
if we're going to actually
use the frame pointer in order
to point to some memory, so
the place that we need to store that
is going to be in our one because
we're going to make a function call
to scan.
So we
will 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 first ganef.
So we have R zero is the
pointer to where we're going to
store the data as per input
and then we need to use our one.
So are zero to point to
this format string, so
we'll get that input.
And then we'll call of the
to think to Toscana.
So I'll put a comment here,
read first.
No, OK,
so once we've read it now, Frame
Poinar 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 our zero,
the value at Frame Poinar
minus.
Sorry, no minus
eight,
so that allowed the value that we
read in from the user.
We they need to load the address
that we want to save that, so we're
going to save that into a.
OK, and then
we need to save the data, so a store
register, we're going to start our
zero into the location at
R-1.
So now we've just saved our value
for a.
And then.
We want to load these into
the vector registers, so we'll do
Eldard are
zero,
the address of a.
And then we use the LDA R
d, so it's going to load two
registers R to
the value at R
zero. So we got the address
and then we go ahead and
load that into our two and R
three.
And then when we do a vector move.
We're going to move a 32 bit integer
from S Z into
zero from R to and slide
a load R two and R three,
and then because I'm going to do
larger multiplication,
I will go ahead and.
Set as one.
To the value of zero,
so this will clear out basically
it all set that data into
zero.
Expanding those registers here, we
did a zero fill, which is
probably the best thing to do.
So then what we need to do is we
need to load the second number.
So once again, we need to
set our registers like we did here,
so I'm going to copy this y
y sorry,
y three y we'll copy
three lines in eye.
And if I do a P four
put, it'll copy those three lines.
So we're going to 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 and to be
so go ahead and load our register,
we load the location of B
into our one, and then we're going
to store our zero back into
our one.
And our SCANA was the same.
So there's no difference there.
All right, so now we need to
go ahead and load our our values
so they are
our zero.
We're going to let it be
eldard D to
loaded word R to
value at R zero.
B move
just floating integers so integer
thirty to s
to
our to side
a letter to in our three and to s
to.
And then set aside three
to the number zero,
so here we are.
Setting the
one.
With B,
I should put up here, this is B,
this is A so got A and we got B.
So we have zero and
Daewon and we're going to
go ahead and multiply those
together.
So we can use the VML
32.
To multiply
and save. So we're going to save the
result, and two, we're going to
multiply D one and
zero, so D one and zero will get
multiplied together.
The result to get stored in D
two.
And so then we can go ahead and try
and save that to see so
they can load register
R zero
C and then
to save it into that we have to do
the V store register.
So the store register D
to enter the
value at R zero.
So now we've saved it to see.
The last thing we want to do is we
want to print it off
or put a comment.
So the last thing to do is print so
we can go ahead and register our
zero,
the pointer to see.
Helda are our
one by zero.
And then we'll look at our own
type of their.
So we'll load up,
load, register
our zero, the
output string,
and then we're going to link
print F.
So this a load that into our
one, so we're just going to load a
thirty two bit integer from.
From sea, because that's what we
define see as and here we did
the store to save to it.
So here's our print off.
And then at the end, to
fix the stack, because we did
do some modification, we can say sub
S.P., F.P.,
the number four.
So we had
added to the frame pointer for Bitts
at the very top.
And so we can subtract from
the frame pointer to restore the
stack to where it was.
So we can just do that and then
ARTPOP should work.
And I have a typo here, so
line 46, helpful hint
and visit Colen,
the line number you want to go to.
I'll go right there.
So it should be VML
I 30 to.
You know, I think I
put the wrong character there that
should be equal zero.
Here we go.
Now, one thing that I did do in the
make files.
So because we're using
the FPU, we need
to tell Jack what type of
instructions to generate for that so
we use them minus M FPU
equals neon dash
VFP v4.
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 specification that you can
compile it to swear
that that ball to the assemble
command and the
command and you can see it when I
write, when I can make
that it's using those options.
So that was modified.
So that way it'll 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
unregister is for some inner energy
operations, we also
use printf and scan
in arm.
And so in the future, we'll look at
floating point in neon and then ACMD
in neon.
If you have questions, you can
contact me, Miller aimed at you in
Kadiatu and you can find me on
Twitter at know how sturdy.