WEBVTT

00:00.610 --> 00:01.450
Hello, my name is Steve.

00:01.630 --> 00:02.560
Welcome to this lecture.

00:02.560 --> 00:06.940
And in this lecture we are going to compile this program, create a mac file for it.

00:06.940 --> 00:10.850
And also I will explain this code line by line first.

00:10.900 --> 00:15.310
First of all, let's actually make our code look nicer here.

00:15.310 --> 00:18.970
Let's add a enter here, the new line.

00:19.960 --> 00:22.120
Have a new line.

00:22.120 --> 00:22.960
And also.

00:24.290 --> 00:25.280
New line here.

00:25.280 --> 00:28.880
So the code is going to be read for us.

00:29.810 --> 00:30.710
And that's it.

00:30.890 --> 00:36.620
So now here, let's get started by explaining this code by line by line.

00:36.860 --> 00:44.390
And what we're going to do is firstly, I will explain this data section, which are which we are defining

00:44.420 --> 00:47.560
the various data variables with different sizes.

00:47.570 --> 00:50.600
So actually we also need the grommet.

00:50.720 --> 00:53.510
Let's actually mark it down to.

00:57.660 --> 01:00.540
Now we are I'm explaining this data here.

01:00.540 --> 01:07.770
So in the first year in Vietnam, we are defining a bite size.

01:07.770 --> 01:12.390
In this case, eight bits for this exploit.

01:13.920 --> 01:17.100
Okay, So this is eight bits.

01:17.940 --> 01:21.750
Um, variable with the value of one, two, three.

01:21.750 --> 01:23.490
And in w num.

01:23.490 --> 01:30.960
Here we are defining a word size in this case, 16 bits.

01:32.010 --> 01:37.100
Um, 16 bits variable with the value of one, two, three, four, five.

01:37.110 --> 01:42.450
And in the Num we are defining a double word size.

01:42.450 --> 01:52.530
In this case it is 32 bits, a variable with a value of 1234567890.

01:52.530 --> 02:02.280
And in num one we are defining a quad word size variable with the value of this here.

02:02.280 --> 02:10.170
In this case, this variable size is 64 bits here, 64 bits.

02:10.590 --> 02:15.360
In this case it's 32 bits, 16 bits and eight bits.

02:15.570 --> 02:21.570
And also in num one, yes, we are defining the 64 bits we already explained.

02:21.570 --> 02:31.660
And in M2 we are defining another quad word size variable with the value of one, two, three, four,

02:31.660 --> 02:32.440
five, six.

02:32.440 --> 02:43.180
In this case, this is also 64 bit and also this is also 64 bit because we defined that as a quad word

02:43.180 --> 02:44.590
size variable.

02:44.590 --> 02:52.480
So and in N3 we are again defining a codeword size variable with the value of 3.14.

02:52.690 --> 02:56.020
It is also 64 bits here.

02:57.280 --> 03:05.350
And here in the section, the section will normally contain initialized data, uninitialized data.

03:05.350 --> 03:09.000
But it seems like there's a we didn't add.

03:09.250 --> 03:18.400
No variables are defined in the section because we don't have any unusual uninitialized data here and

03:18.490 --> 03:20.380
here in this section.

03:20.380 --> 03:29.440
We as you can see, yes, in the section text here, this is the section is for code instruction.

03:29.440 --> 03:37.660
This global main directive specifies that the symbol main is globally accessible entry point for the

03:37.660 --> 03:38.500
program.

03:38.500 --> 03:45.880
And also we have this main push rb r, BP and RWP rsp.

03:46.240 --> 03:51.130
This is this main label marks the start of the main function.

03:51.490 --> 03:58.250
So this code sets up a basic function prologue by saving saving the current value of the base pointer

03:58.280 --> 04:07.640
r bp onto the stack and then copying the current stack pointer rsp into our BP here.

04:08.210 --> 04:13.720
So and after that, we have four lines of code defined here.

04:13.730 --> 04:22.780
So this is for the these are the instructions, um, manip to manipulate the rax register.

04:22.790 --> 04:26.870
This is a general purpose 64 bit register.

04:26.870 --> 04:29.750
So rax is 64 bit.

04:29.750 --> 04:37.640
But you can also open this cheat sheet cheat sheet for the 64 bit registers here.

04:37.640 --> 04:40.880
So 64 bit registers.

04:40.880 --> 04:51.170
So here, as I added comments here, the move rax minus one fills the entire rax register with ones.

04:51.530 --> 04:58.100
This move a l bite b num loads the value of b num.

04:58.110 --> 05:05.540
In this case b is 123 into the lower eight bits of rax preserving the upper bits.

05:05.540 --> 05:09.680
And also we have the XOR rax rax.

05:09.680 --> 05:17.590
This clears all bits, all bits in rax and move a l bite b num.

05:17.600 --> 05:23.660
Again, we are using one, two, three calls, we are using B now which holds the value of 123.

05:23.690 --> 05:32.270
This loads the value of b num into the lower eight bits of rax now correctly here, so similar instructions

05:32.270 --> 05:35.300
are used for this.

05:39.020 --> 05:39.520
Here.

05:39.560 --> 05:51.920
A similar instructions are used for here, a x and a word here, a keyword and a x, which is, as you

05:51.920 --> 05:53.410
can see, for Vina.

05:54.650 --> 06:01.520
And so we are again manipulating this rax register here.

06:01.700 --> 06:07.960
So move rax minus one again fills the rax with once more rax keyword w num.

06:09.170 --> 06:13.090
Loads the value of uh, the PR uh.

06:14.260 --> 06:16.000
W I'm here again.

06:16.000 --> 06:22.090
But this is the almost the same with this one here in the previous one.

06:22.090 --> 06:25.240
But what's interesting here is this.

06:25.420 --> 06:28.920
So again, we are at the start.

06:28.930 --> 06:30.520
We are all the same.

06:30.520 --> 06:39.820
So we are moving the racks, move racks minus one is fills the entire racks register with once again.

06:39.820 --> 06:42.760
You can also use this to learn this registers.

06:42.760 --> 06:46.300
You can also open the Nasm cheat sheet.

06:47.410 --> 06:50.680
You can find that in anywhere.

06:50.890 --> 06:54.940
So you can use that to learn about these registers as well.

06:54.940 --> 07:01.000
So here after that we move racks Keyboard Keenan one.

07:01.120 --> 07:04.930
This loads the value of Keenan into racks.

07:05.260 --> 07:14.510
So we are in this here we are overwriting the previous value of racks and move keyword to Num2 racks.

07:14.510 --> 07:19.850
This stores the value of racks into enum to.

07:20.870 --> 07:24.680
And the lastly mov rax 123456.

07:24.710 --> 07:29.840
This loads the immediate value of 123456 in Rax.

07:29.840 --> 07:40.580
And lastly, what we have here actually we need to instead of using that we need to use mov s mov.

07:45.400 --> 07:46.390
Move here.

07:46.420 --> 07:47.080
So.

07:48.420 --> 07:48.930
Move.

07:51.300 --> 07:52.230
Or still here?

07:52.230 --> 07:52.800
Yes.

07:52.920 --> 07:53.280
This.

07:53.280 --> 07:56.280
This here needs to move here.

07:56.280 --> 07:56.910
So move.

07:56.940 --> 08:05.910
SD So this instruction loads double precision floating point number from the memory location key M3

08:05.910 --> 08:08.580
into Xmm0 register.

08:08.580 --> 08:15.240
And also keep in mind that must is a special instructions for handling floating point number because

08:15.240 --> 08:26.820
in Q and M3 we have the floating point number which is 3.14, and after that we just have several instructions.

08:27.210 --> 08:34.410
So this is here, these instructions here mov rsp rbp pop rbp here.

08:34.410 --> 08:40.470
So these instructions perform the function Epilogue Storing the stack pointer, rsp and base pointer

08:40.510 --> 08:43.410
are to their original values.

08:43.440 --> 08:47.220
This ret instructions is new to us here.

08:47.220 --> 08:49.410
This RET instruction is new to us.

08:49.440 --> 08:54.760
This instruction returns from the main function which we didn't actually use that.

08:55.730 --> 08:55.990
Lecture.

08:56.090 --> 08:58.730
So please also keep in mind that this code is.

08:59.610 --> 09:03.870
The x86 64 assembly language and syntax.

09:03.870 --> 09:11.580
While I explained individual lines, it's important to make sure that code is properly assembled and

09:11.580 --> 09:14.740
executed with a within a suitable environment.

09:14.760 --> 09:22.200
And now what we're going to do is we will first compile it with the make.

09:22.350 --> 09:29.160
We will create the make file in the next lecture and we will also use the triple dee dee dee dee debugger

09:29.160 --> 09:37.320
for debugging our application, which obviously this this will not provide any console output like printing

09:37.320 --> 09:46.680
the words Hello world, but it actually does operations in memory which we will uh, analyze that and

09:46.680 --> 09:48.270
debug that in next lecture.

09:48.270 --> 09:49.620
So I'm waiting you in next lecture.
