Hello, this is Dr. Miller and this
is Episode fourteen point 12
of Assembly.
Today, we're going to use assembly
and sea together,
so for this, we're going to use Dixy
and Nazem and so Nazeem
has the ability to generate object
files for us.
And then inside of our Nazeem code,
we're going to declare a function
and we'll make it global, which
means it'll be exported and usable
within GCC.
And then we can take as many
object files as we have
and it will create an output file.
And so when we give a list of them,
the last one is the one that has to
have the main method in it.
And then we have to also include a
function declaration.
And so this will allow us to
understand what
function exists, even though it
may not exist in the file that we're
using.
So when we get ready to compile,
we'll use the Nazeem minus F,
and so we're doing it on Linux.
So the output format is lf
we have our Assim file and then
generate this object file and
then with Jook we include that
object file before we include
our main file.
So what's our problem to be solved.
So what we're going to do is write a
string link function and so we're
going to college Len String
and we're going to create that in
our assembly file and then we'll
have the signature like this.
So it'll take a pointer to a
character and then a maximum
and it's going to return it int and
then we're going to use that
function inside of our C file.
All right, so what I'm going
to do is we're going to use this
assembly file.
But we're going to change our name,
so here the
function that we have is
one string.
Do it right.
OK.
And so the thing is going to be
our function that
we're going to create.
And so down here,
instead of this, we're going to say,
listen,
String,
and so I'm going to remove
some of this code here.
So, for example, my push my
a I'm going to get rid of those.
All right,
and so a couple of registers
I'm going to use, so I'm going to
use the string scanning function,
so go ahead and we're going to end
up using pushing Eddi
and X.
So at the end, I want to restore
those so pop acts,
Pop Eddi,
and we got our leaving a return at
the end.
OK,
so we're going
to use X or
we're going to use X for
this character that we're going to
scan for. So we're going to use the
S c Asabi
to scan for a bite.
So go ahead and move into X
zero, which is the character, the
null that we're going to search for,
and then we're going to move into
Eddi.
So we have a pointer as
the first argument.
And so we'll grab that from SBP
plus eight.
Remember that our entire set up, our
EBP stack,
we're going to move into X, so
our maximum or the maximum
that we're going to scan SBP
plus zero C.
We'll clear the direction flags so
we can use this
repeat, not equal,
and so what this will do is it's
going to keep going until
the equal flag gets set
with the command that follows.
And so we're going to use SC Aspy
to scan for a string byte
so that a bunch of different
string functions that we can use in
order to search for characters
because strings or something that
we're heavily used in assembly.
So they added a bunch of commands in
there.
And so when we get done with that,
the pointer of Eddi
is going to point to the location
where that character is.
And so we're going to reload
into DCX
the original location.
So that's going to be SBP
plus eight.
So that was our pointer that was on
the stack.
We're going to then move into X
Eddi so that we have
our current pointer.
We're going to subtract
X from X, so
we'll subtract the two pointers,
X being the smaller pointer,
X being the larger
one, and then we're going
to decrement X by one
because this is pointing to the
character. And so the length is
going to be that number minus one.
And so we have to subtract one from
it and then we have
our epilog of our function.
So now we're going to create our
C file.
And so
on call this may not see,
so we're going to do our standard
includes.
So standard input.
Standard lab
and the string library.
And then our function is called the
Lenn String,
it takes a character Pointer
C and A int
Max,
and we're just telling the compiler
that, by the way, we have a
function.
But here's our main.
Here, I'll define our size
for what we're going to do.
I'm going to use Mallick
in order to allocate myself a buffer
buffer.
Here, I'll do a cast, as we say,
this is a char pointer.
And we're allocate that many bites.
And then again and see, we're using
scan F.
I use the S
to search for a string
and I'm going to store that input.
And then I'm going to compare
our two strings, so and Len
is equal to
Sterling.
So this is the standard call.
And then we'll
get our call.
Ours is called lern
string,
and then I'm going to give it the
value of size so it has a maximum.
That was we ended up using an X
and then we'll go ahead and print
our result.
So I'll format it nicely,
so I got my first length,
I'll put my second link there
and then we'll put our string,
put a nice new line in there.
And give us our arguments.
OK, so now we
are going to want to compile them,
so say Nazan
minus F lf.
And then ours is 14,
12 and so on,
14 to 12 oh.
Oh, I need to give the minus.
Come in there
and then G, C, C
minus
and
30 to.
For Jean,
the oh and then maned
of C..
It looks like I have a syntax
error here.
In my cast.
And then let's see.
Our print f.
Oh, I forgot the D there.
All right.
And so then it scanned our string,
which was hello, and it has five
characters in it, so print it off
the Sterling version and
our version and so you can see that
we can easily
create a assembly
file
where we basically export
our function name,
and then we need to make sure that
we use our function arguments
appropriately.
So here I knew I had an eBay
stack, which is what Linux typically
uses, and so I could use EBP
plus eight and 12 is argument one
and argument two
for that.
And then we just ended up using
a string command that is
built into
eighty six assembly.
So today, we saw how we can use
assembly and see together
to use the best of both
worlds so that we can write
code in whichever language is the
easiest for us.
Looking forward, we're going to talk
about interrupts and says calls,
if you have questions, you can email
me millirems you in Canada, Aidoo
and you can find me on Twitter at my
house 30.