Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 328 lines (328 sloc) 11.748 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
.\" Title: yasm
.\" Author: Peter Johnson <peter@tortall.net>
.\" Generator: DocBook XSL Stylesheets v1.71.1 <http://docbook.sf.net/>
.\" Date: April 2007
.\" Manual: The Yasm Modular Assembler
.\" Source: Yasm
.\"
.TH "YASM" "1" "April 2007" "Yasm" "The Yasm Modular Assembler"
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.SH "NAME"
yasm \- The Yasm Modular Assembler
.SH "SYNOPSIS"
.HP 5
\fByasm\fR [\fB\-f\ \fR\fB\fIformat\fR\fR] [\fB\-o\ \fR\fB\fIoutfile\fR\fR] [\fB\fIother\ options\fR\fR...] {\fIinfile\fR}
.HP 5
\fByasm\fR \fB\-h\fR
.SH "DESCRIPTION"
.PP
The Yasm Modular Assembler is a portable, retargetable assembler written under the
\(lqnew\(rq
(2 or 3 clause) BSD license. Yasm currently supports the x86 and AMD64 instruction sets, accepts NASM and GAS assembler syntaxes, outputs binary, ELF32, ELF64, COFF, Win32, and Win64 object formats, and generates source debugging information in STABS, DWARF 2, and CodeView 8 formats.
.PP
YASM consists of the
\fByasm\fR
command, libyasm, the core backend library, and a large number of modules. Currently, libyasm and the loadable modules are statically built into the
\fByasm\fR
executable.
.PP
The
\fByasm\fR
command assembles the file infile and directs output to the file
\fIoutfile\fR
if specified. If
\fIoutfile\fR
is not specified,
\fByasm\fR
will derive a default output file name from the name of its input file, usually by appending
\fI.o\fR
or
\fI.obj\fR, or by removing all extensions for a raw binary file. Failing that, the output file name will be
\fIyasm.out\fR.
.PP
If called with an
\fIinfile\fR
of
\(lq\-\(rq,
\fByasm\fR
assembles the standard input and directs output to the file
\fIoutfile\fR, or
\fIyasm.out\fR
if no
\fIoutfile\fR
is specified.
.SH "OPTIONS"
.PP
Many options may be given in one of two forms: either a dash followed by a single letter, or two dashes followed by a long option name. Options are listed in alphabetical order.
.SS "General Options"
.PP
\fB\-a \fR\fB\fIarch\fR\fR or \fB\-\-arch=\fR\fB\fIarch\fR\fR: Select target architecture
.RS 4
Selects the target architecture. The default architecture is
\(lqx86\(rq, which supports both the IA\-32 and derivatives and AMD64 instruction sets. To print a list of available architectures to standard output, use
\(lqhelp\(rq
as
\fIarch\fR. See
\fByasm_arch\fR(7)
for a list of supported architectures.
.RE
.PP
\fB\-f \fR\fB\fIformat\fR\fR or \fB\-\-oformat=\fR\fB\fIformat\fR\fR: Select object format
.RS 4
Selects the output object format. The default object format is
\(lqbin\(rq, which is a flat format binary with no relocation. To print a list of available object formats to standard output, use
\(lqhelp\(rq
as
\fIformat\fR. See
\fByasm_objfmts\fR(7)
for a list of supported object formats.
.RE
.PP
\fB\-g \fR\fB\fIdebug\fR\fR or \fB\-\-dformat=\fR\fB\fIdebug\fR\fR: Select debugging format
.RS 4
Selects the debugging format for debug information. Debugging information can be used by a debugger to associate executable code back to the source file or get data structure and type information. Available debug formats vary between different object formats;
\fByasm\fR
will error when an invalid combination is selected. The default object format is selected by the object format. To print a list of available debugging formats to standard output, use
\(lqhelp\(rq
as
\fIdebug\fR. See
\fByasm_dbgfmts\fR(7)
for a list of supported debugging formats.
.RE
.PP
\fB\-h\fR or \fB\-\-help\fR: Print a summary of options
.RS 4
Prints a summary of invocation options. All other options are ignored, and no output file is generated.
.RE
.PP
\fB\-L \fR\fB\fIlist\fR\fR or \fB\-\-lformat=\fR\fB\fIlist\fR\fR: Select list file format
.RS 4
Selects the format/style of the output list file. List files typically intermix the original source with the machine code generated by the assembler. The default list format is
\(lqnasm\(rq, which mimics the NASM list file format. To print a list of available list file formats to standard output, use
\(lqhelp\(rq
as
\fIlist\fR.
.RE
.PP
\fB\-l \fR\fB\fIlistfile\fR\fR or \fB\-\-list=\fR\fB\fIlistfile\fR\fR: Specify list filename
.RS 4
Specifies the name of the output list file. If this option is not used, no list file is generated.
.RE
.PP
\fB\-m \fR\fB\fImachine\fR\fR or \fB\-\-machine=\fR\fB\fImachine\fR\fR: Select target machine architecture
.RS 4
Selects the target machine architecture. Essentially a subtype of the selected architecture, the machine type selects between major subsets of an architecture. For example, for the
\(lqx86\(rq
architecture, the two available machines are
\(lqx86\(rq, which is used for the IA\-32 and derivative 32\-bit instruction set, and
\(lqamd64\(rq, which is used for the 64\-bit instruction set. This differentiation is required to generate the proper object file for relocatable object formats such as COFF and ELF. To print a list of available machines for a given architecture to standard output, use
\(lqhelp\(rq
as
\fImachine\fR
and the given architecture using
\fB\-a \fR\fB\fIarch\fR\fR. See
\fByasm_arch\fR(7)
for more details.
.RE
.PP
\fB\-o \fR\fB\fIfilename\fR\fR or \fB\-\-objfile=\fR\fB\fIfilename\fR\fR: Specify object filename
.RS 4
Specifies the name of the output file, overriding any default name generated by Yasm.
.RE
.PP
\fB\-p \fR\fB\fIparser\fR\fR or \fB\-\-parser=\fR\fB\fIparser\fR\fR: Select parser
.RS 4
Selects the parser (the assembler syntax). The default parser is
\(lqnasm\(rq, which emulates the syntax of NASM, the Netwide Assembler. Another available parser is
\(lqgas\(rq, which emulates the syntax of GNU AS. To print a list of available parsers to standard output, use
\(lqhelp\(rq
as
\fIparser\fR. See
\fByasm_parsers\fR(7)
for a list of supported parsers.
.RE
.PP
\fB\-r \fR\fB\fIpreproc\fR\fR or \fB\-\-preproc=\fR\fB\fIpreproc\fR\fR: Select preprocessor
.RS 4
Selects the preprocessor to use on the input file before passing it to the parser. Preprocessors often provide macro functionality that is not included in the main parser. The default preprocessor is
\(lqnasm\(rq, which is an imported version of the actual NASM preprocessor. A
\(lqraw\(rq
preprocessor is also available, which simply skips the preprocessing step, passing the input file directly to the parser. To print a list of available preprocessors to standard output, use
\(lqhelp\(rq
as
\fIpreproc\fR.
.RE
.PP
\fB\-\-version\fR: Get the Yasm version
.RS 4
This option causes Yasm to prints the version number of Yasm as well as a license summary to standard output. All other options are ignored, and no output file is generated.
.RE
.SS "Warning Options"
.PP
\fB\-W\fR
options have two contrary forms:
\fB\-W\fR\fB\fIname\fR\fR
and
\fB\-Wno\-\fR\fB\fIname\fR\fR. Only the non\-default forms are shown here.
.PP
The warning options are handled in the order given on the command line, so if
\fB\-w\fR
is followed by
\fB\-Worphan\-labels\fR, all warnings are turned off
\fIexcept\fR
for orphan\-labels.
.PP
\fB\-w\fR: Inhibit all warning messages
.RS 4
This option causes Yasm to inhibit all warning messages. As discussed above, this option may be followed by other options to re\-enable specified warnings.
.RE
.PP
\fB\-Werror\fR: Treat warnings as errors
.RS 4
This option causes Yasm to treat all warnings as errors. Normally warnings do not prevent an object file from being generated and do not result in a failure exit status from
\fByasm\fR, whereas errors do. This option makes warnings equivalent to errors in terms of this behavior.
.RE
.PP
\fB\-Wno\-unrecognized\-char\fR: Do not warn on unrecognized input characters
.RS 4
Causes Yasm to not warn on unrecognized characters found in the input. Normally Yasm will generate a warning for any non\-ASCII character found in the input file.
.RE
.PP
\fB\-Worphan\-labels\fR: Warn on labels lacking a trailing option
.RS 4
When using the NASM\-compatible parser, causes Yasm to warn about labels found alone on a line without a trailing colon. While these are legal labels in NASM syntax, they may be unintentional, due to typos or macro definition ordering.
.RE
.PP
\fB\-X \fR\fB\fIstyle\fR\fR: Change error/warning reporting style
.RS 4
Selects a specific output style for error and warning messages. The default is
\(lqgnu\(rq
style, which mimics the output of
\fBgcc\fR. The
\(lqvc\(rq
style is also available, which mimics the output of Microsoft's Visual C++ compiler.
.sp
This option is available so that Yasm integrates more naturally into IDE environments such as
Visual Studio
or
Emacs, allowing the IDE to correctly recognize the error/warning message as such and link back to the offending line of source code.
.RE
.SS "Preprocessor Options"
.PP
While these preprocessor options theoretically will affect any preprocessor, the only preprocessor currently in Yasm is the
\(lqnasm\(rq
preprocessor.
.PP
\fB\-D \fR\fB\fImacro[=value]\fR\fR: Pre\-define a macro
.RS 4
Pre\-defines a single\-line macro. The value is optional (if no value is given, the macro is still defined, but to an empty value).
.RE
.PP
\fB\-e\fR or \fB\-\-preproc\-only\fR: Only preprocess
.RS 4
Stops assembly after the preprocessing stage; preprocessed output is sent to the specified output name or, if no output name is specified, the standard output. No object file is produced.
.RE
.PP
\fB\-I \fR\fB\fIpath\fR\fR: Add include file path
.RS 4
Adds directory
\fIpath\fR
to the search path for include files. The search path defaults to only including the directory in which the source file resides.
.RE
.PP
\fB\-P \fR\fB\fIfilename\fR\fR: Pre\-include a file
.RS 4
Pre\-includes file
\fIfilename\fR, making it look as though
\fIfilename\fR
was prepended to the input. Can be useful for prepending multi\-line macros that the
\fB\-D\fR
can't support.
.RE
.PP
\fB\-U \fR\fB\fImacro\fR\fR: Undefine a macro
.RS 4
Undefines a single\-line macro (may be either a built\-in macro or one defined earlier in the command line with
\fB\-D\fR.
.RE
.SH "EXAMPLES"
.PP
To assemble NASM syntax, 32\-bit x86 source
\fIsource.asm\fR
into ELF file
\fIsource.o\fR, warning on orphan labels:
.sp
.RS 4
.nf
yasm \-f elf32 \-Worphan\-labels source.asm
.fi
.RE
.PP
To assemble NASM syntax AMD64 source
\fIx.asm\fR
into Win64 file
\fIobject.obj\fR:
.sp
.RS 4
.nf
yasm \-f win64 \-o object.obj x.asm
.fi
.RE
.PP
To assemble already preprocessed NASM syntax x86 source
\fIy.asm\fR
into flat binary file
\fIy.com\fR:
.sp
.RS 4
.nf
yasm \-f bin \-r raw \-o y.com y.asm
.fi
.RE
.SH "DIAGNOSTICS"
.PP
The
\fByasm\fR
command exits 0 on success, and nonzero if an error occurs.
.SH "COMPATIBILITY"
.PP
Yasm's NASM parser and preprocessor, while they strive to be as compatible as possible with NASM, have a few incompatibilities due to YASM's different internal structure.
.PP
Yasm's GAS parser and preprocessor are missing a number of features present in GNU AS.
.SH "RESTRICTIONS"
.PP
As object files are often architecture and machine dependent, not all combinations of object formats, architectures, and machines are legal; trying to use an invalid combination will result in an error.
.PP
There is no support for symbol maps.
.SH "SEE ALSO"
.PP
\fByasm_arch\fR(7),
\fByasm_dbgfmts\fR(7),
\fByasm_objfmts\fR(7),
\fByasm_parsers\fR(7)
.PP
Related tools:
\fBas\fR(1),
\fBld\fR(1),
\fBnasm\fR(1)
.SH "BUGS"
.PP
When using the
\(lqx86\(rq
architecture, it is overly easy to generate AMD64 code (using the
\fBBITS 64\fR
directive) and generate a 32\-bit object file (by failing to specify
\fB\-m amd64\fR
or selecting a 64\-bit object format such as ELF64 on the command line).
.SH "AUTHOR"
.PP
\fBPeter Johnson\fR <\&peter@tortall.net\&>
.sp -1n
.IP "" 4
Author.
.SH "COPYRIGHT"
Copyright \(co 2004, 2005, 2006, 2007 Peter Johnson
.br
Something went wrong with that request. Please try again.