NASM f elf g F stabs
The name of the source code file to be assembled.
Specifies that debug information is to be generated in the "stabs" format.
Specifies that debug information is to be included in the .o file.
Specifies that the .o file will be generated in the "elf" format.
Invokes the assembler
Figure 5-11: The anatomy of a NASM command line
-f elf: There are a fair number of useful object file formats, and each one is generated differently. The NASM assembler is capable of generating most of them, including other formats, such as bin, aout, coff, and ELF64, that you probably won't need, at least for awhile. The -f command tells NASM which format to use for the object code file it's about to generate. In 32-bit IA-32 Linux work, the format is ELF32, which can be specified on the command line as simply elf.
-g: While you're still working on a program, you want to have debugging information embedded in the object code file so that you can use a debugger to spot problems. (More on how this is done shortly.) The -g command tells NASM to include debugging information in the output file.
-F stabs: As with the output file, there are different formats in which NASM can generate debug information. Again, as with the output file format, if you're working in IA-32 Linux, you'll probably be using the STABS format for debug information, at least while you're starting out. There is a more powerful debug format called DWARF that can also be used with ELF (get it?), and NASM will generate DWARF data instead of STABS data if you replace ''stabs'' with ''dwarf'' in this command. Remember too that Linux commands are case sensitive. The -f command and the -f command are distinct, so watch that Shift key!
eatsyscall.asm: The last item on the NASM command line is always the name of file to be assembled. Again, as with everything in Linux, the filename is case sensitive. EATSYSCALL.ASM and EatSysCall.asm (as well as all other case variations) are considered entirely different files.
Unless you give NASM other orders, it will generate an object code file and name it using the name of the source code file and the file extension .O. The ''other orders'' are given through the -o option. If you include a -o command in a NASM command line, it must be followed by a filename, which is the name you wish NASM to give to the generated object code file. For example:
nasm -f elf -g -F stabs eatsyscall.asm -o eatdemo.o
Here, NASM will assemble the source file eatsyscall.asm to the object code file eatdemo.o.
Now, before moving on to the link step, verify that the object code file has been created by using the ls command to list your working directory contents. The file eatsyscall.o should be there.
Continue reading here: Step 3 Link the Program with LD
Was this article helpful?