Hello, this is Dr. Miller, and this
is Episode twelve point four of
Assembly
today we're going to give a floating
point example.
So what's our problem to be solved?
So we're going to read a radius from
the user and then we'll go ahead and
calculate and print the area.
And what we'll do is we'll end up
using neon instructions for that.
So I already got the project set up.
So we're going to have a couple of
messages here.
So ask them, enter the
radius.
We will have to scan the number
from the user, so use percent F.
And then we'll print off our result
area.
And we'll put a new line in here, so
it's nice for the user.
So up here, we won't put a new line
because these are all type something
and then they'll hit enter.
So we might as well make it look
nice and then we'll declare
a variable. So we'll declare pi.
And I don't believe that.
That will be
three point one four
one five
nine two
six five.
Three five nine, so I'm
going to use a double here so that
we get a little bit more accuracy.
So let's set up our stack.
So we got our frame pointer and our
link register.
And we'll go ahead and
set up the stack.
We'll subtract some for
here, just pick a number
when we go to restore, we're going
to do sub SPF
P.
And number four, because we
added so we do subtract.
So now we'll go ahead and print off
our result, they are zero.
Get our first format.
When print off and hear, let's
declare our
functions that we're going to use.
We're going to have an SCANA, so we
printed off our question for the
user and then we're going to
go ahead and load it.
So Sub R
one is where we're going to use it.
It's going to be our pointer
subframe pointer
and then minus eight.
So the number eight.
So that's where the data is located.
We'll do ldi r r
zero
format A, which is our scan
F, we'll go ahead and call Branch
Hotlinks ganef.
And then so now we've got our result
in there.
And so what we want to do is we want
to copy it out.
So Vector
are
we'll just pick a register.
So I'm going to pick S 15
and we're going to get the value at
the frame pointer
minus the number eight.
And the way ARM does
it, you have to put the hash tag
here to tell that it's a number.
So we're going to frame Poinar minus
eight and then when we
use we convert
into a floating point
sixty four from
a floating point thirty two
into D seven.
And we're going to use as 15.
All right.
And then what we want
to do is we're going to have to do
our multiplication, so that's going
to give us our radius, which is
indeed seven, we can go ahead and
square that so we can say the more
a 64 bit
floating point.
I mean, just say seven is
D seven times D seven.
And so that's an easy way to square
something.
And then we're going to want to go
ahead and load our value for PI in.
So Eldard are zero.
The address of pi
ilda the r d
r to
evaluate R zero.
So again
our two and
R three are going to be loaded,
so we don't forget that and then
we can convert that into
a 64 bit.
So we're going to use the B
move because
they're in our two in our three
floating point sixty four
and two. We'll use the eight.
And we're going to load our two
and our three little copy
those into that register.
We can now multiply
our things together, so we got
diet has pie and D7
has the value squared so
that the more
we're going to do floating point
sixty four
to seven is our restaurant
and we're going to multiplied seven
times the eight.
So now they're multiplied and stored
in these seven.
So again, we can use move.
And so one of the things to
understand is that
when printf is going to print it,
it's going to actually just use R to
an R three and we won't use our one
because our first value is a
double and so it's not going to use
it. So when we do our V move,
we're going to move R to
into our two and our three
the value that's in D seven
to copy it to those two registers.
We're not going to set our zero, but
we will set our one.
Sorry, we're not going to set our
one, but we will set our zero
to low to register our zero.
We'll get our format that we want to
print. So it's format
B
and then we'll go ahead and call
print F
branch link
and then we're at the bottom of our
function. So let's try
this.
And it looks like I had
a typo, which nobody could tell me
about, so
I mistype scan F.
I we go.
And I think I mistyped format
here.
All right,
so far, radius is 10, 10 times,
ten is 100,
100 times, pi is three
hundred and fourteen.
All right, so we gave an example
using floating point, so we did some
loading of registers, we did some
reading from Scanner F and we also
did some printing with print F.
So in the future, we'll talk about
ACMD and then
thumbhole and conditional execution.
If you have questions, you can email
me Miller, MJ at you, Ankita, Edu
and you can find me on Twitter at
has 30.