Hello, my name is Stephan, and in this lecture we will develop another assembly program.
And now that you have a firm grasp of GDB and know what an assembly program looks like, let's add some
complexity.
In this lecture I will show you how to obtain the length of a string variable.
I will show you how to print integer and floating point values using printf and I will expand your knowledge
of GDB commands.
So now here we will firstly open CSM or you can also choose another text editor so you don't need much
about creating or developing assembly code.
And let's actually use the CSM here.
Now create a new project here.
Let's delete this project, save it somewhere.
In this case, let's actually our project name is going to be kicking.
That's it.
Now save it as the name of kicking that --.
That's it.
And here is our code.
Now we will firstly comment it out.
Our the.
Assembly program, name, file name, RSM here.
Now we will firstly add this data section in it here because we will add the two variables.
It's actually two variables, but we will add four variables.
The two variables is for the our string and string.
And the second variables is the length of the first string and the length of the second string.
Now here we will firstly write this the message MSG one db here.
Hello world.
Let's actually case sensitive words here.
Hello world and ten zero.
And a comma and zero here.
So what?
So this is something new, right?
So we added zero for the null terminated.
But here we added ten, which I will explain right now.
So this is the string with an L and zero.
The string width and zero here.
We will also have the.
Message one.
Length here.
Actually, length is okay.
So we will write here and what we're going to do, we will take this message variable minus message
one, minus one.
So this is for measuring the length minus the zero here.
So measure.
Measure the length.
Of message one and minus.
The zero.
And we will also create our string too.
We will name it MSG two.
Here we will write it DB right here.
And our message is going to be kicking and alive this here.
So.
Here.
We will also.
All this again, ten and zero.
Remember, this ten is for new line and is for nation.
So we will terminate our string after new line.
Right.
So string with L and zero here.
And after that, we will also create the search tool.
Len, here.
This is going to be, again, equal here.
And here we will again measure the length and we will miss the zero.
So a message to.
Minus one here.
So this is for the measure.
The length of message to.
Plus minus.
The zero.
And here we will create some radius.
So this is the radius.
And pi is actually the terminology for you, which you will learn by the end of this section.
I will explain this terminologies deeply later.
So radius.
Be cool not to be here and.
357.
And we will add comments.
But as I say, they I will explain this further.
String not.
This.
Is playable.
Again.
We will copy this.
And we will again create a P here.
P.
BQ 3.14 and again.
So now our section data is completed.
Now we will also create the section which we will not use.
We will not notice anything here.
Section The main where our main function will live here is section text and we will create a global
main.
Now let's start developing our main function.
So in our main function we will again add the we will push the.
R p.
P.
This is the function prologue.
Actually, we can.
Less taps, though, because we will not have.
The strings here.
These are just instructions.
So here, this is the.
Function prologue.
Move.
Are BP RSP.
This is, again a function prologue as well.
Move.
One.
I always add this here.
Here.
So Rex1 is as we did in previous lectures.
This is for right writing here.
One is right.
And we will again move here.
Ready?
As for to write on the console.
To STD out.
Out.
Out here.
So move.
RSI.
Message one.
First, we will use this message.
One.
So this is the.
String to display and after that.
We will again.
We will move.
Are the eggs.
And after that we will again print the length of this message one string, and after that we will apply
the same for the message to here.
Message one length.
Here.
This is the length.
Of the string here.
Actually, we let's actually add tabs.
More tabs here.
Doesn't look good here for display purposes.
And that's it.
After that, we will call the syscall to display the string.
Display the string.
So these are the comments, as you know.
So we will again instead of writing.
Actually we can write it out here.
So rax one, it's for one.
Right.
Of I.
Are thy one is for the STD out.
STD out.
And after that.
It's called.
Tracks RDA and after that we will need to add RSA again.
Message to.
Um, this is the string to display and move again.
Ah, the X.
This is the message to Len.
And again, this is the length of the string.
Length of the string.
Length out a string.
And.
After that.
That's it.
We will.
You can call the syscall.
So this is for.
Displaying this string again, the second string which is kicking in the live display.
So you might be wondering where we will use this radius and pi here, which we will use that right now.
And this is the skull is display.
The ring.
And after that, this is the last year, so we will develop the function.
Epilogue.
Function.
Epilogue.
Again, we will add exit and success exit code again.
And after that we will again call the syscall to quit the program.
Right.
So.
After calling the Siskel here again, we will call it one more time.
After completing these four lines of code, we will firstly create a two function epilogue Our BP.
Are here.
Cases here.
Bob, I.
Okay.
You can't hear my voice.
Okay.
Beep.
I just scared.
I thought this ten minutes of work just for nothing.
And here are BP.
This is the function epilogue.
And again move RB.
Here are BP again without the BP.
Here just BP.
This is the function epilogue as well.
And after that we will move the racks which we did in previous code here.
This is for the 60 means exit, and after that we will again call.
Lastly, rest instruction is called RDA and this is for the zero, which is the success exit code as.
Exit code and after that.
Port here.
And after that we will call the syscall.
And that's.
Uh, quit.
This is just a quick.
So our program is done.
So this type of programming to your, uh, you can write it in your, um, favorite editor and save
as kicking the ACM.
And now in next lecture, we will create the make file here.
So I'm waiting you in next lecture.