13 hours 15 minutes
Hello. This is Dr Miller, and this is Episode 10.2 of Assembly.
Today, we're going to
create an example using an array.
So here's our array example.
So what's our problem to solve? So what we want to do is we want to read in a list of numbers. We will then want to add all those numbers together and then print the sun
and will do all of these operations using an array.
All right, so
I've already created my project, and I'm editing that project.
So the first thing we need to do is define our ray.
So I'll just call it a
and then we're going to write, read in all the values. And so we'll go ahead and use reds D to reserve a bunch of the words,
actually allocate five of them.
All right, So the first thing that we want to do is we're gonna probably use a loop in order to go through and read these five numbers so we'll go ahead and move into easy X,
the number five, which is how many elements are going to be in our ray. We're going to use e b X for offset
we'll start that off zero and then we're going to use a loop, so we'll call this. I read loop
at the bottom. We're going to loop to read.
All right, So what will want to do is we'll want to call
read int to read and manager that'll store it in E. X,
and then we can go ahead and copy E X into our array. So we're going to move
our raise, called a and then are offset is E V X,
and then the value we're gonna copy in there is E X.
So go ahead and copy the value of V A X into our array
and then each time through, So
he's got a double check here. We're using EBX for our
offset, and each time we need to add the appropriate amount to be offset. So here we're using the words, and each D word is four bites. So we'll go ahead and add to e v X
for each time through the loop.
So now we need Teoh some all of our numbers together. So we've read them all into our ray.
We stored them and now we want to go ahead and some them. So again, we're gonna We're gonna use a,
loop here and will you zc x So we'll go ahead and move into E c X the number five.
And then what we want to do is we want to load the value. So,
we will do that inside of our loop will have to figure out what the offset is. So move into E d. X,
the offset which we're going to set at zero,
and we'll go ahead and call this our summer rain. So we're going toe loop
then this will be some
We also we want to use a variable in order to store the sun so we'll just go ahead and use e X.
Little said Ta x 20
so there's a couple different ways we could do this. I'll show you the first way so we could just add into yea X, and then we need to grab our ray a
plus our offset, which is e d x.
We could add that directly, or we could use
this. We could move into db x that value
and then add yea x and ebx
and then each time through, we need to increment our
So we're using e d X as are offset. So we need to add for each time we do that.
And then our goal was to print off the some
So we'll go ahead and use print F.
So the first thing that we want to do is maybe define our format
is and will use percent de
terminate our format, which again is a string which is an array. And we talked about how that should be terminated by zero.
Ah, we also want to We're going to use print f so we want to say X turn
and then inside of here we will go ahead.
Pushy x. So that was our some that we had push our format
call print F
That's what we went the function. We want to call that we had to correct our stack.
So add four tsp.
Eight. Push on two parameters, not just one.
All right, Let's see if this works.
All right. So, flying to the numbers
1 to 5, we got 15. Let's make one small correction.
Let's put ah, new line in here
so that way it prints that off.
12345 And if you had those all together, you should get the number 15.
So today we gave an example using an array we went through and loaded values into the array. And then we also read values from that array,
um, and then called our printout function.
So looking forward, we'll talk about string operations and different functions that you can run on strings.
If you have questions, you can email me Miller MJ at you and Kate I e to you. 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