Hello, my name is Stephan.
And in this lecture we will create our Hello World program again.
But in this time we will use the make file.
In previous lecture we created our Hello World program in assembly language, but without the BS section
and without the make file.
But in this lecture we added this to knowledge into our brains and we will start our programming.
So generations of programmers have started their programming careers by learning how to display Hello
World on a computer screen.
It is a tradition that was started in the 70s by brain koningen In the book he wrote with Dennis Ritchie
the C programming language, Cunningham developed the C programming language at Bell Labs.
Since then, the C language has changed a lot, but has remained the language that every self-respecting
programmer should be familiar with.
The majority of modern and fancy programming languages have their roots in C, and C is sometimes called
a portable assembly language, and as an aspiring assembler programmer, you should get familiar with
C to honor the tradition.
We will start with an assembler program to put Hello World on your screen and we will also develop the
Makefile.
So let's get started with developing Hello dot CSM here.
So instead of writing this again, we can also um, as you can see we have three Hello world here.
So erm delete, everything starts with H here and here we will open the our fasm which is the IDE or
CSM and here we will create a new project.
And in this new project we will save this in our assembly here.
That's it.
And we will name it as.
Not RSM.
And that's it.
And here we will delete the auto generate generated code by sacem and we will add new command and we
will create our Hello, SSR, ESM, and we will add a section data section data.
Again, MSG, DB here again.
Hello.
World is okay, I think.
And also we will add a null terminated string here and we will also add the section VSS and we will
also create a section text.
And in this lecture we will create again a global main.
So if you remember, this code is different from the code we created in previous lecture and we will
create our main function here.
Main move here.
Move.
AX1.
And also let's add the spaces between this.
Our x one.
This one corresponds for the right and move.
Are.
Move are the I.
One.
This is for the STD out.
Out and we will also create the.
Move.
RSI.
MCG here.
As you can see here, we will get this variable name MCG.
This is the string to display in RSA and we will also move here the RDX.
This is the length of the string without the zero here.
So this is the length of the string without zero.
And we will call the fiscal.
In this case, this fiscal will display the string on this here.
Display the.
Ring and move.
Racks here 60.
This is for exit code here.
60 equals to exit and move.
Ready?
Zero.
And this is this means the success exit code here that our program.
With success here.
It says exit code.
And we will also add t-sql.
This will quit the program.
That here, this is the last line of our code.
And so there are many good text editors on the market, both free and commercial.
In this case, we will use CSM, which is a free and look one that supports syntax highlighting for
64 bit.
In this case, CSM is fully supports 64 bit and in most cases you will have to download some kind of
plugin if you.
Get it or uh, any other text editors to have syntax highlighting.
But in, in s m the syntax highlighting come with pre-installed.
And in this course we will write code for the netwide assembler here.
Let's actually write this right now.
Grommit np x This is for the writing things on the screen.
So in this course we will write the code for Netwide assembler and.
A.
S.
M.
So there are other assemblers as well, such as.
Y a s m f a s m gas or m a m from the Microsoft.
And as with everything in the computer world, there are sometimes heavy discussions about which assembler
is the best, and we will use an ASM in this course because it is available on Linux, Windows and Mac
OS.
This is available on Windows and Linux.
And in Mac OS.
Mac OS.
And so this is one of the best.
Assemblers here and RSM And because there are and also there is a.
Large community using an RSM, you can find the the manual at the nasm.us and we can also use the jedit
with an assembler language syntax file installed so you can find.
The assembly language for the Jets as well.
But in this case, as I said, M is a best idea for assembly and it's also free and open source.
And here on our screen, the Hello dot Asem file is shown here.
And as you can see here, we think that you will agree that syntax highlighting makes the assembler
code a little bit easier to read.
So when we're when we write assembly programs, we have two windows open on our screen, a windows with
the IDE or text editor containing our assembler source code and the windows with a command prompt in
the project directory so that we can easily switch between the editing and manipulating the project
file and assembling a program, debugging and so on.
And we agree that for more complex and larger project, this is not feasible.
So you will need an integrated development environment.
Ida But for now, working with a simple or text editor and the command line in other words, CLI will
do our job and we will improve that in next lectures as well.
And here we will also need the GCC for installing this.
Installing GCC is one of the simplest things to do in developing assembly languages.
So GCC stands for new compiler collection and this is the standard compiler and linker tool Linux.
So Genius stands for it's not Unix and it's a recursive acronym.
Using the recursive acronyms for naming things is an insider programmer joke that started in the 70s
by Lisp programmers and the GCC.
So firstly, of course we need to install GCC here.
Sudo apt.
Install DCC.
That's it.
Enter your pseudo password and that's it.
As you can see, I'm installed.
But now let's actually remove the DCC again.
So the APT remove DCC here.
Yes.
So this is a pretty easy to install here.
And here we will also need to use bool essential.
And here now we will install the GCC again actually clear the terminal and so sudo apt install GCC.
That's it.
And this is easy as that.
And as you can see GCC is already installed.
So we will also need to install the nasm here.
Sudo apt build, essential ascent shell and NSM.
So actually let's actually first install it, remove our purge here.
So we will remove it.
As you can see, 556 disk space will be freed.
And now pseudo.
Sudo apt install build essential.
And ask again.
And as you can see here.
Here.
And that's it.
So we have the essential and and also we have the GKE.
So in order to check that, we will write GKE V here and as you can see here, using Boolean spec.
So if you use if you are seeing this, this is a version Debian, then this means that GKE is installed
and we will also check the V here.
And as you can see in version 22.60.01.
So NSM is also successfully installed.
And now let's go back to our Hello World program.
And this is the complete version of our code.
And after that which we will create this Hello World program without the Makefile.
But as a first lecture, let's create this with a.
Make file.
So if you click on this and as you can see, we have hello Dot Asem, if we open this with our text
editor, you can see our code without syntax highlighting of course.
And now we will go back to terminal here.
Now we will what we will do is we will open the new file torch.
Actually, let's use it with mouse pad.
Mouse.
Uh, so this is going to be Makefile and uh, yes, so here we will delete our old code.
So this is a new file as you can see here.
Clear LZ LA.
Now we will open the make file here with mouse path.
And that's it.
Now we will write our make file here.
So make file.
Make file for.
Hello, Esme.
Hello.
Here the hello all and JC all.
Hello.
That all?
And we will also know pi argument.
And after that we will use the Hello.
That all here.
Hello.
That And after that we will with the tab here we will add an elf.
For the F warfare.
Hello.
But Assam.
And also we will create a yellow dot here.
And that's it with our make file.
Now we will go back and run.
We will save the this file as a make file in the same directory as Hello Dot Assam.
And also also after writing it, we can close the make file here.
As you can see here, our make file is increased at make file and as it is our make file.
And after that.
Uh, we will.
Um, actually, this, uh, firstly, uh, let's read the make file here, actually, and read it from
here.
So you read the make file from the bottom up to see what's what it is doing.
So here's a simplified explanation here.
So the make utility is open, the make file.
So this make utility.
Uh, works with a dependency tree.
So it noticed that.
Hello?
Depends on Hello, Dot.
All right.
And it sees the Hello.
All depends on Hello, Dot.
And that.
Hello, Asem depends on nothing else.
So make compares the last modification date of Hello dot asem with the hello.
Oh and.
And if the date from hello Asem is more recent make executes the line after hello which is hello dot
asem.
So then make starts reading the make file and finds that the modification date of hello dot oh is more
recent than the date from.
Hello.
So it executes the line after hello.
Which is hello.
Oh here and in the bottom line of our make file and is used as the assembler.
So the f is followed by the output format in our case is elf64, which means executable linkable format
for 64 bit.
And the g means that we want to include the include the debug information in a debug format specified
after the F option and we use the var debug format and the software geeks for this format seem to like
The Hobbit and Lord of the Rings written by J.R.R. Tolkien.
So maybe that's why they decided that the var will be a nice compliment to Elf, just in case you were
wondering.
So seriously, the var stands for the debug with arbitrary record format.
The debug with arbitrary the record format.
And stamps in another debug format here, which has nothing to do with all the stabbings in novels.
So the name comes from symbol table strings we will use.
We will not use the steps here so you won't get hurt here.
And this l here tells NASA to generate the LST file.
We will use the LST files to examine the results of the assembly, and NASA will create an object file
with an dot or extension.
And that object file will.
What will next be used by our linker.
And often it will happen that NSM complains a number of cryptic messages and refuses to give you an
object file.
So sometimes NSM will complain so often that it will drive you almost insane.
In use cases, it is essential to keep calm.
You have another coffee and review your code because you did something wrong.
As you as you program more and more in assembly, you will catch mistakes faster.
And when you finally convinced that NSM to give you an object file, this object file is linked with
a linker and a linker takes your object code and searches the system for other files that are needed.
So typically system services are or other object files as well.
So these files are combined with your generated object code by the linker and then an executable file
is produced.
Of course, the linker will take every possible occasion to complain to you about missing things and
so on.
So if that is the case, have another coffee and check your code and make file as well.
In our case, we use the linking functionality of GCC, as you can see here.
Hello.
All GCC or hello all know Pi.
So there is an GCC linker and compiler generate position independent executable pis.
So this is to prevent hackers from investigating how memory is used by a program and eventually interfering
with a program execution.
And at this point we will not build a position, independent executables, and it will really complicate
the analysis of our program on purpose for security reasons.
So we added the parameter no Pi in the make file.
And finally, you can insert commands in your Makefile by preceding them with the this hashtag symbols
as we did in first line here, make file for location and we use GCC because of the ease of accessing
C standard library functions from within the assembler code.
And to make life easy we will use C language functions from time to time to simplify the example assembly
code as well.
So just, you know, another popular linker on Linux is LD the linker.
And if the previous paragraphs do not make sense to you, don't worry.
Have a copy.
Copy and carry on.
It is just a background.
Important at this stage.
And here at the command prompt here, we will go back to here.
Let's actually close this and we will go to the directory where you saved our Hello ESM file and your
make file.
In this case, we are in this directory so we won't go anywhere.
So we will type make to assemble and build the program and then run the program by typing.
Hello.
So as you can see, we could Hello here and.
If you see the message Hello world displayed in this screen here.
I'm sorry.
Hello?
With two L and that's it.
Our program works.
So if you see the message Hello world displayed in front of the command prompt, then everything worked
out fine.
Otherwise you made something typing or other error and you need review your source code or mac file.
So refill your cup of coffee and happy debugging.