Hello, This is Dr Miller and this is Episode 14.12 of Assembly.
Today we're going to use assembly and see together.
So for this we're going to use GCC and Nazem and so Nazem has the ability to generate object files for us
and then inside of our Nazem code, we're going to declare a function and we'll make it global, which means it will be exported and usable
within GCC. And then GCC can take his 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,
um, what function exists even though it may not exist in the file that we're using.
So when we get ready to compile, we use the Nazem minus f and so we're doing it on Lenox. So the output format is elf.
We have our Essam file and then or generate this object file and then with GCC. We include that object file before we include our main file.
So what's our problem? To be false solved. So what we're gonna do is write a strangling function, and so we're going to call it lends string.
Um, 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 gonna return an end, and then we're going to use that function inside of our C file.
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 Len String.
No, do it right.
And so the lens string is going to be our function
that we're going to create.
And so down here instead of this, we're going to say Len
and so I'm gonna
remove some of this code here.
So, for example, my push A and my pop A I'm going to get rid of those.
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 e d I
and e c x
eso At the end, I went to restore those So Poppy z x
bob e d I,
and we got our leaving a return it And
um, we're going to use E c X.
We're going to use E X for too low this character that we're gonna scan for, So we're going to use the S C A S B to scan for a bite.
So go ahead and move into the a X
zero, which is the character the knoll that we're going to search for. Then we're gonna move into E D. I. So we have a pointer as the first argument, and so we'll grab that from E B. P
plus eight. Remember that our enter set up Ari BP BAE Stack,
we're going to move into E. C. X. So our maximum or the maximum, that we're going to scan
UBP plus zero c.
We'll clear the direction flags that we can use. This
I 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 S C A S B to scan for a string bite
so that a bunch of different
string functions that we can use in order to search for characters because strings were something that were heavily used an assembly. So they added a bunch of commands in there.
And so when we get done with that, the pointer of e d. I is going to point to the location where that character is, and so we're gonna reload
into easy X,
the original location.
that's going to be E B P plus eight. So that was our pointer that was on the stack.
We're gonna let him move into E x
e d I. So we have our
We're going to subtract
yea x from EEC X. So we'll subtract the two pointers e c x being the smaller pointer. Yea x
being the larger one.
Um and then we're in a deck. Ament, yea x by one because this is pointing to the character. And so the length is gonna be that number minus one. And so we have to subtract one from it,
and then we have our epilogue of our function.
So now we're going to create our
we'll call this main dot c
So we're gonna do our standard includes
so standard input,
and the string library.
And then we're our function is called Len String.
It takes a character pointer, see?
And a hint, Max,
we're just telling the compiler. But by the way, we have a function.
Here is our main
Harold. Define our size for what we're going to do. I'm gonna use Malik in order to allocate myself a bumper buffer
here, I'll do a cast just to be safe. 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 percent s to search for a string,
and I'm gonna store that in input.
And then I'm gonna compare,
um, are two strings So and Len physical twos
stir. Len, this is the standard call
won't get our call.
Ours is called Len String,
and then I'm gonna give it the value of size so it has a maximum. That was we ended up using any C X
and then we'll go ahead and print our result,
so format it nicely. So I got my first length.
I'll put my second length there,
and then we'll put our string,
put a nice new line in there
and give us our arguments.
so now we're gonna want to compile them. So it's a Nazem
minus f elf.
And then ours is 14. $12 sn and so called. $14 12 0
no, I need to give the minus. Oh, come in there.
And then GCC minus
14 12 0 and then main off. See,
it looks like I have, ah, syntax here, 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 printed off the sterling version
and our version. And so you can see that we can easily,
um, create a assembly file
where we basically export our function name, and then we need to just make sure that we use our function arguments appropriately. So
here I knew I had a knee BP based stack, which is what Lennox typically uses, and so I could use E. V P plus eight and 12. His argument won an argument to
And then we just ended up using a string command that is built into X 86 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 gonna talk about interrupts and Siskel's.
If you have questions, you can email me Miller, MJ at you and Kate I e. To you, and you can find me on Twitter at Mahal's 30.