Hello, my name is Stephan, and in this lecture we are going to create our Mac file, compile assembly
and run our program.
So here in previous lecture we just have this errors here.
So I fix this and change this.
We had the move here accidentally, right?
It move as an instruction, but here you need to change it to pop.
So this is the last final version of our code here and I will share this on the instructor on the lecture
attachment sections, and that's it.
So now we will clear the screen again.
And as you can see, we have kikinda here.
So we will create the gedit file.
In this case we will go get it.
Um, actually we can also use the mouse pad, text editor, mouse pad, the make file and that's it.
So here, this is our mouse pad.
So we will firstly add actually we can also add comments and so on.
But however, now we will.
Here.
Let's kicking.
Uh, actually, it's actually.
It's far from the keyboard, so.
So kicking here and we all.
Bring that all here and GCC output file so you learn that what this means in previous lecture when we
compile the Hello world application.
So I will not this entailed in this lecture again.
So kicking.
Seeing that all here again.
We will also.
So, you know, pie.
And after that, we'll go to the second line.
So thinking that, oh, here, this is also.
You're kicking that.
We will take this file.
Give it to Nasm f Elf 64 is going to be kicked or kicked over here and that's it.
Save this make file here.
And after that you can close this notepad here, close and make here.
And as you can see here, our make file is created and our application is also compiled.
So this make this typing make here.
After creating your make file, it should compile and link your assembly code and.
Here.
You need to also keep in mind that.
Make file.
So here, keep in mind that you don't use the spaces here.
You need to use the tabs and that's it.
After that.
Mike, and as you can see.
Is up to date and that's it here.
Now, what we're going to do is we will start our program and analysis and we will start the analysis
phase.
So clear Now, let's start our kicking program.
And as you can see, hello world and alive.
So in our first program, hello ASM, we passed the length of message here message MSG 13 characters
and in in this RDX in order to display the message and kicking that we use a nice feature to calculate
the length of our variables as you can see here.
So the message minus negative message one minus one part means this here.
So take this memory location and here the dollar sign and subtract the memory location of message to.
And the result is the length of message.
So and this this is the same applies for this message one here.
So take this memory location and subtract the memory location of message one.
So the result is the length message one.
So that length minus one here, this is the string terminating zero and it is stored in the constant
message one length here and.
And and note keep in mind that the use of function prologue and the function epilogue in the code so
these are the needed for gdb to function correctly.
As pointed out in the previous lecture, the prologue and epilogue code will be explained in later sections
and let's do some memory digging with the GDB here again because we love that here and now we will gdb
kicking here and that's it.
So then at the gdb prompt you type this disassemble.
Amble, Maine.
And that's it.
So here, this will show this output here.
So on your computer, it seems that the variable message.
One variable message, one sits at a location or somewhere on the byte and.
Yeah.
What are we going to do is, uh.
We will firstly check that, um.
X as.
Zero x.
The one here.
And as you can see, you can access to at the address.
So what we're going to do is we will.
Now, we will also try that with the message one with this and.
One here.
And as you can see, here is Hello World.
And let's actually try the message tool.
And this is the kicking and alive.
So we got this memory addresses of message one and message two here and we can also find the numeric
values here.
So in order to find that, we will again use x, d, W, so we will reduce it, reduce, reduce.
And here, as you can see, we got 357 and this is the radius.
And now we get the get this P here.
So radius and P, as you can see here, P is.
7113.
And that's it.
So we got this here.
As you can see, it's the floating point number.
And that's why.
Uh, we got a strange output here, and in order to fix that, we will, instead of using x here.
X w here.
So we got we can get this decimal and hexadecimal right value stored at the memory locations like radius
and so on.
And then we get a strange result when we try to get this floating point variable and print it on screen.
And in order to do that we will just we will not use D or W, we will use F, g.
And here after that, we will pass and that's it.
So this is the shows up and we can also.
And rally with X here and.
P and that's it.
And this is our the size of the variable.
And now what we're going to do is we will.
Slim.
Actually, there's a subtlety that you should be aware of here.
So to demonstrate, we will open the.
We will open this.
We actually created the LST using the Makefile.
Let's actually do that again.
So it's a pretty simple just open Makefile again.
Emily.
Project.
As however mousepad eg file.
So now you will learn how to create this l.
While here.
In order to do that, we will just add just a slight bit modification here.
So.
In the kicking that whole section here after this line that.
Right.
We will add.
L.
Uh, kicking.
At least so because we need this so much here for analyzing.
But.
The.
Begin Project Make here.
And make it up to date as our place.
Us.
And as you can see, we got this kicking that this test here.
So we wanted that, but it's okay.
There's a, uh, actually this file extensions didn't make much difference in programming, low level,
high level programming here.
And that's why let's actually.
Let's make it right.
Right.
So our, um, kicking or I'm kicking that LSTs and ram.
Or I'm kicking that all here as.
And I'll use the Mac.
And as you can see, we have this LST file right here.
So what we're going to do is we will firstly open this file with mouse pad again, the picking dot lst
and that's it.
So what we have here, there's a.
Uh, so what we have here, we have the.
Sections and the memories here.
So.
Now, you need to check this lines.
Line ten and 11 here.
And you'll also need to check.
Yes.
Line on 11 and here.
On the left here, you can find the hexadecimal representation of the radius P And as you can see here.
And instead of.
0165.
You find 62501.
And instead of this which we got here, the hexadecimal number we got here.
Remember that?
Add it somewhere.
Here.
Excellent.
Let's actually.
As.
And that makes.
Again.
Players gdb.
So here we will again get that value for you so you can see what's the difference and where is the problem
with that.
So in order to do that we will just go for example XD.
Actually let's get first a string and write that down here.
Have string message one string message.
But we first need this radius and pi here so we know that the value of radius, we obviously can see
it here.
Uh.
King taking that He.
Open a mousepad.
So here we see this variables and values.
But there's a strange here, so there's something wrong, actually.
Our program will work, but.
It has some warnings here, which we.
You need to learn, uh, what what stands for.
So I need to explain to you.
Explain it to you.
And now the W here.
We will firstly get the radius.
So, uh, with, with the W we get the radius value here.
In this case, let's actually reduce.
But we don't need that.
We already can see it.
We will use x, w and again we will also use f x here for the P.
As the P here.
That's it.
X 50.
Uh, yeah, that's it.
So.
As I said, instead of.
This.
0165.
You're seeing 6501.
So this is the bytes.
The one byte in two hex numbers are in reverse order.
So this characteristics is called indianness.
So the big Indian format stores numbers the way we are used to seeing them.
So with the most significant digits starting at the left and the left, Indian format stores the least
significant numbers starting at the left.
So Intel processors use little endian and that can be very confusing when looking at the hexadecimal
code.
So why do they have such strange names like Big in Indian and Little in Indian?
So in 1726, Jonathan Swift wrote a famous novel.
Villiers travels in the novel appear to fictional islands.
So Lilliput and Blefuscu inhabitants of Lilliput are at war with the people of Blefuscu.
But after break, eggs on the small island or on the bigger end.
So little boats are little Indians.
Indians.
So preferring to break their eggs on the smaller ones and Basophils are big Indians, not Indians.
Indians.
Now you see that the modern computing has traditions rooted in the distant past.
So take the time to single step through the program.
Break main run Next, next, next.
And you can see that GDB steps over the function block and edit the source code.
Delete the function prologue epilogue and we make the program single step again with a gdb.
In our case, gdb does not does refuse to single step at.
The program.
And when assembling with another assembler based on NSM, we can safely omit the prologue and epilogue
code and step through the code with GDB.
And sometimes it's necessary to experiment.
Tinker and giggle around.