Floating Point Circle 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 »

Course
Time
13 hours 15 minutes
Difficulty
Beginner
CEU/CPE
14
Video Transcription
00:01
Hello. This is Dr Miller, and this is Episode 8.2 of Assembly.
00:05
Today, we're going to write a program using floating point numbers.
00:10
So here is our program description. So we're gonna write a program to calculate the following
00:15
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.
00:26
Alright, So I've already created the directory.
00:29
So the top, we're gonna do our definitions. And so we got a few definitions we're gonna have toe put in here.
00:36
So, for example, all enter pie,
00:43
so we'll define it is a cue word because I don't give us more precision.
00:53
Six.
00:55
I give some example. Digits, you can do some. Or if you'd like to do this on your own,
01:00
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.
01:08
The area
01:11
that is going to be a floating point number so we'll define it is a cured so that it has 64 bits.
01:22
Here's our circle or circumference.
01:26
Go ahead and to find that is also a cured zero,
01:30
and then I'm just gonna to find the number two.
01:34
We'll use that later.
01:38
All right? And then we got a couple different formats. So one is for scan F.
01:45
So I find this bites
01:53
and then are printed format
02:06
and then percent f is the
02:09
formats specify air for printing off a floating point number.
02:14
Here. We had 10 for a new line and then zero.
02:20
We got a couple externals
02:23
scan, huh,
02:25
friend?
02:30
Yes.
02:31
All right, so now we're ready to go into our program. So first off, I have to have to add the pointer
02:38
to the scan of format. So that is I'm gonna push X for the hat,
02:47
push our format and then call
02:51
scan of
02:53
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.
03:07
So because we pushed to things, we have to correct a stack.
03:13
Okay, Now, put a comment here, so we know.
03:20
All right.
03:22
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
03:30
pie.
03:32
So, Ethel de Floating Point load, This is a que
03:37
word and I'm gonna load pie.
03:43
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,
03:53
We're using a D word for X,
03:57
so I'm pi times are times are so just go ahead and multiply again.
04:03
Okay,
04:05
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.
04:15
And so this is calculating my
04:17
area.
04:19
So now I need to save that
04:21
floating point store and then p is for Pop because I don't want that to stay on the stack,
04:30
go ahead and store that in area
04:34
and then
04:35
So I used pie here as
04:39
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
04:49
and then
04:50
so the
04:53
the circumference is two pi r. So I've got pie, and I need to multiply that by two
05:00
So I have my number two.
05:03
Okay. And then I need to multiply that by X, which is our radius.
05:10
That's also on you, ***.
05:15
And then I need to
05:18
Here we are
05:26
doing that calculation,
05:29
and then we need to store that. So we want to floating points
05:33
store and pop.
05:36
It's a cue word,
05:41
and they're just telling how big. So that way it knows what to write.
05:45
This is
05:46
circumference.
05:48
All right, so now comes the fun part of
05:50
trying to print these off. So because these are Q words, I have to basically push two things onto the stack.
05:59
So we're gonna do printing here.
06:02
So with this, we need to I'm gonna move into the A X
06:08
value at circumference
06:11
plus four.
06:13
***. I'll get me
06:15
four of the bites and then I can push that onto the stack,
06:18
and then I need to
06:20
move into yea x,
06:24
the value. It's a conference. So I gets me the other four bites.
06:29
I don't have to push that on in the stack.
06:33
So here we're loading
06:36
circumference,
06:39
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
06:45
movie X area, close four.
06:50
Push the axe,
06:53
move yaks
06:55
area
06:57
without you it area,
07:00
push the X
07:01
And then we're gonna have to
07:03
push our format.
07:08
And it's called P for friends.
07:12
And then we're gonna call print F.
07:16
Now, if we go back, we're going to count how many things we pushed on the stack for this printing. So we got
07:21
one. So 48 12
07:27
16. And I missed my ex here.
07:31
16
07:33
in decimal, which is 10. And hex right here and then 14. Hicks. So to correct a stack, we have to do ad
07:43
14. Add two tsp 14 hex.
07:48
And so that's your correct a stack for all the things we
07:51
pushed on the stack for our printing.
08:01
Looks like I have an air. So let's go and fix that
08:09
loading point.
08:13
Parents post some letters there,
08:22
and we messed one of them up. Okay, so it says area is zero conference is 6200
08:31
so let's go back in. Double check. So
08:46
ah, floating point store. Sea area.
08:52
That would be a cue word.
08:56
There we go.
09:01
All right. So it looks like we got the right results.
09:09
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
09:16
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.
09:24
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.
09:35
So today we built our example program. And then you saw that that was used in order to
09:43
demonstrate how we can load of floating point numbers. And then now we can print those off.
09:48
So in the future, we're gonna talk about conditions. So making decisions based on floating point numbers.
09:54
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
Up Next