Hello, this is Dr. Miller and this
is Episode ten point two of
Assembly.
Today, we're going to
create an example using an array.
So here's our example,
so what's our problem to solve?
So what we want to do is we want to
retain a list of numbers.
We will then want to add all of
those numbers together and then
print the sum and we'll 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 way.
So I'll just call it A
and then we're going to read in
all the values.
And so we'll go ahead and use ready
to reserve a bunch of D words,
actually allocate five of them.
All right. So the first thing that
we want to do is we're going to
probably use a loop in order to go
through and read these five numbers.
So we'll go ahead and move into X,
the number five, which is how many
elements are going to be in our
array. We're going to use Ebix for
our offset.
We'll start that off at zero and
then we're going to use a loop, so
we'll call this our read loop
at the bottom, we're going to loop
to read.
All right. So what we'll want to do
is we'll want to call,
read, end
to read an integer that will store
it in X
and then we can go ahead and copy
X into our array.
So we're going to move
our is called A and then
our offset is Ebe X
and then the value we're going to
copy in there is X,
so go ahead and copy the value of
VACC into our array
and then each time through.
So just got to double check.
We're using Ebix for our
offset and each time we need
to add the appropriate amount to the
offset. So here we're using these
words and each word is four bytes.
So we'll go ahead and add to SBX
for each time through the loop.
So now we need to sum all of our
numbers together.
So we've read them all into our ray.
We've stored them and now we want
to go ahead in some
them. So, again, we're going to
we're going to use a
loop here and we'll use X,
so we'll go ahead and move into X
then. Number five.
And then what we want to do is we
want to load the values,
so
we will do that inside of our loop.
We'll have to figure out what the
offset is.
Some move into IDEX,
the offset which we're going to
set at zero.
And we'll go ahead and call this our
summary, so we're going to loop
to some and this
will be some.
We also want to use a variable
in order to store the sun, so we'll
just go ahead and use X,
so we'll set to zero.
All right, so there's
a couple of different ways we could
do this. I'll show you the first way
so we could just add into Yak's
and then we need to grab our
array A plus
our offset, which is
IDEX.
We could add that directly or
we could use
this. We could move
into SBX that
value.
And then add yak's
and SBX.
And then each time through,
we need to increment
our offset.
So we are using IDEX as
our offset, so we need to add
for each time we do
that and then
our goal was to print off the sum.
So we'll go ahead and use printf.
So the first thing that we
want to do is maybe define our
format.
This is
and will use Precent D
terminate our format,
which again is a string, which is an
array, and we talked about how that
should be terminated by zero.
We also want to we're going
to use printf.
So we want to say X
turn print
F.
And then inside of here, we will go
ahead and push.
So that was our son that we had to
push our format,
call Prenter,
because we that's what we want to
function. We want to call.
And we have to correct our STAC.
So ad for the E.S.P.
I'm sorry, eight
push on two parameters, not just
one.
All right, let's see if this works.
All right, so play into the numbers.
One through five, we got 15.
Let's make one small correction,
let's put a new line in here.
So that way it prints that off.
One, two, three, four or five.
And if you add 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
and then called our print
function.
So looking forward, we'll talk about
string operations and different
functions that you can run on
string's.
If you have questions, you can email
me Miller, MJ at you in KSTU
and you can find me on Twitter at
Milhouse 30.