Back to basics!
Variety is a good thing in life!. Well, to me it is not always.
Back in the days, when it was almost a requirement to code some parts of your software in assembler and some other parts in C, it was always the question what library you include when you use the link editor to link several such object files into a program. For example, if I don't use any math routines, I don't need to include the math lib but the standard c runtime is automatically included.
Now when you come down to craft a little program in assembly language, it again pops up in strange ways !!!
An example at hand is to use the AT&T as assembler in Mac OS X and Linux. Under linux one will cook up a function like the following -
#exit.s file
.section data
#data section
.section .text
.globl _start
movl $1, %eax #sys call number for exit
movl $0, %ebx # ret code stored in ebx
int $0x80 # system call interrupt
----
So nothing fancy, this routine by itself a program. Using the following commands
as exit.s -o exit.o
ld exit.o -o exit
I should have the program ready. But if you take this and try to use it on Mac OS X, it would surely complain when you assemble using 'as' command. Once you get over that problem, the linker would complain too.
If you dealt with these problems, you will see symbols like main, _main, __main, start, _start, __start and what have you.
First the assemble would complain that it needs a comma after the section definitions, so you add the commas in two section assembler directives. Now compiler is happy to produce the object file.
Now if you try the link-edit phase, again you will run into quite a few problem. First it would say oops, I can not seem to find the crt1.o object file. Uh, I thought I don't need to mention anything about c runtime, right? Where the heck c runtime comes from? Then after couple round of circus if I say the following -
ld exit.o -lc -o exit
I get the link-editor to get out of that crt1.o not found. Now I will have to tackle about the symbol 'start', but I did put '_start' since that is what linux would take without complaining. So what I do is to take what you like
.globl start, _start
start:
_start:
That it, now I can assemble and test that little program.
References (2)
-
Response: cv writerThis is very interesting that you shared this gain especially for those who are having some weak points on the grip of this subject. This is very nice that you are providing the all that is having the useful knowledge about that.
-
Response: gmail email login
Reader Comments