Chapter 7. bin: Flat-Form Binary Output

Table of Contents

7.1. ORG: Binary Origin
7.2. bin Extensions to the SECTION Directive
7.3. bin Special Symbols
7.4. Map Files

The bin object format does not produce object files: the output file produced contains only the section data; no headers or relocations are generated. The output can be considered plain binary, and is useful for operating system and boot loader development, generating MS-DOS .COM executables and .SYS device drivers, and creating images for embedded target environments (e.g. Flash ROM).

The bin object format supports an unlimited number of named sections. See Section 7.2 for details. The only restriction on these sections is that their storage locations in the output file cannot overlap.

When used with the x86 architecture, the bin object format starts Yasm in 16-bit mode. In order to write native 32-bit or 64-bit code, an explicit BITS 32 or BITS 64 directive is required respectively.

bin produces an output file with no extension by default; it simply strips the extension from the input file name. Thus the default output filename for the input file foo.asm is simply foo.

7.1. ORG: Binary Origin

bin provides the ORG directive in NASM syntax to allow setting of the memory address at which the output file is initially loaded. The ORG directive may only be used once (as the output file can only be initially loaded into a single location). If ORG is not specified, ORG 0 is used by default.

This makes the operation of NASM-syntax ORG very different from the operation of ORG in other assemblers, which typically simply move the assembly location to the value given. bin provides a more powerful alternative in the form of extensions to the SECTION directive; see Section 7.2 for details.

When combined with multiple sections, ORG also has the effect of defaulting the LMA of the first section to the ORG value to make the output file as small as possible. If this is not the desired behavior, explicitly specify a LMA for all sections via either START or FOLLOWS qualifiers in the SECTION directive.