13 hours 15 minutes
Hello. This is Dr Miller, and this is Episode 3.2 of Assembly.
Today we're going to show some examples of how to do multiplication and division.
Here's the example for multiplication.
So we should know from previous lectures that when we do a multiplication, we use the a X register
to implicitly multiply, and then we modify both DX and dy dx,
so we need a problem to solve. So here's our problem.
We want to read in two numbers and then multiply them and then print the result.
If you think you know how to solve it, go ahead and pause the lecture and do it on your own and see if you got the right result.
And if you're back, here is the example that we're going to go through.
So I'll start off by creating a new project. So I use gen make dot s h. And the name of my project is gonna be the lecture for today. So 3.2.
So if I look, I have my projects directories go ahead and into that,
and now I'm going to go ahead and go into the 3.2 directory.
All right, so we don't have anything inside of here, so we're gonna go ahead and
at our code,
so we know we want to read it number from the user so we can use the function called Read end.
That'll read a number and stored inside of e X. So we're gonna want to move it to another register, because when we call, read it again.
It will also store it in the X.
So I go ahead and copy it to EBX. So now I have one number in EBX.
Now I have my second number and e X.
And so we want to use mall
so we can say mole
E b X, and that will multiply ebx times e X and then store the result in E, d, X and E X.
And so if I want to go ahead and print off
well, it's already stored in E. X. So I can say call print,
that would put my number. And then I'll put a new line
Simon insert mode. Go ahead and escape Colon W Q.
I could run make. So it built my project and go ahead and run it
so Now, I wants me to enter a number,
so I'll pick numbers. I know 15 times two,
give me the number 30 or
Give me 2000.
All right, so that was our example on how to read in the two numbers multiply and then print the result
now for division.
So again, we have some implicit registers. So we typically use E x and E d. X if we're doing,
um, long division with possibly 64 bit numbers,
and so then it will modify E x and E d. X as a result.
So we're gonna go ahead and read our two numbers, divide them, and then go ahead and print the remainder and the question
I'll go ahead and make another project.
All right, So what we want to do here is we want to read our numbers
again. This will read it into the a X,
read the next number.
Now we have one in E x, and we have one in e v X. And so we're gonna end up dividing the second number by the 1st 1 and then we'll print off the remainder in the results, so we'll go ahead and do dio
e b x
And then what's in E X should be our number of times It goes into it.
So our quotient
go ahead and print a new line
so we can see the difference.
And then we have the result in E D. X of the remainder. So go ahead and move that back TX
print are integer
print on new line
go ahead and run our program.
So if I take
three, that gives me a floating point And if I take 3 10 that also gives me a floating point.
So if you recall when you're ready to do division,
we have the problem of, we have to zero out e d. X. Otherwise we'll get a floating point air. So movie D X zero
run, run! Make
build our project
Run our example.
So three goes into 10 3 times and then has a remainder one.
So in this lecture we showed how to do multiplication and division some examples where we actually get some inputs from user and then go ahead and print off those results. Also, we see the common air that most students have as they forgot to zero out GDX and thus the result
causes a crash.
So in future elections, we're going to look at doing comparison and condition ALS and then looping.
If you have questions, you can email me at Miller MJ at you and Kate. I e d u. And you can find me on Twitter at Milhouse 30.
How to Use GDB (BSWJ)
In this part of the Breaking Stuff with Joe (BSWJ) series, Joe Perry demonstrates how ...
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