phoenix <spamtrap@[EMAIL PROTECTED]
> wrote:
>
>I am a complete newbie who is trying to learn assembly. I am using
>NASM and working on Linux.
>I have written a (very) simple program that calculates ah+al.
>...
>So I type in the terminal: nasm -f elf ass.s -o ass.o
>and then I type: gcc ass.o -o as***e
>
>An error message appears:
>/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/crt1.o: In function
>`_start':
>(.text+0x18): undefined reference to `main'
>collect2: ld returned 1 exit status
>
>If the label (in the program) is called main (and not prog), there's
>no error message.
>If the label is called start, the error message appears again.
>
>My question is: can I choose whatever label names in my program,
>without having all these error messages? Or am I forced to always
>insert a label called "main" in my code?
When you are writing a function that will be called by other code, you can
name it whatever you want to, as long as both sides agree on the names.
In this case, however, there is another player involved. When you run a
program from a command line, the system loads your program into memory and
starts it by jumping to a special address called the "transfer address".
When you use "gcc" to link your code, "gcc" assumes that you are using the
C run-time library, so it arranges that the "transfer address" points to a
startup function in the C run-time library. That startup function
initializes a bunch of stuff in the library, and then calls a function
called "main". Every C program must include a function called "main",
which receives the command-line arguments and does the main processing.
When "main" returns, the program ends.
So, if you want to use "gcc" to link your code (and that's a reasonable
thing to do when you are learning assembly, because it lets you use
convenient functions like printf), then your main entry point will have to
be called "main".
The code you wrote is not really a "program", because it doesn't do
anything with the result of the addition. It is more of a function that
is
designed to be called by someone else. If you were calling this from a C
main program, you could call it "prog", and your "main" would be in the C
file.
--
Tim Roberts, timr@[EMAIL PROTECTED]
& Boekelheide, Inc.


|