13 hours 15 minutes
Hello. This is Dr Miller and this is Episode 2.3 of Assembly.
So today we're gonna learn about segments and executing functions
so different segments have different meanings inside of the assembler. So we have the dot data section
and this is used for stringing global variables.
It's initialized data, and then it's reading, right, so we can read data from it and we can write data to it.
We also have the BSS. So the BSS is for un initialized variables,
and it is both reading, right, additionally, but it doesn't take up space. And so you might say, Why do I want one of the others? The data is for something that we
would care about, and we want to actually give it a value the BSS is gonna be for for buffers. Maybe so. If you were going to read a file from disk,
you might put that in the BSS and then read the data from the disk instead of wasting space in your binary
with useless data.
And then we have the text. And so that is where our code goes. And this is reading execute, meaning that the computer can read it, and then it can run it. But it's not gonna ever change it,
and that's what your programs should be set up now. People who are attacking different things might change it so that
the text segment is read, write execute so they can write additional instructions. Or some interpreters might modify their tech segment so that it is
read, execute and right. So there's a different
ways that you can change that. But this is generally how our assembly is going to work.
So in the data section, we can define different pieces of data, so we can, as we talked about before, define a bite, define a word or define a d word,
and this can take up one bite. This will take up two bites, and this will take up four bites.
And then for convenience, we can define a whole bunch of bites. Right, So this is a string. So each one of these is gonna be a bite. And so it's a lot easier than trying to figure out what is the ask e or hex value of each one of these. We just type them in, and then the assembler will take care of that
So we're executing a function. We use the demonic call for calling a function,
and then the operation is a function name that we're going to call.
So, for example, we could define a string and then put that address in yea X, and then we'll call this function called Print String,
which prints what is pointed to by E. X. And we got to make sure that we have a null terminated string. So let's go ahead and do that.
So I've already created a project Gen make here 2.3, went into that directory and already built it just so that everything was ready.
I'm going to insert mode
and I'll define a string.
Now, one of the things that often times my students forget is to put in a zero in here. So this will neural null terminate our string.
So no means that this has the actual zero byte inside of it.
And so, as it said, what we're gonna do here
move into yaks
go ahead and write and quit
type make. Hopefully, everything worked
so we can see a printed off hello world. But it didn't print off a new line just slightly knowing.
So let's go ahead and add a new line in here. So a new line is the character. 10.
Go ahead and add that
And now we got a new line at the end of our our program.
All right, so we just executed a function that was called Prince String, given that null terminated string that we had in there.
So inside of the
template, we have a bunch of the functions that have been created that we can easily use. So we have Read INT, which reads an integer from the user
and then stores that result in the X. We have print INTs, which will printed Manager. That's in E X.
We have print and now, which will print Ah, a new line. And then we have read characters. This reads a single character from the user
and stores it in the X, and it's actually in the lowest half. So ale of that register.
We also have print string, which we saw in the previous slide.
So we're gonna do a little example here, so we're gonna go ahead and print a prompt for the user to enter two numbers.
Well, read those in and then we will add them together and go ahead and print the result.
So I'll go ahead and use the same program that I had before.
I'm gonna take off the new in here because I think it looks better this way.
So I'll go ahead and move my prompt in t a X
and then I'll want to read that number from the user
so you can look in the slot in the previous part of the lecture.
But we're gonna go ahead and call, read
So now the result is in the X, so I'm gonna go ahead and move that to EBX.
So I'm just copying the data that's in E. X into ebx.
Now, once again, I will move the X prompt
read another number,
and so I have one of my numbers in E b X. And after this, I should have the other one inside of yea X.
So now I can go ahead and say Add e x e v X,
so that will
add the value that's in the E X to the value. That's an E B X and save the results into E. X.
And now I can call my
print in function,
which will print whatever is in the X
and I'll add a new line at the end.
Go ahead and make.
I didn't mess up.
So let's pick two numbers. Let's say
So our result got printed on 110
right? And we could have done a couple other things to make it maybe a little bit nicer. So,
for example, let's suppose we wanted to print an additional prompt
saying that the result And so I'm gonna have to save yea X after this reading, so I might have to do movie see ex.
Yeah, so save my results And I have
in the Vieques
number two in
So let's let's do our result.
If you are not an insert menu type, exit will delete characters.
So move my
print off my string.
And now down here, I needed to
move into the x e c x. So now I have moved E c X into E X and then added the two together and then called my
print in printing line.
See if we messed up?
So I had 98.
My results is 110.
So in summary, we talked about segments. We talked about executing functions. And then I gave an example of how we can execute functions to solve a very simple mathematical problem. I'm just reading two numbers from the user and then adding the results together.
So in future lectures, we're going to talk about extending numbers. So extending the sign on signed numbers that are stored in two's complement
and then doing multiplication and doing division.
If you have questions, you can contact me at Miller MJ at you and Kate I e. To you,
and you can find me on Twitter at Milhouse 30.
How to Use GDB (BSWJ)
The GNU Debugger (GDB) is one of the most commonly-used debugging tools in the world. ...
Certificate of Completion Offered
How to Use IDA (BSWJ)
The IDA is used throughout the IT and cybersecurity industries by exploit developers, vulnerability analysts, ...
Certificate of Completion Offered