### Video Transcription

00:01

Hello. This is Dr Miller, and this is Episode 3.2 of Assembly.

00:07

Today we're going to show some examples of how to do multiplication and division.

00:13

Here's the example for multiplication.

00:16

So we should know from previous lectures that when we do a multiplication, we use the a X register

00:22

to implicitly multiply, and then we modify both DX and dy dx,

00:29

so we need a problem to solve. So here's our problem.

00:32

We want to read in two numbers and then multiply them and then print the result.

00:36

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.

00:45

And if you're back, here is the example that we're going to go through.

00:51

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.

01:03

So if I look, I have my projects directories go ahead and into that,

01:08

and now I'm going to go ahead and go into the 3.2 directory.

01:23

All right, so we don't have anything inside of here, so we're gonna go ahead and

01:30

at our code,

01:33

so we know we want to read it number from the user so we can use the function called Read end.

01:41

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.

01:49

It will also store it in the X.

01:53

So I go ahead and copy it to EBX. So now I have one number in EBX.

02:01

Now I have my second number and e X.

02:05

And so we want to use mall

02:07

so we can say mole

02:10

E b X, and that will multiply ebx times e X and then store the result in E, d, X and E X.

02:19

And so if I want to go ahead and print off

02:22

that result,

02:23

well, it's already stored in E. X. So I can say call print,

02:28

and

02:29

that would put my number. And then I'll put a new line

02:35

in there.

02:36

Simon insert mode. Go ahead and escape Colon W Q.

02:42

I could run make. So it built my project and go ahead and run it

02:51

so Now, I wants me to enter a number,

02:53

so I'll pick numbers. I know 15 times two,

02:58

give me the number 30 or

03:00

20

03:02

times. 100.

03:05

Give me 2000.

03:09

All right, so that was our example on how to read in the two numbers multiply and then print the result

03:16

now for division.

03:19

So again, we have some implicit registers. So we typically use E x and E d. X if we're doing,

03:25

um, long division with possibly 64 bit numbers,

03:30

and so then it will modify E x and E d. X as a result.

03:36

So we're gonna go ahead and read our two numbers, divide them, and then go ahead and print the remainder and the question

03:46

I'll go ahead and make another project.

04:08

All right, So what we want to do here is we want to read our numbers

04:15

again. This will read it into the a X,

04:23

read the next number.

04:28

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

04:41

e b x

04:43

And then what's in E X should be our number of times It goes into it.

04:48

So our quotient

04:55

go ahead and print a new line

04:58

so we can see the difference.

05:00

And then we have the result in E D. X of the remainder. So go ahead and move that back TX

05:11

print are integer

05:15

print on new line

05:18

Pregnant.

05:20

All right,

05:26

go ahead and run our program.

05:30

So if I take

05:31

10

05:34

three, that gives me a floating point And if I take 3 10 that also gives me a floating point.

05:43

So if you recall when you're ready to do division,

05:46

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

05:58

All right,

06:00

run, run! Make

06:01

build our project

06:03

Run our example.

06:11

So three goes into 10 3 times and then has a remainder one.

06:20

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

06:38

causes a crash.

06:40

So in future elections, we're going to look at doing comparison and condition ALS and then looping.

06:47

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.

### Up Next

### Assembly

This course will provide background and information related to programming in assembly. Assembly is the lowest level programming language which is useful in reverse engineering and malware analysis.

### Instructed By

Matthew Miller

Instructor