Output formats: bin, elf, elf64
| The common formats | |
| elf64 and elf32 | |
| bin: flat binary |
The common formats
The -f flag selects the output format. elf64 is the default target for Linux programs, elf32 for 32-bit objects, win64 for Windows, macho64 for macOS, and bin for a flat raw binary:
nasm -f elf64 -o prog.o prog.asm
nasm -f bin -o boot.bin boot.asm
elf64 and elf32
ELF objects carry section and symbol tables, so the linker can place and rename them. Every lesson so far used elf64. The 32-bit format differs in register assignment for syscalls (int 0x80 with EAX and EBX).
bin: flat binary
bin emits exactly the bytes you assembled, with no headers. That is what a boot sector needs: 512 bytes ending in the 0xAA55 signature. The origin point is set with the bits and org directives, because there is no header to say where the code lives.
Next: Advanced macros and %include
Article author: Arthur Isaev