Hello, this is Dr. Miller, and this
is Episode eight point two of
Assembly
today we're going to write a program
using floating point numbers.
So here is our program description,
so we're going to write a program to
calculate the following,
the area of a circle, which is PI
squared and the circumference of a
circle, and then we'll have the user
enter those values.
All right, so I've already created
the directory, so
at the top, we're going to do our
definitions and so we've got a few
definitions that we're going to have
to put in here.
So, for example, I'll enter pie.
So we'll define it as a key word,
because that'll give us more
precision.
Six.
I gave some example digits,
you can do some more if you'd like
to do this on your own.
We're going to have X, which is a
value that these are going to enter
and we'll start that off at zero
and that'll be an integer.
The area
that is going to be a floating
point numbers. So we'll define it as
a keyword so that it has 64
bits.
Here's our circle or circumference.
Go ahead and find that is also a key
word, zero,
and then I'm just going to define
the number two, we'll
use that later.
All right. And then we've got a
couple of different formats.
So one is first ganef.
So the finest bites.
And then our print format.
And then F is
the format specified
for printing off
a floating point number here,
we had 10 for our new line
and then zero,
we got a couple of externals.
SCANA.
Parent
Beth.
All right, so now we're ready to
go into our program.
So, first off, I have to I have
to add the pointer to
the scanner format.
So that is I'm going to push X
for that.
Pusha format and then call
scan if
and then after that, X
should have the value that we
care about.
So that's the number that we're
going to use for our radius.
I guess R might be a better term,
but I'm using X,
so because we push two things, we
have to correct the stack.
OK, now put a comment here
so we know.
All right, next
step is to load our
data onto the floating point stack,
so the first thing that I'm going to
do is I'm going to go ahead and load
PI.
So I thought the floating point
load, this is a cue
word and I'm going to load
PAE.
And then I want to multiply
that by X, but X is an integer,
so F I am
more so floating point integer
ml
we're using a D word for X,
so I'm pi.
Times are, times are.
So I'll just go ahead and multiply
again.
OK, so now I
have my result, it should be on top
of the stack, so I took
pie and then I multiplied it and it
replaced that on top of the stack.
And so this is calculating my
area.
So now I need to save that floating
point store and then P
is for Pop because I don't
want that to stay on the stack.
Go ahead and draw that in area
and then so I used pie
here as
just a number that I typed in,
but there is also a
floating point load
pie which will actually load pie
on top of the stack.
And then so
the the circumference
is to pie are so I've got pie
and I need to multiply that by two.
So I have my number two,
OK, and then I need to multiply that
by X, which
is our radius.
That's also an integer.
And then I need to
know, here we are.
Doing that calculation
and then we need to store that.
So we went to a floating point
store and pop.
It's a key word.
And they're just telling it how big,
so that way it knows what to write.
And this is circumference.
All right, so now comes the fun part
of trying to print
these off. So because these are cute
words, I have to basically push two
things onto the stack.
So we're going to do printing here.
So with this, we need to
I'm going to move into X
value at circumference
plus four
so that get me.
Four of the bites and then I can
push that onto the stack
and then I need to
move into X
value at circumference, so I get
me the other four bites
and I have to push that onto the
stack.
So here we're loading
circumference and
now we want to do the same thing for
the area, so remember, we have to do
them a reverse order.
So that's why we did circumference
first.
Yak's area
was for
pushbacks,
yak's
area, valuate
area pushbacks.
And then we're going to have to
push our format.
And it's called P for
Perens
and then we're going to call PRAnd.
Now, if we go back, we're going to
have to count how many things we
pushed on the stack for this
printing. So we got one,
four, eight, 12,
16.
I missed my X here.
16 in
decimal, which is 10 and Hex
right here and then 14
hex, so to correct the stack,
we have to do add
14, add to E.S.P
14 hex.
And so that's a correct to stack for
all the things that we pushed
on the stack for our printing.
And it looks like I have an error,
so let's go and fix that.
Floating point
parents put some letters their.
And we messed one of them up, OK?
So it says the area is zero,
circumference is 60,
200.
So let's go back and double check,
so.
Oh, floating point or
C area.
That should be a cue word.
Marigot.
All right, so it looks like we got
the right results.
So as you can see, some of the
debugging steps you have to go
through and figure out which line
you might have an error on and
go and see what operation
that you might have missed.
So we could see that I had a typo.
I've had a couple of typos,
but going through at least December
will tell you that there is an error
and then you can go back and figure
out where that error exists.
So today, we built our example
program and then you saw that that
was used in order to
demonstrate how we can load a
floating point numbers and then now
we can print those off.
So in the future, we're going to
talk about conditions.
So making decisions based on
floating point numbers.
If you have questions, you can
contact me via email
at Miller, MJ, at Uncrated Edu
and on Twitter at know how sturdy.