Hello, this is Dr. Miller, and this
is Episode three point two 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 X register
to implicitly multiply
and then we modify both X
and Ed X,
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 genomic data, S.H.,
and the name of my project is going
to be the lecture for today.
So three point two.
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 three point two directly.
All right, so we don't have anything
inside of here, so we're going to go
ahead and.
At our code,
so we know we want to read a number
from the user so we can use a
function called Read Int.
That'll read a number and store it
inside of Yak's, so
we're going to want to move it to
another register because when we
call read it again, it will
also store it in X.
So I'll go ahead and copy it to SBX,
so now I have one number in SBX.
Now I have my second number, an X,
and so we want to use them all
so we can save more
SBX and that will multiply SBX
times X and then store
the result in an X.
And so if I want to go ahead and
print off that result,
well, it's already stored in X,
so I can say call print
and that'll put my number
and then I'll put a new line.
In there, so I'm in insert
mode, go ahead and hit escape Kolan
WQ.
I can make so
it built my project and go ahead and
run it.
So now it wants me to enter a
number, so I'll pick
numbers I know 15
times to give
me the number 30 or
20
times a hundred
and give me 20.
All right, so that was our example
on how to read in the two numbers,
multiply them and then print the
result.
Now for division.
So again, we have some implicit
registers. So we typically
use X and X if
we're doing long
division with possibly sixty
four bit numbers.
And so then it'll modify X
and as a result.
So we're going to go ahead and read
our two numbers, divide them and
then go ahead and print the
remainder and the quotient.
I 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 X.
Read the next number.
Now we have one in E, X
and we have one in Ebix, and
so we're going to end up dividing
the second number by the first one
and then we'll print off the
remainder and the result.
So we'll go ahead and do div
SBX
and then what's in X
should be our
number of times. It goes into it.
So our quotient.
I go ahead and print a new line
so we can see the difference
and then we have the result in
edits of the remainder,
so go ahead and move that back to
yak's.
Print are integer.
Print our new line.
Can take.
All right.
So go ahead and run our program.
So if I take
10.
Three, that gives me a floating
point, and if I take three,
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, otherwise we'll get a
floating point air.
So move IDEX
zero.
All right, go ahead and
run, make build
our project,
run our example.
So three goes into ten, three
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 the user and
then go ahead and print off those
results.
Also, we see the common error that
most students have is they forgot to
zero out edicts and thus the
result causes a crash.
So in future elections, we're going
to look at doing comparison
and conditionals and then looping,
if you have questions, you can
e-mail me at Miller, MJ, at you and
Keda, Aidoo, and you can find
me on Twitter at Milhouse 30.