WEBVTT

00:00.500 --> 00:06.950
Hello, my name is Typhoon and in this lecture we are going to write our Makefile to compile this program.

00:06.950 --> 00:12.890
Also we will get again as we did in the previous lecture, we will get the move that or output move

00:12.890 --> 00:16.400
that lStm and move that um M as well.

00:16.400 --> 00:20.390
And I will also produce the move executable move file.

00:20.690 --> 00:25.930
Um, well, so here what we're going to do is we will first go to, um.

00:27.020 --> 00:28.430
Assembly here.

00:28.550 --> 00:30.650
We have the Move project here.

00:31.380 --> 00:32.430
Um, as you can see.

00:32.460 --> 00:35.250
Oops, move, uh, clear here.

00:35.250 --> 00:37.550
So we have moved that here.

00:37.560 --> 00:42.030
What we're going to do is we will open our some text editors in this case.

00:42.030 --> 00:45.240
We also cannot convert gedit or mousepad.

00:45.270 --> 00:53.550
Yes, it depends on is here and we will create something named make file and that's it here.

00:53.730 --> 01:00.990
So what we're going to do is we will need to, uh, right, right here with move, start writing with

01:00.990 --> 01:01.860
move here.

01:02.010 --> 01:06.750
We will first create a move that all this line defines a rule in the make file.

01:06.750 --> 01:11.310
It states that the target move depends on the file move.org.

01:11.340 --> 01:16.350
So this means that if move that all is modified or doesn't exist.

01:16.350 --> 01:22.170
Um, then the target moves rebuilt using this comment here.

01:22.170 --> 01:26.010
And also, uh, we will.

01:26.700 --> 01:29.910
At GCC or move.

01:30.650 --> 01:35.010
But also we will use the no pi here, which I will explain right now.

01:35.030 --> 01:44.450
So this this command is used to link the object file, move that or into the executable named move here.

01:45.170 --> 01:51.440
So it uses the GCC compiler and this all here specifies the output file name.

01:51.440 --> 01:59.450
And this no Pi is a linker option that disables position independent executable in this case pi generation.

01:59.450 --> 02:06.260
So Pi is a security feature that randomizes the address space of the executable, but it's being disabled

02:06.260 --> 02:08.360
here because we want to debug it.

02:08.540 --> 02:15.110
So here we will also add the move.org here.

02:15.500 --> 02:17.660
Now we will move that ESM.

02:19.480 --> 02:23.140
So this line defines the another rule in the make file.

02:23.910 --> 02:29.700
It indicates that the target moved at all depends on the file moved at RSM.

02:29.730 --> 02:38.040
So if we move that RSM is modified or doesn't exist, the target moved at all needs to be rebuilt using

02:38.040 --> 02:39.300
this command here.

02:39.300 --> 02:48.900
Nasm f elf 64 g Move that SM or move that over here and move that LST.

02:48.930 --> 02:56.040
So this command assembles the assembly file, move that RSM using the Nasm here.

02:56.040 --> 02:56.970
Elf 64.

02:57.000 --> 03:00.540
Now let's break the down options and arguments here.

03:00.540 --> 03:06.960
So F Elf 64 specifies the output format to be Elf 64.

03:07.200 --> 03:14.820
The G here generates a debugging information which can be useful for debugging with tools like GDB or

03:15.390 --> 03:16.110
here.

03:16.110 --> 03:24.580
And this move that RSM this is a source assembly file to be assembled and not this all move that all

03:24.580 --> 03:32.260
here specifies the output file name as moveto and L here This is the generates a listing file containing

03:32.260 --> 03:39.130
the assembly code along with the memory addresses so the this listing can be helpful for reviewing reviewing

03:39.130 --> 03:40.990
the assembly code as well.

03:40.990 --> 03:48.010
So to summarize the provide a set of commands and rules as are part of the make file which is used automate

03:48.010 --> 03:50.620
the build process for an assembler program.

03:50.620 --> 03:57.190
So the make file defines how the executable move is built from the assembly source file and move that

03:57.220 --> 04:06.260
RSM by by assembling it into an object file, move that over here and then linking it to g C.

04:06.670 --> 04:13.210
So now what we're going to do is we will save this file right now here and we will continue.

04:14.110 --> 04:20.590
On drawing or on starting out and debugging or JC here.

04:20.680 --> 04:22.380
So now, uh, here.

04:22.390 --> 04:23.290
Clear.

04:23.390 --> 04:29.890
So, cat make file and as you can see, make file is written here and here.

04:29.890 --> 04:33.450
Now we will just press write make, and that's it.

04:33.460 --> 04:35.020
Our program is compiled.

04:35.020 --> 04:38.230
And as you can see, we have this executable file here.

04:38.230 --> 04:43.560
So if we run this and as you can see, we have no output because we are working in a memory.

04:43.570 --> 04:47.230
So now, uh, we saved, uh, the source file.

04:47.230 --> 04:48.850
Yes, everything is okay.

04:48.850 --> 04:53.330
And here we will need to start a triple D, so I will call it D.

04:54.800 --> 04:56.320
The DVD here.

04:56.690 --> 04:57.410
Move.

04:57.530 --> 04:58.700
And that's it.

04:59.210 --> 05:03.860
We installed DDT in actual dribbled is more easy to pronounce.

05:03.860 --> 05:05.070
So I use I.

05:05.090 --> 05:10.160
We installed a triple D in previous lectures, so we will not install it again.

05:10.910 --> 05:17.320
And here we have some informations on blah blah blah here and that's it.

05:17.330 --> 05:23.720
So here you will see this graphical user interface with a rather dated layout.

05:23.720 --> 05:30.590
And DDT is an old open source tool and apparently nobody is willing to adapt it to the graphical user

05:30.590 --> 05:32.780
interface standards we are used today.

05:32.780 --> 05:40.460
And so you have a window with your source file, source code displayed and window where you can type

05:40.880 --> 05:43.370
gdb, gdb command.

05:43.370 --> 05:48.560
So there is also a floating panel where you can click run here.

05:49.300 --> 05:50.510
And see, here we are.

05:50.530 --> 05:51.340
This is the terminal.

05:51.340 --> 05:59.440
We can type GDB commands and if we click on the service menu and um, let's actually click on the source,

05:59.440 --> 06:00.670
uh, menu and.

06:01.430 --> 06:01.940
Um.

06:03.940 --> 06:04.510
Here.

06:04.540 --> 06:06.820
Uh, as you can see here, uh, menu.

06:06.820 --> 06:08.350
And we can, uh, display.

06:08.710 --> 06:09.730
Display.

06:09.730 --> 06:11.320
Uh, line numbers.

06:15.390 --> 06:15.930
Here for.

06:16.020 --> 06:23.100
As you can see here, we have find find words only find case sensitive only line numbers, display machine

06:23.100 --> 06:24.600
code in the source and so on.

06:24.600 --> 06:27.000
So we will click on display line numbers.

06:27.090 --> 06:35.810
Um, we can see the line numbers on the left like the most the new text editors and in the same menu

06:35.820 --> 06:41.100
can choose have a window with the assembled code as well.

06:41.100 --> 06:49.440
So now, uh, we will place the cursor here on this, uh, main and we will right click here.

06:50.630 --> 06:56.840
And here, as you can see here, we will actually let's actually place run here.

06:57.800 --> 07:01.460
And here we can in right click on it.

07:02.480 --> 07:03.530
Now, uh, here.

07:03.530 --> 07:06.590
We can also set the breakpoint here.

07:12.940 --> 07:24.790
Also we now we if we run this again and this, you can see we're one breakpoint main at that in 15 line.

07:25.980 --> 07:26.790
And.

07:28.290 --> 07:29.220
Here.

07:29.610 --> 07:32.250
Uh, let's actually right click on the again.

07:33.030 --> 07:36.090
And as you can see, we have also commands program.

07:37.800 --> 07:38.640
Cool here.

07:38.640 --> 07:40.410
Edit on.

07:50.210 --> 07:54.590
And here again, delete this breakpoint.

07:55.560 --> 07:56.190
Sable.

07:56.190 --> 07:58.470
You can also delete and disable the breakpoints.

07:58.470 --> 08:01.710
But here in this case, let's actually delete again and I will.

08:01.830 --> 08:03.120
Let's run it again.

08:03.120 --> 08:10.800
So what we're going to see is and what we are need to see is we will need to see registers, which this

08:10.800 --> 08:12.930
is the whole logic of this code.

08:12.930 --> 08:19.620
That's why we written this code to show something on registers, uh, which now we will add the main,

08:19.620 --> 08:22.530
uh, main the breakpoint at the main here.

08:23.290 --> 08:32.170
And to observe and understand how the content of registers changes with the this move command, we will

08:32.170 --> 08:32.810
follow.

08:33.200 --> 08:40.900
We need to place the cursor in the front of the main here and we right click on it.

08:43.300 --> 08:46.060
And now we will choose a break.

08:47.080 --> 08:49.790
Or you can also click the.

08:49.840 --> 08:52.780
Yes, uh, you can also click break here on.

08:53.630 --> 08:54.440
It's on break.

08:55.320 --> 08:56.040
And.

08:57.310 --> 09:04.840
Or you can also click on the top of this menu, uh, on the, uh, stop icon here, as you can see here.

09:06.710 --> 09:07.850
But it's right.

09:07.970 --> 09:09.770
Just right click on it and choose break.

09:09.770 --> 09:16.220
And then we will click on Run here on the floating panel debugging.

09:16.250 --> 09:18.620
So this will start a debugging process.

09:18.620 --> 09:25.400
And now we will click on the status here in the top menu bar and then select registers.

09:25.400 --> 09:31.370
So this action will open a window displaying the current values of registers here.

09:32.830 --> 09:33.290
Here.

09:38.310 --> 09:39.120
Make it a little.

09:43.150 --> 09:43.630
But will.

09:44.520 --> 09:45.280
To our screens.

09:45.290 --> 09:47.090
Oh, this is so wide here.

09:47.470 --> 09:47.850
Don't need.

09:53.140 --> 09:55.720
This debugger needs to be updated at.

09:56.500 --> 09:57.760
Graphical here.

09:57.850 --> 09:58.930
But this.

10:23.590 --> 10:25.590
And that's it here.

10:25.600 --> 10:26.410
So.

10:27.820 --> 10:36.640
And after that we will click on this step here to execute the current instruction in the program.

10:41.130 --> 10:41.580
This.

10:48.600 --> 10:49.620
And see here.

10:50.420 --> 10:51.260
Up in.

10:54.770 --> 10:56.060
And here.

10:57.970 --> 11:01.090
As you click this step, you will observe.

11:01.210 --> 11:07.300
You will able to observe how the values in registers change with each step through the program.

11:07.570 --> 11:17.050
If you wish to inspect memory addresses like you num1 or be num, uh, you can uh, go to the view option

11:17.050 --> 11:17.710
here.

11:18.570 --> 11:23.580
And to make the data window visible here and under this data.

11:26.630 --> 11:27.320
But now it's.

11:28.980 --> 11:29.160
I'll.

11:30.810 --> 11:31.230
Was this.

11:31.230 --> 11:32.310
No, we don't want to close this.

11:32.310 --> 11:35.460
I don't want to do it again from zero here.

11:35.460 --> 11:36.600
Let's actually make it.

11:38.280 --> 11:39.000
Down here.

11:39.690 --> 11:41.530
And here, um.

11:42.000 --> 11:45.000
Under here and go from here.

11:45.750 --> 11:46.010
Step.

11:48.460 --> 11:49.030
Here.

11:49.840 --> 11:51.850
Up and up.

11:52.370 --> 11:53.080
Finish.

11:54.480 --> 11:55.260
Interrupt.

11:56.360 --> 11:56.730
That's it.

11:56.750 --> 11:58.190
Now we will run it again.

12:01.730 --> 12:02.900
And here.

12:06.330 --> 12:06.690
You.

12:07.740 --> 12:08.610
Data window.

12:12.230 --> 12:12.680
Even though.

12:21.440 --> 12:24.560
And here, as you can see here, we are seeing our variables as well.

12:25.230 --> 12:28.380
But the most important thing here is in registers.

12:28.500 --> 12:30.540
So and keep in mind that.

12:31.610 --> 12:32.270
Here.

12:32.880 --> 12:36.120
Keep in mind that the while has a graphical interface.

12:36.120 --> 12:44.140
It can sometimes be intricate to navigate, so if you find it faster you can use gdb which is uh, this.

12:44.220 --> 12:52.290
GDB is better, which is and gdb input window for better for certain tasks.

12:52.290 --> 12:58.020
And it's important to keep in mind that DVD is built up on top of gdb.

12:58.440 --> 13:04.710
The new debugger and consequently using a proper function, prologue and epilogue code is essential

13:04.710 --> 13:11.520
to avoid potential uses during the program execution and typically ignores the function prologue while

13:11.520 --> 13:14.820
stepping with the code here.

13:14.970 --> 13:21.840
And the primary objective of this code is to demonstrate how the move command actually again, I want

13:21.840 --> 13:25.950
to do it again here how this move command.

13:28.380 --> 13:32.220
Here impacts the contents of registers.

13:32.220 --> 13:32.850
Right.

13:33.770 --> 13:35.210
As you can see, in racks.

13:35.960 --> 13:38.420
You're always changing the here.

13:40.410 --> 13:41.150
Now see here.

13:41.160 --> 13:44.340
Now it's one, two, three, four, five, six.

13:45.100 --> 13:45.520
An.

13:46.640 --> 13:48.220
It's done because there's a.

13:50.020 --> 13:52.810
Its program is at the read here.

13:52.810 --> 13:55.830
So interrupt it, run it again.

13:55.840 --> 14:00.580
And as you can see, Rex is something just random thing here.

14:00.970 --> 14:06.190
But and in this here we are filling Rex with once.

14:07.270 --> 14:10.510
And here we are.

14:10.510 --> 14:11.110
Step.

14:13.050 --> 14:13.530
Here.

14:13.830 --> 14:20.220
And as you can see here, here now, Rex has the correct value here, which is zero for now.

14:20.220 --> 14:22.650
And here we are filling Rex with ones.

14:22.650 --> 14:30.720
And as you can see, here is the Rex value is one, two, three step again minus one as it did here.

14:30.930 --> 14:37.110
Then again, minus five, 319, one step again and zero again.

14:37.110 --> 14:43.530
So now let's step again and one, two, three, four, five, six, which is the value of our.

14:44.470 --> 14:45.880
Welcome here.

14:48.010 --> 14:48.670
One, two.

14:49.610 --> 14:49.830
We?

14:49.910 --> 14:50.330
Yes.

14:53.160 --> 14:54.090
Again, minus one.

14:54.090 --> 14:56.340
And here we also.

14:59.390 --> 15:00.050
Again.

15:01.130 --> 15:03.230
And no one here.

15:04.320 --> 15:05.430
And after that.

15:06.750 --> 15:13.590
Lastly, we are seeing this move Racks Keenum 123456 here.

15:14.200 --> 15:18.280
And here we are, instruction for floating point number.

15:20.060 --> 15:21.740
And that's it.

15:23.670 --> 15:30.720
So this is, um, how have you, as you continue stepping through the code, you will notice that when

15:30.720 --> 15:38.650
you move a 32 bit value into a 64 bit, register the higher bits in the 64 bit registers are cleared.

15:38.670 --> 15:45.300
So likewise, when you move value in to ax the upper bits of Rax are cleared.

15:45.390 --> 15:51.870
Well, so this insight is vital to keep in mind during programming and debugging.
