Arrays Examples

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 10.2 of Assembly.
00:07
Today, we're going to
00:08
create an example using an array.
00:12
So here's our array example.
00:14
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
00:22
and will do all of these operations using an array.
00:29
All right, so
00:30
I've already created my project, and I'm editing that project.
00:34
So the first thing we need to do is define our ray.
00:37
So I'll just call it a
00:40
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,
00:47
actually allocate five of them.
00:51
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,
01:00
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
01:07
we'll start that off zero and then we're going to use a loop, so we'll call this. I read loop
01:12
at the bottom. We're going to loop to read.
01:18
All right, So what will want to do is we'll want to call
01:22
read int to read and manager that'll store it in E. X,
01:27
and then we can go ahead and copy E X into our array. So we're going to move
01:34
our raise, called a and then are offset is E V X,
01:40
and then the value we're gonna copy in there is E X.
01:42
So go ahead and copy the value of V A X into our array
01:48
and then each time through, So
01:49
he's got a double check here. We're using EBX for our
01:53
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
02:04
for each time through the loop.
02:07
So now we need Teoh some all of our numbers together. So we've read them all into our ray.
02:13
We stored them and now we want to go ahead and some them. So again, we're gonna We're gonna use a,
02:21
um,
02:22
loop here and will you zc x So we'll go ahead and move into E c X the number five.
02:29
And then what we want to do is we want to load the value. So,
02:34
um,
02:35
we will do that inside of our loop will have to figure out what the offset is. So move into E d. X,
02:42
the offset which we're going to set at zero,
02:54
and we'll go ahead and call this our summer rain. So we're going toe loop
03:00
to some,
03:01
then this will be some
03:07
We also we want to use a variable in order to store the sun so we'll just go ahead and use e X.
03:13
Little said Ta x 20
03:24
All right,
03:27
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
03:36
plus our offset, which is e d x.
03:40
We could add that directly, or we could use
03:45
this. We could move into db x that value
03:53
and then add yea x and ebx
04:00
and then each time through, we need to increment our
04:08
offset.
04:12
So we're using e d X as are offset. So we need to add for each time we do that.
04:19
And then our goal was to print off the some
04:23
So we'll go ahead and use print F.
04:26
So the first thing that we want to do is maybe define our format
04:32
is and will use percent de
04:39
terminate our format, which again is a string which is an array. And we talked about how that should be terminated by zero.
04:46
Ah, we also want to We're going to use print f so we want to say X turn
04:54
print out
04:56
and then inside of here we will go ahead.
04:59
Pushy x. So that was our some that we had push our format
05:04
call print F
05:06
That's what we went the function. We want to call that we had to correct our stack.
05:13
So add four tsp.
05:15
Oh, sorry.
05:16
Eight. Push on two parameters, not just one.
05:21
All right, Let's see if this works.
05:27
All right. So, flying to the numbers
05:31
1 to 5, we got 15. Let's make one small correction.
05:35
Let's put ah, new line in here
05:40
so that way it prints that off.
05:45
12345 And if you had those all together, you should get the number 15.
05:54
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,
06:01
um, and then called our printout function.
06:05
So looking forward, we'll talk about string operations and different functions that you can run on strings.
06:13
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.
Up Next