Let's come back to, uh, the minimal assembly.
So we wrote, uh, in this first code, we wrote this code where we print hello, and we return zero.
And now this is taking like, almost, uh, 17, uh, KB of size.
But now I will not write a C code.
Maybe sequel is adding so much of extra bytes.
Let's write the same code in assembly.
So here we have starting having data section where we have a string of hello okay.
And then we have a text section.
And this is a start.
We don't have main function.
We are saying start it from here.
And we are directly calling system call.
So we keep the system call number in our register.
And we fill the parameters in the RDA, RSI and RX.
So in this particular order we need to fill RDA contains the file descriptor.
So we are writing on standard out this particular memory.
Uh this particular message.
Hello.
And this is the length of.
So instead of writing write one and hello and seven we are using assembly.
And then we are calling the system call.
And then we are calling 60 uh using this system call.
And we are returning.
We are saying uh x sorry admits it will fill RDA equals to zero.
So we are calling exit system call with return value of zero.
So how do we compile this code which I have in assembly format.
I use Nasm uh Nasm thing LSM application assembler.
And as you can give me Elf 64 human object file.
Uh, hello.
Oh, hello.
Hello, Sam.
And this is an object file.
And I can use elf and H to verify it has number of section headers are reduced to seven.
And number of parameters in the, uh, relocatable file or object file is zero.
Because we can I cannot directly run this dot L.
Right.
It is.
I cannot give permissions and I also I need not work.
It's okay because it does not have any program headers.
It needs program headers.
If I want to run anything, I need to have program headers.
Now I have this, uh, hello dot o.
I need to generate an executable.
I pass it to the linker.
I say give me executable.
Now read elf.
Uh, I can see it will have program headers and how many parameters are added three parameters compared
to the previous uh uh first executable.
It had 13 program headers and 31 uh section headers.
This one is having only six parameters and three six section headers and three program headers.
So some amount of reduction.
And this is working okay.
Uh, our application is working.
Uh, if I see into the size.
Now this.
Hello.
It has reduced to 8.7 KB.
So by writing a simple, uh, assembly code where we don't have dependency on any libraries, we are
directly calling C, we are directly calling system call, which is a API provided by kernel.
By writing the registers, we have reduced from 17 kb to 1617 kb to 8.7 KB, which is a good amount
of reduction, right?
You can also verify using X to see it, but still it has lot of other sections.
What else section it has.
We can verify uh lot of parameters.
It has no program.
It has it has three parameters.
So it is not having any interpreter.
So it is a static library.
So it has three parameters.
One is empty program I mean not mapped to any section.
And it has one segment which is mapped to text section.
So this is where the text section comes and one segment it has mapped to the data section data set.
So this segment is mapped to data section.
This segment is mapped to text section.
So three parameters only are present.
And uh how many sections are present.
So we have text section data section symbol table string table.
And this thing I can still remove I can concentrate on.
Hello.
And now I can reduce the sections to text section and data section.
And my code still works uh in size we can verify should be reduced to a few more bytes.
So now it is from 8.7 KB to we have reduced to 8.3 KB.
And this still working, but is still for this much of assembly.
I need this much of size.
This is not correct.
So and who is taking this much of size right.
I can use again very DLF visit M5 and a or I can say m5 and J what is the text section is printed and
that is.
So this is only the two contents.
Right.
Uh, and this is only this much of opcode.
I need this much of size.
Let's try to reduce more in the next video.
Reduce the size of this executable to a few hundred bytes in the next few.