13 hours 15 minutes
Hello. This is Dr Miller, and this is Episode 8.2 of Assembly.
Today, we're going to write a program using floating point numbers.
So here is our program description. So we're gonna write a program to calculate the following
the area of a circle which is pi r squared and the circumference of a circle, and then we'll have the user into those values.
Alright, So I've already created the directory.
So the top, we're gonna do our definitions. And so we got a few definitions we're gonna have toe put in here.
So, for example, all enter pie,
so we'll define it is a cue word because I don't give us more precision.
I give some example. Digits, you can do some. Or if you'd like to do this on your own,
we're gonna have X, which is a value that these is gonna enter. We'll start that off zero, and that will be an imager.
that is going to be a floating point number so we'll define it is a cured so that it has 64 bits.
Here's our circle or circumference.
Go ahead and to find that is also a cured zero,
and then I'm just gonna to find the number two.
We'll use that later.
All right? And then we got a couple different formats. So one is for scan F.
So I find this bites
and then are printed format
and then percent f is the
formats specify air for printing off a floating point number.
Here. We had 10 for a new line and then zero.
We got a couple externals
All right, so now we're ready to go into our program. So first off, I have to have to add the pointer
to the scan of format. So that is I'm gonna push X for the hat,
push our format and then call
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 our might be a better term, but I'm using X.
So because we pushed to things, we have to correct a stack.
Okay, Now, put a comment here, so we know.
Next step is to load our data onto the floating point stack. So the first thing that I'm gonna do is I'm gonna go ahead and load
So, Ethel de Floating Point load, This is a que
word and I'm gonna load pie.
And then I want to multiply that by X. But X isn't manager, so f I and mole. It's a floating point imager. Mole,
We're using a D word for X,
so I'm pi times are times are so just go ahead and multiply again.
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
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 store that in area
So I used pie here as
just a number that I typed in. But there is also a floating point load high which will actually load pie on top of the stack
the circumference is two pi r. So I've got pie, and I need to multiply that by two
So I have my number two.
Okay. And then I need to multiply that by X, which is our radius.
That's also on you, ***.
And then I need to
Here we are
doing that calculation,
and then we need to store that. So we want to floating points
store and pop.
It's a cue word,
and they're just telling how big. So that way it knows what to write.
All right, so now comes the fun part of
trying to print these off. So because these are Q words, I have to basically push two things onto the stack.
So we're gonna do printing here.
So with this, we need to I'm gonna move into the A X
value at circumference
***. I'll get me
four of the bites and then I can push that onto the stack,
and then I need to
move into yea x,
the value. It's a conference. So I gets me the other four bites.
I don't have to push that on in the stack.
So here we're loading
and now we want to do the same thing for the area. So remember, we have to do them reverse orders. That's why we did circumference. First
movie X area, close four.
Push the axe,
without you it area,
push the X
And then we're gonna have to
push our format.
And it's called P for friends.
And then we're gonna call print F.
Now, if we go back, we're going to count how many things we pushed on the stack for this printing. So we got
one. So 48 12
16. And I missed my ex here.
in decimal, which is 10. And hex right here and then 14. Hicks. So to correct a stack, we have to do ad
14. Add two tsp 14 hex.
And so that's your correct a stack for all the things we
pushed on the stack for our printing.
Looks like I have an air. So let's go and fix that
Parents post some letters there,
and we messed one of them up. Okay, so it says area is zero conference is 6200
so let's go back in. Double check. So
ah, floating point store. Sea area.
That would be a cue word.
There we go.
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 air on
and go and see what operation? That you might have missed type so we could see that I had a typo. I've had a couple typos.
Um, but going through, at least the assembly will tell you that there is an air, and then he can go back and figure out where that air exists.
So today we built our example program. And then you saw that that was used in order to
demonstrate how we can load of floating point numbers. And then now we can print those off.
So in the future, we're gonna 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 you indicated I e d u and on Twitter at no house. 30
How to Use GDB (BSWJ)
The GNU Debugger (GDB) is one of the most commonly-used debugging tools in the world. ...
Certificate of Completion Offered
How to Use IDA (BSWJ)
The IDA is used throughout the IT and cybersecurity industries by exploit developers, vulnerability analysts, ...
Certificate of Completion Offered