WEBVTT

00:00.390 --> 00:01.470
Hello, my name is Stephan.

00:01.470 --> 00:05.310
And in this lecture we will create our Hello World program again.

00:05.310 --> 00:08.400
But in this time we will use the make file.

00:08.700 --> 00:15.750
In previous lecture we created our Hello World program in assembly language, but without the BS section

00:15.750 --> 00:17.860
and without the make file.

00:17.880 --> 00:24.320
But in this lecture we added this to knowledge into our brains and we will start our programming.

00:24.330 --> 00:30.150
So generations of programmers have started their programming careers by learning how to display Hello

00:30.150 --> 00:31.850
World on a computer screen.

00:31.860 --> 00:39.240
It is a tradition that was started in the 70s by brain koningen In the book he wrote with Dennis Ritchie

00:39.330 --> 00:45.270
the C programming language, Cunningham developed the C programming language at Bell Labs.

00:45.270 --> 00:53.130
Since then, the C language has changed a lot, but has remained the language that every self-respecting

00:53.130 --> 00:54.930
programmer should be familiar with.

00:54.960 --> 01:01.390
The majority of modern and fancy programming languages have their roots in C, and C is sometimes called

01:01.390 --> 01:06.760
a portable assembly language, and as an aspiring assembler programmer, you should get familiar with

01:06.790 --> 01:08.560
C to honor the tradition.

01:08.560 --> 01:13.570
We will start with an assembler program to put Hello World on your screen and we will also develop the

01:13.570 --> 01:14.290
Makefile.

01:14.290 --> 01:18.610
So let's get started with developing Hello dot CSM here.

01:18.610 --> 01:25.510
So instead of writing this again, we can also um, as you can see we have three Hello world here.

01:25.510 --> 01:35.340
So erm delete, everything starts with H here and here we will open the our fasm which is the IDE or

01:35.440 --> 01:38.770
CSM and here we will create a new project.

01:38.770 --> 01:45.430
And in this new project we will save this in our assembly here.

01:46.150 --> 01:46.720
That's it.

01:46.720 --> 01:48.970
And we will name it as.

01:54.470 --> 01:55.410
Not RSM.

01:56.130 --> 01:57.000
And that's it.

01:57.120 --> 02:05.220
And here we will delete the auto generate generated code by sacem and we will add new command and we

02:05.220 --> 02:13.230
will create our Hello, SSR, ESM, and we will add a section data section data.

02:13.380 --> 02:18.300
Again, MSG, DB here again.

02:18.780 --> 02:19.440
Hello.

02:21.250 --> 02:24.100
World is okay, I think.

02:24.100 --> 02:32.440
And also we will add a null terminated string here and we will also add the section VSS and we will

02:32.440 --> 02:34.930
also create a section text.

02:34.930 --> 02:39.760
And in this lecture we will create again a global main.

02:39.760 --> 02:47.380
So if you remember, this code is different from the code we created in previous lecture and we will

02:47.380 --> 02:49.300
create our main function here.

02:49.450 --> 02:52.150
Main move here.

02:52.480 --> 02:53.350
Move.

02:55.210 --> 02:57.490
AX1.

02:57.910 --> 03:01.150
And also let's add the spaces between this.

03:03.050 --> 03:04.550
Our x one.

03:04.640 --> 03:09.110
This one corresponds for the right and move.

03:09.790 --> 03:10.510
Are.

03:14.450 --> 03:16.880
Move are the I.

03:18.230 --> 03:18.920
One.

03:18.920 --> 03:22.220
This is for the STD out.

03:24.350 --> 03:26.600
Out and we will also create the.

03:28.490 --> 03:28.820
Move.

03:30.830 --> 03:31.820
RSI.

03:32.940 --> 03:34.410
MCG here.

03:34.410 --> 03:39.510
As you can see here, we will get this variable name MCG.

03:39.750 --> 03:49.430
This is the string to display in RSA and we will also move here the RDX.

03:49.530 --> 03:54.150
This is the length of the string without the zero here.

03:54.390 --> 03:59.820
So this is the length of the string without zero.

03:59.820 --> 04:02.220
And we will call the fiscal.

04:02.370 --> 04:06.750
In this case, this fiscal will display the string on this here.

04:07.020 --> 04:08.340
Display the.

04:09.280 --> 04:11.260
Ring and move.

04:12.760 --> 04:14.830
Racks here 60.

04:14.860 --> 04:17.200
This is for exit code here.

04:17.560 --> 04:21.340
60 equals to exit and move.

04:21.550 --> 04:22.360
Ready?

04:22.960 --> 04:23.740
Zero.

04:23.740 --> 04:30.280
And this is this means the success exit code here that our program.

04:31.340 --> 04:32.870
With success here.

04:33.200 --> 04:35.630
It says exit code.

04:35.630 --> 04:38.000
And we will also add t-sql.

04:38.030 --> 04:40.040
This will quit the program.

04:43.160 --> 04:46.880
That here, this is the last line of our code.

04:47.000 --> 04:52.640
And so there are many good text editors on the market, both free and commercial.

04:52.640 --> 05:01.400
In this case, we will use CSM, which is a free and look one that supports syntax highlighting for

05:01.940 --> 05:02.630
64 bit.

05:02.630 --> 05:10.220
In this case, CSM is fully supports 64 bit and in most cases you will have to download some kind of

05:10.220 --> 05:11.420
plugin if you.

05:12.120 --> 05:16.290
Get it or uh, any other text editors to have syntax highlighting.

05:16.290 --> 05:23.010
But in, in s m the syntax highlighting come with pre-installed.

05:23.400 --> 05:28.860
And in this course we will write code for the netwide assembler here.

05:28.860 --> 05:32.310
Let's actually write this right now.

05:32.340 --> 05:37.710
Grommit np x This is for the writing things on the screen.

05:38.540 --> 05:46.040
So in this course we will write the code for Netwide assembler and.

05:46.640 --> 05:47.300
A.

05:48.110 --> 05:49.030
S.

05:49.250 --> 05:49.880
M.

05:50.780 --> 05:53.750
So there are other assemblers as well, such as.

05:53.900 --> 05:59.300
Y a s m f a s m gas or m a m from the Microsoft.

05:59.300 --> 06:05.030
And as with everything in the computer world, there are sometimes heavy discussions about which assembler

06:05.030 --> 06:14.150
is the best, and we will use an ASM in this course because it is available on Linux, Windows and Mac

06:14.150 --> 06:15.080
OS.

06:15.440 --> 06:19.970
This is available on Windows and Linux.

06:21.080 --> 06:24.670
And in Mac OS.

06:26.230 --> 06:27.940
Mac OS.

06:28.800 --> 06:31.140
And so this is one of the best.

06:32.960 --> 06:38.750
Assemblers here and RSM And because there are and also there is a.

06:38.770 --> 06:48.790
Large community using an RSM, you can find the the manual at the nasm.us and we can also use the jedit

06:48.790 --> 06:53.590
with an assembler language syntax file installed so you can find.

06:55.070 --> 06:57.980
The assembly language for the Jets as well.

06:57.980 --> 07:05.390
But in this case, as I said, M is a best idea for assembly and it's also free and open source.

07:05.390 --> 07:12.410
And here on our screen, the Hello dot Asem file is shown here.

07:12.410 --> 07:19.160
And as you can see here, we think that you will agree that syntax highlighting makes the assembler

07:19.160 --> 07:20.780
code a little bit easier to read.

07:20.780 --> 07:27.590
So when we're when we write assembly programs, we have two windows open on our screen, a windows with

07:27.590 --> 07:33.710
the IDE or text editor containing our assembler source code and the windows with a command prompt in

07:33.710 --> 07:38.450
the project directory so that we can easily switch between the editing and manipulating the project

07:38.450 --> 07:41.840
file and assembling a program, debugging and so on.

07:41.840 --> 07:45.770
And we agree that for more complex and larger project, this is not feasible.

07:45.770 --> 07:48.890
So you will need an integrated development environment.

07:48.920 --> 07:56.820
Ida But for now, working with a simple or text editor and the command line in other words, CLI will

07:56.820 --> 08:01.920
do our job and we will improve that in next lectures as well.

08:02.860 --> 08:07.090
And here we will also need the GCC for installing this.

08:07.720 --> 08:13.870
Installing GCC is one of the simplest things to do in developing assembly languages.

08:13.870 --> 08:22.120
So GCC stands for new compiler collection and this is the standard compiler and linker tool Linux.

08:22.120 --> 08:27.070
So Genius stands for it's not Unix and it's a recursive acronym.

08:27.070 --> 08:33.430
Using the recursive acronyms for naming things is an insider programmer joke that started in the 70s

08:33.430 --> 08:37.030
by Lisp programmers and the GCC.

08:37.630 --> 08:41.980
So firstly, of course we need to install GCC here.

08:41.980 --> 08:43.390
Sudo apt.

08:44.510 --> 08:46.180
Install DCC.

08:46.250 --> 08:46.730
That's it.

08:46.730 --> 08:48.590
Enter your pseudo password and that's it.

08:48.590 --> 08:49.730
As you can see, I'm installed.

08:49.730 --> 08:54.260
But now let's actually remove the DCC again.

08:54.260 --> 08:58.130
So the APT remove DCC here.

08:58.160 --> 08:59.090
Yes.

08:59.090 --> 09:02.930
So this is a pretty easy to install here.

09:06.220 --> 09:10.150
And here we will also need to use bool essential.

09:10.540 --> 09:19.180
And here now we will install the GCC again actually clear the terminal and so sudo apt install GCC.

09:19.210 --> 09:19.930
That's it.

09:19.930 --> 09:22.750
And this is easy as that.

09:22.750 --> 09:25.300
And as you can see GCC is already installed.

09:25.300 --> 09:29.920
So we will also need to install the nasm here.

09:29.920 --> 09:38.610
Sudo apt build, essential ascent shell and NSM.

09:38.680 --> 09:42.880
So actually let's actually first install it, remove our purge here.

09:42.880 --> 09:44.080
So we will remove it.

09:44.080 --> 09:49.450
As you can see, 556 disk space will be freed.

09:55.340 --> 09:56.660
And now pseudo.

09:59.920 --> 10:05.170
Sudo apt install build essential.

10:06.290 --> 10:07.760
And ask again.

10:07.760 --> 10:09.410
And as you can see here.

10:14.550 --> 10:15.120
Here.

10:16.260 --> 10:17.310
And that's it.

10:18.430 --> 10:22.780
So we have the essential and and also we have the GKE.

10:22.900 --> 10:29.170
So in order to check that, we will write GKE V here and as you can see here, using Boolean spec.

10:29.170 --> 10:37.330
So if you use if you are seeing this, this is a version Debian, then this means that GKE is installed

10:37.420 --> 10:40.360
and we will also check the V here.

10:40.360 --> 10:44.620
And as you can see in version 22.60.01.

10:44.620 --> 10:48.190
So NSM is also successfully installed.

10:48.550 --> 10:51.370
And now let's go back to our Hello World program.

10:51.370 --> 10:55.990
And this is the complete version of our code.

10:55.990 --> 11:03.850
And after that which we will create this Hello World program without the Makefile.

11:03.850 --> 11:08.560
But as a first lecture, let's create this with a.

11:09.850 --> 11:10.390
Make file.

11:10.390 --> 11:15.520
So if you click on this and as you can see, we have hello Dot Asem, if we open this with our text

11:15.520 --> 11:19.150
editor, you can see our code without syntax highlighting of course.

11:19.150 --> 11:22.780
And now we will go back to terminal here.

11:22.930 --> 11:28.030
Now we will what we will do is we will open the new file torch.

11:29.020 --> 11:31.180
Actually, let's use it with mouse pad.

11:31.570 --> 11:32.380
Mouse.

11:35.060 --> 11:45.860
Uh, so this is going to be Makefile and uh, yes, so here we will delete our old code.

11:45.860 --> 11:48.500
So this is a new file as you can see here.

11:48.890 --> 11:51.960
Clear LZ LA.

11:52.520 --> 11:55.850
Now we will open the make file here with mouse path.

11:56.990 --> 11:57.920
And that's it.

11:57.950 --> 12:00.950
Now we will write our make file here.

12:00.950 --> 12:02.810
So make file.

12:04.170 --> 12:05.340
Make file for.

12:05.340 --> 12:06.870
Hello, Esme.

12:07.140 --> 12:07.890
Hello.

12:08.400 --> 12:13.440
Here the hello all and JC all.

12:13.950 --> 12:14.820
Hello.

12:15.120 --> 12:15.510
Hello.

12:15.510 --> 12:16.230
That all?

12:16.230 --> 12:20.100
And we will also know pi argument.

12:20.100 --> 12:22.950
And after that we will use the Hello.

12:22.950 --> 12:24.390
That all here.

12:24.510 --> 12:24.870
Hello.

12:24.870 --> 12:31.640
That And after that we will with the tab here we will add an elf.

12:32.610 --> 12:36.690
For the F warfare.

12:38.070 --> 12:38.790
Hello.

12:39.790 --> 12:40.610
But Assam.

12:40.620 --> 12:44.400
And also we will create a yellow dot here.

12:44.580 --> 12:46.770
And that's it with our make file.

12:46.770 --> 12:50.090
Now we will go back and run.

12:50.100 --> 12:57.300
We will save the this file as a make file in the same directory as Hello Dot Assam.

12:57.570 --> 13:03.360
And also also after writing it, we can close the make file here.

13:03.360 --> 13:10.440
As you can see here, our make file is increased at make file and as it is our make file.

13:10.440 --> 13:11.970
And after that.

13:13.090 --> 13:13.900
Uh, we will.

13:14.430 --> 13:20.350
Um, actually, this, uh, firstly, uh, let's read the make file here, actually, and read it from

13:20.350 --> 13:20.800
here.

13:20.800 --> 13:26.310
So you read the make file from the bottom up to see what's what it is doing.

13:26.320 --> 13:28.900
So here's a simplified explanation here.

13:28.900 --> 13:33.640
So the make utility is open, the make file.

13:33.640 --> 13:35.440
So this make utility.

13:37.560 --> 13:39.200
Uh, works with a dependency tree.

13:39.210 --> 13:40.890
So it noticed that.

13:40.890 --> 13:41.510
Hello?

13:41.520 --> 13:44.190
Depends on Hello, Dot.

13:44.230 --> 13:45.710
All right.

13:45.720 --> 13:47.810
And it sees the Hello.

13:47.810 --> 13:51.310
All depends on Hello, Dot.

13:52.200 --> 13:52.830
And that.

13:52.860 --> 13:55.260
Hello, Asem depends on nothing else.

13:55.260 --> 14:01.320
So make compares the last modification date of Hello dot asem with the hello.

14:01.320 --> 14:02.250
Oh and.

14:02.250 --> 14:11.230
And if the date from hello Asem is more recent make executes the line after hello which is hello dot

14:11.280 --> 14:11.940
asem.

14:11.940 --> 14:20.130
So then make starts reading the make file and finds that the modification date of hello dot oh is more

14:20.130 --> 14:21.420
recent than the date from.

14:21.420 --> 14:21.750
Hello.

14:22.020 --> 14:22.790
Hello.

14:22.800 --> 14:25.950
So it executes the line after hello.

14:25.950 --> 14:27.340
Which is hello.

14:27.340 --> 14:33.720
Oh here and in the bottom line of our make file and is used as the assembler.

14:33.900 --> 14:41.620
So the f is followed by the output format in our case is elf64, which means executable linkable format

14:41.620 --> 14:42.820
for 64 bit.

14:42.820 --> 14:49.390
And the g means that we want to include the include the debug information in a debug format specified

14:49.390 --> 14:58.840
after the F option and we use the var debug format and the software geeks for this format seem to like

14:58.840 --> 15:02.470
The Hobbit and Lord of the Rings written by J.R.R. Tolkien.

15:02.470 --> 15:09.550
So maybe that's why they decided that the var will be a nice compliment to Elf, just in case you were

15:09.550 --> 15:10.090
wondering.

15:10.090 --> 15:13.900
So seriously, the var stands for the debug with arbitrary record format.

15:14.140 --> 15:17.080
The debug with arbitrary the record format.

15:17.710 --> 15:25.780
And stamps in another debug format here, which has nothing to do with all the stabbings in novels.

15:25.780 --> 15:29.460
So the name comes from symbol table strings we will use.

15:29.470 --> 15:33.790
We will not use the steps here so you won't get hurt here.

15:33.790 --> 15:40.000
And this l here tells NASA to generate the LST file.

15:40.150 --> 15:47.830
We will use the LST files to examine the results of the assembly, and NASA will create an object file

15:48.190 --> 15:50.140
with an dot or extension.

15:50.140 --> 15:51.880
And that object file will.

15:53.130 --> 15:56.310
What will next be used by our linker.

15:56.310 --> 16:03.780
And often it will happen that NSM complains a number of cryptic messages and refuses to give you an

16:03.780 --> 16:04.490
object file.

16:04.500 --> 16:10.980
So sometimes NSM will complain so often that it will drive you almost insane.

16:10.980 --> 16:14.480
In use cases, it is essential to keep calm.

16:14.490 --> 16:19.080
You have another coffee and review your code because you did something wrong.

16:19.110 --> 16:24.990
As you as you program more and more in assembly, you will catch mistakes faster.

16:24.990 --> 16:30.600
And when you finally convinced that NSM to give you an object file, this object file is linked with

16:30.600 --> 16:36.570
a linker and a linker takes your object code and searches the system for other files that are needed.

16:36.570 --> 16:40.980
So typically system services are or other object files as well.

16:40.980 --> 16:48.360
So these files are combined with your generated object code by the linker and then an executable file

16:48.360 --> 16:49.050
is produced.

16:49.080 --> 16:56.290
Of course, the linker will take every possible occasion to complain to you about missing things and

16:56.290 --> 16:57.010
so on.

16:57.010 --> 17:02.140
So if that is the case, have another coffee and check your code and make file as well.

17:02.140 --> 17:08.770
In our case, we use the linking functionality of GCC, as you can see here.

17:08.770 --> 17:09.040
Hello.

17:09.040 --> 17:09.310
Hello.

17:09.310 --> 17:13.060
All GCC or hello all know Pi.

17:13.090 --> 17:19.030
So there is an GCC linker and compiler generate position independent executable pis.

17:19.030 --> 17:25.840
So this is to prevent hackers from investigating how memory is used by a program and eventually interfering

17:25.840 --> 17:27.310
with a program execution.

17:27.310 --> 17:32.320
And at this point we will not build a position, independent executables, and it will really complicate

17:32.320 --> 17:36.430
the analysis of our program on purpose for security reasons.

17:36.520 --> 17:40.570
So we added the parameter no Pi in the make file.

17:40.570 --> 17:47.770
And finally, you can insert commands in your Makefile by preceding them with the this hashtag symbols

17:47.770 --> 17:54.970
as we did in first line here, make file for location and we use GCC because of the ease of accessing

17:54.990 --> 17:58.240
C standard library functions from within the assembler code.

17:58.240 --> 18:04.780
And to make life easy we will use C language functions from time to time to simplify the example assembly

18:04.780 --> 18:05.620
code as well.

18:05.620 --> 18:12.340
So just, you know, another popular linker on Linux is LD the linker.

18:13.290 --> 18:17.290
And if the previous paragraphs do not make sense to you, don't worry.

18:17.310 --> 18:18.360
Have a copy.

18:18.390 --> 18:20.140
Copy and carry on.

18:20.160 --> 18:21.180
It is just a background.

18:22.460 --> 18:24.020
Important at this stage.

18:24.200 --> 18:29.510
And here at the command prompt here, we will go back to here.

18:29.510 --> 18:36.380
Let's actually close this and we will go to the directory where you saved our Hello ESM file and your

18:36.380 --> 18:37.070
make file.

18:37.070 --> 18:40.880
In this case, we are in this directory so we won't go anywhere.

18:40.880 --> 18:48.110
So we will type make to assemble and build the program and then run the program by typing.

18:48.110 --> 18:48.470
Hello.

18:48.470 --> 18:51.950
So as you can see, we could Hello here and.

18:52.970 --> 18:58.250
If you see the message Hello world displayed in this screen here.

18:58.280 --> 18:58.940
I'm sorry.

18:59.240 --> 18:59.460
Hello?

18:59.480 --> 19:01.990
With two L and that's it.

19:02.000 --> 19:02.810
Our program works.

19:02.810 --> 19:08.630
So if you see the message Hello world displayed in front of the command prompt, then everything worked

19:08.630 --> 19:09.440
out fine.

19:09.470 --> 19:14.960
Otherwise you made something typing or other error and you need review your source code or mac file.

19:14.960 --> 19:20.000
So refill your cup of coffee and happy debugging.
