Clean up some more _GENERIC___ contexts.
[binutils-gdb.git] / gas / doc / as.texinfo
1 \input texinfo
2 @c @tex
3 @c \special{twoside}
4 @c @end tex
5 _if__(_GENERIC__)
6 @setfilename as.info
7 _fi__(_GENERIC__)
8 _if__(_AMD29K__ && !_GENERIC__)
9 @setfilename as-29k.info
10 _fi__(_AMD29K__ && !_GENERIC__)
11 _if__(_I960__ && !_GENERIC__)
12 @setfilename as-960.info
13 _fi__(_I960__ && !_GENERIC__)
14 _if__(_M680X0__ && !_GENERIC__)
15 @setfilename as-m680x0.info
16 _fi__(_M680X0__ && !_GENERIC__)
17 _if__(0)
18
19 NOTE: this manual is marked up for preprocessing with a collection
20 of m4 macros called "pretex.m4".
21
22 THIS IS THE FULL SOURCE. The full source needs to be run through m4
23 before either tex- or info- formatting: for example,
24 m4 pretex.m4 none.m4 m680x0.m4 as.texinfo >as-680x0.texinfo
25 will produce (assuming your path finds either GNU or SysV m4; Berkeley
26 won't do) a file suitable for formatting. See the text in "pretex.m4"
27 for a fuller explanation (and the macro definitions).
28
29 _fi__(0)
30 @c
31 @synindex ky cp
32 @ifinfo
33 This file documents the GNU Assembler "_AS__".
34
35 Copyright (C) 1991 Free Software Foundation, Inc.
36
37 Permission is granted to make and distribute verbatim copies of
38 this manual provided the copyright notice and this permission notice
39 are preserved on all copies.
40
41 @ignore
42 Permission is granted to process this file through Tex and print the
43 results, provided the printed document carries copying permission
44 notice identical to this one except for the removal of this paragraph
45 (this paragraph not being relevant to the printed manual).
46
47 @end ignore
48 Permission is granted to copy and distribute modified versions of this
49 manual under the conditions for verbatim copying, provided also that the
50 section entitled ``GNU General Public License'' is included exactly as
51 in the original, and provided that the entire resulting derived work is
52 distributed under the terms of a permission notice identical to this
53 one.
54
55 Permission is granted to copy and distribute translations of this manual
56 into another language, under the above conditions for modified versions,
57 except that the section entitled ``GNU General Public License'' may be
58 included in a translation approved by the Free Software Foundation
59 instead of in the original English.
60 @end ifinfo
61 @iftex
62 @finalout
63 @smallbook
64 @end iftex
65 @setchapternewpage odd
66 _if__(_GENERIC__)
67 @settitle Using _AS__
68 _fi__(_GENERIC__)
69 _if__(!_GENERIC__)
70 @settitle Using _AS__ (_HOST__)
71 _fi__(!_GENERIC__)
72 @titlepage
73 @title{Using _AS__}
74 @subtitle{The GNU Assembler}
75 _if__(!_GENERIC__)
76 @subtitle{for the _HOST__ family}
77 _fi__(!_GENERIC__)
78 @sp 1
79 @subtitle March 1991
80 @sp 1
81 @c pesch@cygnus.com
82 @subtitle edited by Roland Pesch
83 @subtitle for Cygnus Support
84 @sp 13
85 The Free Software Foundation Inc. thanks The Nice Computer
86 Company of Australia for loaning Dean Elsner to write the
87 first (Vax) version of @code{as} for Project GNU.
88 The proprietors, management and staff of TNCCA thank FSF for
89 distracting the boss while they got some work
90 done.
91 @sp 3
92 @author{Dean Elsner, Jay Fenlason & friends}
93 @page
94 @tex
95 \def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
96 \xdef\manvers{\$Revision$} % For use in headers, footers too
97 {\parskip=0pt
98 \hfill Cygnus Support\par
99 \hfill \manvers\par
100 \hfill \TeX{}info \texinfoversion\par
101 }
102 %"boxit" macro for figures:
103 %Modified from Knuth's ``boxit'' macro from TeXbook (answer to exercise 21.3)
104 \gdef\boxit#1#2{\vbox{\hrule\hbox{\vrule\kern3pt
105 \vbox{\parindent=0pt\parskip=0pt\hsize=#1\kern3pt\strut\hfil
106 #2\hfil\strut\kern3pt}\kern3pt\vrule}\hrule}}%box with visible outline
107 \gdef\ibox#1#2{\hbox to #1{#2\hfil}\kern8pt}% invisible box
108 @end tex
109
110 @vskip 0pt plus 1filll
111 Copyright @copyright{} 1991 Free Software Foundation, Inc.
112
113 Permission is granted to make and distribute verbatim copies of
114 this manual provided the copyright notice and this permission notice
115 are preserved on all copies.
116
117 Permission is granted to copy and distribute modified versions of this
118 manual under the conditions for verbatim copying, provided also that the
119 section entitled ``GNU General Public License'' is included exactly as
120 in the original, and provided that the entire resulting derived work is
121 distributed under the terms of a permission notice identical to this
122 one.
123
124 Permission is granted to copy and distribute translations of this manual
125 into another language, under the above conditions for modified versions,
126 except that the section entitled ``GNU General Public License'' may be
127 included in a translation approved by the Free Software Foundation
128 instead of in the original English.
129 @end titlepage
130 @page
131 @node Top,,,
132 @ifinfo
133 This file is a user guide to the GNU assembler @code{_AS__}.
134 _if__(!_GENERIC__)
135 This version of the file describes @code{_AS__} configured to generate
136 code for _HOST__ architectures.
137 _fi__(!_GENERIC__)
138 @end ifinfo
139 @node Overview,,,
140 @chapter Overview
141 @iftex
142 This manual is a user guide to the GNU assembler @code{_AS__}.
143 _if__(!_GENERIC__)
144 This version of the manual describes @code{_AS__} configured to generate
145 code for _HOST__ architectures.
146 _fi__(!_GENERIC__)
147 @end iftex
148
149 @node Invoking,,,
150 @section Invoking @code{_AS__}
151
152 Here is a brief summary of how to invoke @code{_AS__}. For details,
153 @pxref{Options}.
154
155 @c We don't use @deffn and friends for the following because they seem
156 @c to be limited to one line for the header.
157 @smallexample
158 _AS__ [ -D ] [ -f ] [ -I @var{path} ] [ -k ] [ -L ]
159 [ -o @var{objfile} ] [ -R ] [ -v ] [ -w ]
160 _if__(_AMD29K__)
161 @c am29k has no machine-dependent assembler options
162 _fi__(_AMD29K__)
163 _if__(_I960__)
164 @c see md_parse_option in i960.c
165 [ -ACA | -ACA_A | -ACB | -ACC | -AKA | -AKB | -AKC | -AMC ]
166 [ -b ] [ -norelax ]
167 _fi__(_I960__)
168 _if__(_M680X0__)
169 [ -l ] [ -mc68000 | -mc68010 | -mc68020 ]
170 _fi__(_M680X0__)
171 [ -- | @var{files} @dots{} ]
172 @end smallexample
173
174 @table @code
175
176 @item -D
177 This option is accepted only for script compatibility with calls to
178 other assemblers; it has no effect on @code{_AS__}.
179
180 @item -f
181 ``fast''---skip preprocessing (assume source is compiler output)
182
183 @item -I @var{path}
184 Add @var{path} to the search list for @code{.include} directives
185
186 @item -k
187 _if__((!_GENERIC__) && (_AMD29K__ || _I960__))
188 This option is accepted but has no effect on the _HOST__ family.
189 _fi__((!_GENERIC__) && (_AMD29K__ || _I960__))
190 _if__(_GENERIC__)
191 Issue warnings when difference tables altered for long displacements.
192 _fi__(_GENERIC__)
193
194 @item -L
195 Keep (in symbol table) local symbols, starting with @samp{L}
196
197 @item -o @var{objfile}
198 Name the object-file output from @code{_AS__}
199
200 @item -R
201 Fold data segment into text segment
202
203 @item -W
204 Suppress warning messages
205
206 _if__(_I960__)
207 @item -ACA | -ACA_A | -ACB | -ACC | -AKA | -AKB | -AKC | -AMC
208 Specify which variant of the 960 architecture is the target.
209
210 @item -b
211 Add code to collect statistics about branches taken.
212
213 @item -norelax
214 Do not alter compare-and-branch instructions for long displaements;
215 error if necessary.
216 _fi__(_I960__)
217
218 _if__(_M680X0__)
219 @item -l
220 Shorten references to undefined symbols, to one word instead of two
221
222 @item -mc68000 | -mc68010 | -mc68020
223 Specify what processor in the 68000 family is the target (default 68020)
224 _fi__(_M680X0__)
225
226 @item -- | @var{files} @dots{}
227 Source files to assemble, or standard input
228 @end table
229
230 @node Manual, GNU Assembler, Invoking, Overview
231 @section Structure of this Manual
232 This document is intended to describe what you need to know to use
233 @code{_AS__}. We cover the syntax expected in source files, including
234 notation for symbols, constants, and expressions; the directives that
235 @code{_AS__} understands; and of course how to invoke @code{_AS__}.
236
237 _if__(!_GENERIC__)
238 We also cover special features in the _HOST__
239 configuration of @code{_AS__}, including assembler directives.
240 _fi__(!_GENERIC__)
241 _if__(_GENERIC__)
242 This document also describes some of the machine-dependent features of
243 various flavors of the assembler.
244 _fi__(_GENERIC__)
245 _if__(_INTERNALS__)
246 This document also describes how the assembler works internally, and
247 provides some information that may be useful to people attempting to
248 port the assembler to another machine.
249 _fi__(_INTERNALS__)
250 @refill
251
252 On the other hand, this manual is @emph{not} intended as an introduction
253 to programming in assembly language---let alone programming in general!
254 In a similar vein, we make no attempt to introduce the machine
255 architecture; we do @emph{not} describe the instruction set, standard
256 mnemonics, registers or addressing modes that are standard to a
257 particular architecture. You may want to consult the manufacturer's
258 machine architecture manual for this information.
259
260
261 @c I think this is premature---pesch@cygnus.com, 17jan1991
262 @ignore
263 Throughout this document, we assume that you are running @dfn{GNU},
264 the portable operating system from the @dfn{Free Software
265 Foundation, Inc.}. This restricts our attention to certain kinds of
266 computer (in particular, the kinds of computers that GNU can run on);
267 once this assumption is granted examples and definitions need less
268 qualification.
269
270 @code{_AS__} is part of a team of programs that turn a high-level
271 human-readable series of instructions into a low-level
272 computer-readable series of instructions. Different versions of
273 @code{_AS__} are used for different kinds of computer.
274 @end ignore
275
276 @c There used to be a section "Terminology" here, which defined
277 @c "contents", "byte", "word", and "long". Defining "word" to any
278 @c particular size is confusing when the .word directive may generate 16
279 @c bits on one machine and 32 bits on another; in general, for the user
280 @c version of this manual, none of these terms seem essential to define.
281 @c They were used very little even in the former draft of the manual;
282 @c this draft makes an effort to avoid them (except in names of
283 @c directives).
284
285 @node GNU Assembler,,,
286 @section _AS__, the GNU Assembler
287 GNU @code{as} is really a family of assemblers.
288 _if__(!_GENERIC__)
289 This manual describes @samp{_AS__}, a member of that family which is
290 configured for the _HOST__ architectures.
291 _fi__(!_GENERIC__)
292 If you use (or have used) the GNU assembler on another architecture, you
293 should find a fairly similar environment. Each version has much in
294 common with the others, including object file formats, most assembler
295 directives (often called @dfn{pseudo-ops)} and assembler syntax.@refill
296
297 @code{_AS__} is primarily intended to assemble the output of the GNU C
298 compiler @code{_GCC__} for use by the linker @code{_LD__}. Nevertheless,
299 we've tried to make @code{_AS__} assemble correctly everything that the native
300 assembler would.
301 _if__(_VAX__)
302 Any exceptions are documented explicitly (@pxref{_MACH_DEP__}).
303 _fi__(_VAX__)
304 _if__(_GENERIC__||_M680X0__)
305 This doesn't mean @code{_AS__} always uses the same syntax as another
306 assembler for the same architecture; for example, we know of several
307 incompatible versions of 680x0 assembly language syntax.
308 _fi__(_GENERIC__||_M680X0__)
309
310 Unlike older assemblers, @code{_AS__} is designed to assemble a source
311 program in one pass of the source file. This has a subtle impact on the
312 @kbd{.org} directive (@pxref{Org}).
313
314 @node Object Formats,,,
315 @section Object File Formats
316 The GNU assembler can be configured to produce several alternative
317 object file formats.
318 _if__(!_GENERIC__)
319 _if__(!_I960__)
320 @code{_AS__} is configured to produce @code{a.out} format object
321 files.@refill
322 _fi__(!_I960__)
323 _if__(_I960__)
324 @code{_AS__} can be configured to produce either @code{b.out} or COFF
325 format object files.
326 _fi__(_I960__)
327 _fi__(!_GENERIC__)
328
329 @node Command Line,,,
330 @section Command Line
331
332 After the program name @code{_AS__}, the command line may contain
333 options and file names. Options may be in any order, and may be
334 before, after, or between file names. The order of file names is
335 significant.
336
337 @file{--} (two hyphens) by itself names the standard input file
338 explicitly, as one of the files for @code{_AS__} to assemble.
339
340 Except for @samp{--} any command line argument that begins with a
341 hyphen (@samp{-}) is an option. Each option changes the behavior of
342 @code{_AS__}. No option changes the way another option works. An
343 option is a @samp{-} followed by one or more letters; the case of
344 the letter is important. All options are optional.
345
346 Some options expect exactly one file name to follow them. The file
347 name may either immediately follow the option's letter (compatible
348 with older assemblers) or it may be the next command argument (GNU
349 standard). These two command lines are equivalent:
350
351 @smallexample
352 _AS__ -o my-object-file.o mumble.s
353 _AS__ -omy-object-file.o mumble.s
354 @end smallexample
355
356 @node Input Files, Object, Command Line, Overview
357 @section Input Files
358
359 We use the phrase @dfn{source program}, abbreviated @dfn{source}, to
360 describe the program input to one run of @code{_AS__}. The program may
361 be in one or more files; how the source is partitioned into files
362 doesn't change the meaning of the source.
363
364 @c I added "con" prefix to "catenation" just to prove I can overcome my
365 @c APL training... pesch@cygnus.com
366 The source program is a concatenation of the text in all the files, in the
367 order specified.
368
369 Each time you run @code{_AS__} it assembles exactly one source
370 program. The source program is made up of one or more files.
371 (The standard input is also a file.)
372
373 You give @code{_AS__} a command line that has zero or more input file
374 names. The input files are read (from left file name to right). A
375 command line argument (in any position) that has no special meaning
376 is taken to be an input file name.
377
378 If @code{_AS__} is given no file names it attempts to read one input file
379 from the @code{_AS__} standard input, which is normally your terminal. You
380 may have to type @key{ctl-D} to tell @code{_AS__} there is no more program
381 to assemble.
382
383 Use @samp{--} if you need to explicitly name the standard input file
384 in your command line.
385
386 If the source is empty, @code{_AS__} will produce a small, empty object
387 file.
388
389 @node Filenames, , Input Files, Input Files
390 @subsection Filenames and Line-numbers
391 There are two ways of locating a line in the input file (or files) and both
392 are used in reporting error messages. One way refers to a line
393 number in a physical file; the other refers to a line number in a
394 ``logical'' file.
395
396 @dfn{Physical files} are those files named in the command line given
397 to @code{_AS__}.
398
399 @dfn{Logical files} are simply names declared explicitly by assembler
400 directives; they bear no relation to physical files. Logical file names
401 help error messages reflect the original source file, when @code{_AS__}
402 source is itself synthesized from other files. @xref{App-File}.
403
404 @node Object, Errors, Input Files, Overview
405 @section Output (Object) File
406 Every time you run @code{_AS__} it produces an output file, which is
407 your assembly language program translated into numbers. This file
408 is the object file, named @code{a.out} unless you tell @code{_AS__} to
409 give it another name by using the @code{-o} option. Conventionally,
410 object file names end with @file{.o}. The default name of
411 @file{a.out} is used for historical reasons: older assemblers were
412 capable of assembling self-contained programs directly into a
413 runnable program.
414 @c This may still work, but hasn't been tested.
415
416 The object file is meant for input to the linker @code{_LD__}. It contains
417 assembled program code, information to help @code{_LD__} integrate
418 the assembled program into a runnable file, and (optionally) symbolic
419 information for the debugger.
420
421 @comment link above to some info file(s) like the description of a.out.
422 @comment don't forget to describe GNU info as well as Unix lossage.
423
424 @node Errors, Options, Object, Overview
425 @section Error and Warning Messages
426
427 @code{_AS__} may write warnings and error messages to the standard error
428 file (usually your terminal). This should not happen when @code{_AS__} is
429 run automatically by a compiler. Warnings report an assumption made so
430 that @code{_AS__} could keep assembling a flawed program; errors report a
431 grave problem that stops the assembly.
432
433 Warning messages have the format
434 @smallexample
435 file_name:@b{NNN}:Warning Message Text
436 @end smallexample
437 @noindent
438 (where @b{NNN} is a line number). If a logical file name has
439 been given (@pxref{App-File}) it is used for the filename, otherwise the
440 name of the current input file is used. If a logical line number was
441 given
442 _if__(!_AMD29K__)
443 (@pxref{Line})
444 _fi__(!_AMD29K__)
445 _if__(_AMD29K__)
446 (@pxref{Ln})
447 _fi__(_AMD29K__)
448 then it is used to calculate the number printed,
449 otherwise the actual line in the current source file is printed. The
450 message text is intended to be self explanatory (in the grand Unix
451 tradition). @refill
452
453 Error messages have the format
454 @smallexample
455 file_name:@b{NNN}:FATAL:Error Message Text
456 @end smallexample
457 The file name and line number are derived as for warning
458 messages. The actual message text may be rather less explanatory
459 because many of them aren't supposed to happen.
460
461 @node Options, , Errors, Overview
462 @section Options
463 This section describes command-line options available in @emph{all}
464 versions of the GNU assembler; @pxref{_MACH_DEP__}, for options specific
465 _if__(!_GENERIC__)
466 to the _HOST__.
467 _fi__(!_GENERIC__)
468 _if__(_GENERIC__)
469 to particular machine architectures.
470 _fi__(_GENERIC__)
471
472 @subsection @code{-D}
473 This option has no effect whatsoever, but it is accepted to make it more
474 likely that scripts written for other assemblers will also work with
475 @code{_AS__}.
476
477 @subsection Work Faster: @code{-f}
478 @samp{-f} should only be used when assembling programs written by a
479 (trusted) compiler. @samp{-f} stops the assembler from pre-processing
480 the input file(s) before assembling them.
481 @quotation
482 @emph{Warning:} if the files actually need to be pre-processed (if they
483 contain comments, for example), @code{_AS__} will not work correctly if
484 @samp{-f} is used.
485 @end quotation
486
487 @subsection @code{.include} search path: @code{-I} @var{path}
488 Use this option to add a @var{path} to the list of directories
489 @code{_AS__} will search for files specified in @code{.include} directives
490 (@pxref{Include}). You may use @code{-I} as many times as necessary to
491 include a variety of paths. The current working directory is always
492 searched first; after that, @code{_AS__} searches any @samp{-I} directories
493 in the same order as they were specified (left to right) on the command
494 line.
495
496 @subsection Difference Tables: @code{-k}
497 _if__((!_GENERIC__) && (_AMD29K__ || _I960__))
498 On the _HOST__ family, this option is allowed, but has no effect. It is
499 permitted for compatibility with the GNU assembler on other platforms,
500 where it can be used to warn when the assembler alters the machine code
501 generated for @samp{.word} directives in difference tables. The _HOST__
502 family does not have the addressing limitations that sometimes lead to this
503 alteration on other platforms.
504 _fi__((!_GENERIC__) && (_AMD29K__ || _I960__))
505
506 _if__(_GENERIC__ || (! _AMD29K__ || _I960__ ))
507 @code{_AS__} sometimes alters the code emitted for directives of the form
508 @samp{.word @var{sym1}-@var{sym2}}; @pxref{Word}.
509 You can use the @samp{-k} option if you want a warning issued when this
510 is done.
511 _fi__(_GENERIC__ || (! _AMD29K__ || _I960__ ))
512
513 @subsection Include Local Labels: @code{-L}
514 Labels beginning with @samp{L} (upper case only) are called @dfn{local
515 labels}. @xref{Symbol Names}. Normally you don't see such labels when
516 debugging, because they are intended for the use of programs (like
517 compilers) that compose assembler programs, not for your notice.
518 Normally both @code{_AS__} and @code{_LD__} discard such labels, so you don't
519 normally debug with them.
520
521 This option tells @code{_AS__} to retain those @samp{L@dots{}} symbols
522 in the object file. Usually if you do this you also tell the linker
523 @code{_LD__} to preserve symbols whose names begin with @samp{L}.
524
525 @subsection Name the Object File: @code{-o}
526 There is always one object file output when you run @code{_AS__}. By
527 default it has the name @file{a.out}. You use this option (which
528 takes exactly one filename) to give the object file a different name.
529
530 Whatever the object file is called, @code{_AS__} will overwrite any
531 existing file of the same name.
532
533 @subsection Join Data and Text Segments: @code{-R}
534 @code{-R} tells @code{_AS__} to write the object file as if all
535 data-segment data lives in the text segment. This is only done at
536 the very last moment: your binary data are the same, but data
537 segment parts are relocated differently. The data segment part of
538 your object file is zero bytes long because all it bytes are
539 appended to the text segment. (@xref{Segments}.)
540
541 When you specify @code{-R} it would be possible to generate shorter
542 address displacements (because we don't have to cross between text and
543 data segment). We refrain from doing this simply for compatibility with
544 older versions of @code{_AS__}. In future, @code{-R} may work this way.
545
546 @subsection Suppress Warnings: @code{-W}
547 @code{_AS__} should never give a warning or error message when
548 assembling compiler output. But programs written by people often
549 cause @code{_AS__} to give a warning that a particular assumption was
550 made. All such warnings are directed to the standard error file.
551 If you use this option, no warnings are issued. This option only
552 affects the warning messages: it does not change any particular of how
553 @code{_AS__} assembles your file. Errors, which stop the assembly, are
554 still reported.
555
556 @node Syntax, Segments, Overview, Top
557 @chapter Syntax
558 This chapter describes the machine-independent syntax allowed in a
559 source file. @code{_AS__} syntax is similar to what many other assemblers
560 use; it is inspired in BSD 4.2
561 _if__(!_VAX__)
562 assembler. @refill
563 _fi__(!_VAX__)
564 _if__(_VAX__)
565 assembler, except that @code{_AS__} does not assemble Vax bit-fields.
566 _fi__(_VAX__)
567
568 @node Pre-processing, Whitespace, Syntax, Syntax
569 @section Pre-processing
570
571 The pre-processor:
572 @itemize @bullet
573 @item
574 adjusts and removes extra whitespace. It leaves one space or tab before
575 the keywords on a line, and turns any other whitespace on the line into
576 a single space.
577
578 @item
579 removes all comments, replacing them with a single space, or an
580 appropriate number of newlines.
581
582 @item
583 converts character constants into the appropriate numeric values.
584 @end itemize
585
586 Excess whitespace, comments, and character constants
587 cannot be used in the portions of the input text that are not
588 pre-processed.
589
590 If the first line of an input file is @code{#NO_APP} or the @samp{-f}
591 option is given, the input file will not be pre-processed. Within such
592 an input file, parts of the file can be pre-processed by putting a line
593 that says @code{#APP} before the text that should be pre-processed, and
594 putting a line that says @code{#NO_APP} after them. This feature is
595 mainly intend to support @code{asm} statements in compilers whose output
596 normally does not need to be pre-processed.
597
598 @node Whitespace, Comments, Pre-processing, Syntax
599 @section Whitespace
600 @dfn{Whitespace} is one or more blanks or tabs, in any order.
601 Whitespace is used to separate symbols, and to make programs neater
602 for people to read. Unless within character constants
603 (@pxref{Characters}), any whitespace means the same as exactly one
604 space.
605
606 @node Comments, Symbol Intro, Whitespace, Syntax
607 @section Comments
608 There are two ways of rendering comments to @code{_AS__}. In both
609 cases the comment is equivalent to one space.
610
611 Anything from @samp{/*} through the next @samp{*/} is a comment.
612 This means you may not nest these comments.
613
614 @smallexample
615 /*
616 The only way to include a newline ('\n') in a comment
617 is to use this sort of comment.
618 */
619
620 /* This sort of comment does not nest. */
621 @end smallexample
622
623 Anything from the @dfn{line comment} character to the next newline
624 is considered a comment and is ignored. The line comment character is
625 _if__(_VAX__)
626 @samp{#} on the Vax;
627 _fi__(_VAX__)
628 _if__(_I960__)
629 @samp{#} on the i960;
630 _fi__(_I960__)
631 _if__(_M680X0__)
632 @samp{|} on the 680x0;
633 _fi__(_M680X0__)
634 _if__(_AMD29K__)
635 @samp{;} for the AMD 29K family;
636 _fi__(_AMD29K__)
637 @pxref{_MACH_DEP__}. @refill
638 @c FIXME: fill in SPARC line comment char
639
640 _if__(_GENERIC__)
641 On some machines there are two different line comment characters. One
642 will only begin a comment if it is the first non-whitespace character on
643 a line, while the other will always begin a comment.
644 _fi__(_GENERIC__)
645
646 To be compatible with past assemblers a special interpretation is
647 given to lines that begin with @samp{#}. Following the @samp{#} an
648 absolute expression (@pxref{Expressions}) is expected: this will be
649 the logical line number of the @b{next} line. Then a string
650 (@xref{Strings}.) is allowed: if present it is a new logical file
651 name. The rest of the line, if any, should be whitespace.
652
653 If the first non-whitespace characters on the line are not numeric,
654 the line is ignored. (Just like a comment.)
655 @smallexample
656 # This is an ordinary comment.
657 # 42-6 "new_file_name" # New logical file name
658 # This is logical line # 36.
659 @end smallexample
660 This feature is deprecated, and may disappear from future versions
661 of @code{_AS__}.
662
663 @node Symbol Intro, Statements, Comments, Syntax
664 @section Symbols
665 A @dfn{symbol} is one or more characters chosen from the set of all
666 letters (both upper and lower case), digits and the three characters
667 @samp{_.$}. No symbol may begin with a digit. Case is significant.
668 There is no length limit: all characters are significant. Symbols are
669 delimited by characters not in that set, or by the beginning of a file
670 (since the source program must end with a newline, the end of a file is
671 not a possible symbol delimiter). @xref{Symbols}.
672
673 @node Statements, Constants, Symbol Intro, Syntax
674 @section Statements
675 _if__(!_AMD29K__)
676 A @dfn{statement} ends at a newline character (@samp{\n}) or at a
677 semicolon (@samp{;}). The newline or semicolon is considered part of
678 the preceding statement. Newlines and semicolons within character
679 constants are an exception: they don't end statements.
680 _fi__(!_AMD29K__)
681 _if__(_AMD29K__)
682 A @dfn{statement} ends at a newline character (@samp{\n}) or an ``at''
683 sign (@samp{@@}). The newline or at sign is considered part of the
684 preceding statement. Newlines and at signs within character constants
685 are an exception: they don't end statements.
686 _fi__(_AMD29K__)
687
688 It is an error to end any statement with end-of-file: the last
689 character of any input file should be a newline.@refill
690
691 You may write a statement on more than one line if you put a
692 backslash (@kbd{\}) immediately in front of any newlines within the
693 statement. When @code{_AS__} reads a backslashed newline both
694 characters are ignored. You can even put backslashed newlines in
695 the middle of symbol names without changing the meaning of your
696 source program.
697
698 An empty statement is allowed, and may include whitespace. It is ignored.
699
700 @c "key symbol" is not used elsewhere in the document; seems pedantic to
701 @c @defn{} it in that case, as was done previously... pesch@cygnus.com,
702 @c 13feb91.
703 A statement begins with zero or more labels, optionally followed by a
704 key symbol which determines what kind of statement it is. The key
705 symbol determines the syntax of the rest of the statement. If the
706 symbol begins with a dot @samp{.} then the statement is an assembler
707 directive: typically valid for any computer. If the symbol begins with
708 a letter the statement is an assembly language @dfn{instruction}: it
709 will assemble into a machine language instruction.
710 _if__(_GENERIC__)
711 Different versions of @code{_AS__} for different computers will
712 recognize different instructions. In fact, the same symbol may
713 represent a different instruction in a different computer's assembly
714 language.@refill
715 _fi__(_GENERIC__)
716
717 A label is a symbol immediately followed by a colon (@code{:}).
718 Whitespace before a label or after a colon is permitted, but you may not
719 have whitespace between a label's symbol and its colon. @xref{Labels}.
720
721 @smallexample
722 label: .directive followed by something
723 another$label: # This is an empty statement.
724 instruction operand_1, operand_2, @dots{}
725 @end smallexample
726
727 @node Constants, , Statements, Syntax
728 @section Constants
729 A constant is a number, written so that its value is known by
730 inspection, without knowing any context. Like this:
731 @smallexample
732 .byte 74, 0112, 092, 0x4A, 0X4a, 'J, '\J # All the same value.
733 .ascii "Ring the bell\7" # A string constant.
734 .octa 0x123456789abcdef0123456789ABCDEF0 # A bignum.
735 .float 0f-314159265358979323846264338327\
736 95028841971.693993751E-40 # - pi, a flonum.
737 @end smallexample
738
739 @node Characters, Numbers, Constants, Constants
740 @subsection Character Constants
741 There are two kinds of character constants. A @dfn{character} stands
742 for one character in one byte and its value may be used in
743 numeric expressions. String constants (properly called string
744 @emph{literals}) are potentially many bytes and their values may not be
745 used in arithmetic expressions.
746
747 @node Strings, Chars, Characters, Characters
748 @subsubsection Strings
749 A @dfn{string} is written between double-quotes. It may contain
750 double-quotes or null characters. The way to get special characters
751 into a string is to @dfn{escape} these characters: precede them with
752 a backslash @samp{\} character. For example @samp{\\} represents
753 one backslash: the first @code{\} is an escape which tells
754 @code{_AS__} to interpret the second character literally as a backslash
755 (which prevents @code{_AS__} from recognizing the second @code{\} as an
756 escape character). The complete list of escapes follows.
757
758 @table @kbd
759 @c @item \a
760 @c Mnemonic for ACKnowledge; for ASCII this is octal code 007.
761 @item \b
762 Mnemonic for backspace; for ASCII this is octal code 010.
763 @c @item \e
764 @c Mnemonic for EOText; for ASCII this is octal code 004.
765 @item \f
766 Mnemonic for FormFeed; for ASCII this is octal code 014.
767 @item \n
768 Mnemonic for newline; for ASCII this is octal code 012.
769 @c @item \p
770 @c Mnemonic for prefix; for ASCII this is octal code 033, usually known as @code{escape}.
771 @item \r
772 Mnemonic for carriage-Return; for ASCII this is octal code 015.
773 @c @item \s
774 @c Mnemonic for space; for ASCII this is octal code 040. Included for compliance with
775 @c other assemblers.
776 @item \t
777 Mnemonic for horizontal Tab; for ASCII this is octal code 011.
778 @c @item \v
779 @c Mnemonic for Vertical tab; for ASCII this is octal code 013.
780 @c @item \x @var{digit} @var{digit} @var{digit}
781 @c A hexadecimal character code. The numeric code is 3 hexadecimal digits.
782 @item \ @var{digit} @var{digit} @var{digit}
783 An octal character code. The numeric code is 3 octal digits.
784 For compatibility with other Unix systems, 8 and 9 are accepted as digits:
785 for example, @code{\008} has the value 010, and @code{\009} the value 011.
786 @item \\
787 Represents one @samp{\} character.
788 @c @item \'
789 @c Represents one @samp{'} (accent acute) character.
790 @c This is needed in single character literals
791 @c (@xref{Characters}.) to represent
792 @c a @samp{'}.
793 @item \"
794 Represents one @samp{"} character. Needed in strings to represent
795 this character, because an unescaped @samp{"} would end the string.
796 @item \ @var{anything-else}
797 Any other character when escaped by @kbd{\} will give a warning, but
798 assemble as if the @samp{\} was not present. The idea is that if
799 you used an escape sequence you clearly didn't want the literal
800 interpretation of the following character. However @code{_AS__} has no
801 other interpretation, so @code{_AS__} knows it is giving you the wrong
802 code and warns you of the fact.
803 @end table
804
805 Which characters are escapable, and what those escapes represent,
806 varies widely among assemblers. The current set is what we think
807 the BSD 4.2 assembler recognizes, and is a subset of what most C
808 compilers recognize. If you are in doubt, don't use an escape
809 sequence.
810
811 @node Chars, , Strings, Characters
812 @subsubsection Characters
813 A single character may be written as a single quote immediately
814 followed by that character. The same escapes apply to characters as
815 to strings. So if you want to write the character backslash, you
816 must write @kbd{'\\} where the first @code{\} escapes the second
817 @code{\}. As you can see, the quote is an acute accent, not a
818 grave accent. A newline
819 _if__(!_AMD29K__)
820 (or semicolon @samp{;})
821 _fi__(!_AMD29K__)
822 _if__(_AMD29K__)
823 (or at sign @samp{@@})
824 _fi__(_AMD29K__)
825 immediately following an acute accent is taken as a literal character
826 and does not count as the end of a statement. The value of a character
827 constant in a numeric expression is the machine's byte-wide code for
828 that character. @code{_AS__} assumes your character code is ASCII:
829 @kbd{'A} means 65, @kbd{'B} means 66, and so on. @refill
830
831 @node Numbers,,,
832 @subsection Number Constants
833 @code{_AS__} distinguishes three kinds of numbers according to how they
834 are stored in the target machine. @emph{Integers} are numbers that
835 would fit into an @code{int} in the C language. @emph{Bignums} are
836 integers, but they are stored in more than 32 bits. @emph{Flonums}
837 are floating point numbers, described below.
838
839 @node Integers,,,
840 @subsubsection Integers
841 A binary integer is @samp{0b} or @samp{0B} followed by zero or more of
842 the binary digits @samp{01}.
843
844 An octal integer is @samp{0} followed by zero or more of the octal
845 digits (@samp{01234567}).
846
847 A decimal integer starts with a non-zero digit followed by zero or
848 more digits (@samp{0123456789}).
849
850 A hexadecimal integer is @samp{0x} or @samp{0X} followed by one or
851 more hexadecimal digits chosen from @samp{0123456789abcdefABCDEF}.
852
853 Integers have the usual values. To denote a negative integer, use
854 the prefix operator @samp{-} discussed under expressions
855 (@pxref{Prefix Ops}).
856
857 @node Bignums,,,
858 @subsubsection Bignums
859 A @dfn{bignum} has the same syntax and semantics as an integer
860 except that the number (or its negative) takes more than 32 bits to
861 represent in binary. The distinction is made because in some places
862 integers are permitted while bignums are not.
863
864 @node Flonums,,,
865 @subsubsection Flonums
866 A @dfn{flonum} represents a floating point number. The translation is
867 complex: a decimal floating point number from the text is converted by
868 @code{_AS__} to a generic binary floating point number of more than
869 sufficient precision. This generic floating point number is converted
870 to a particular computer's floating point format (or formats) by a
871 portion of @code{_AS__} specialized to that computer.
872
873 A flonum is written by writing (in order)
874 @itemize @bullet
875 @item
876 The digit @samp{0}.
877 @item
878 _if__(_GENERIC__)
879 A letter, to tell @code{_AS__} the rest of the number is a flonum. @kbd{e}
880 is recommended. Case is not important.
881 @ignore
882 @c FIXME: verify if flonum syntax really this vague for most cases
883 (Any otherwise illegal letter
884 will work here, but that might be changed. Vax BSD 4.2 assembler seems
885 to allow any of @samp{defghDEFGH}.)
886 @end ignore
887 _fi__(_GENERIC__)
888 _if__(_AMD29K__)
889 _if__(_GENERIC__)
890 On the AMD 29K architecture, the letter must be:
891 _fi__(_GENERIC__)
892 One of the letters @samp{DFPRSX} (in upper or lower case), to tell
893 @code{_AS__} the rest of the number is a flonum.
894 _fi__(_AMD29K__)
895 _if__(_I960__)
896 _if__(_GENERIC__)
897 On the Intel 960 architecture, the letter must be:
898 _fi__(_GENERIC__)
899 One of the letters @samp{DFT} (in upper or lower case), to tell
900 @code{_AS__} the rest of the number is a flonum.
901 _fi__(_I960__)
902 @item
903 An optional sign: either @samp{+} or @samp{-}.
904 @item
905 An optional @dfn{integer part}: zero or more decimal digits.
906 @item
907 An optional @dfn{fraction part}: @samp{.} followed by zero
908 or more decimal digits.
909 @item
910 An optional exponent, consisting of:
911 @itemize @bullet
912 @item
913 An @samp{E} or @samp{e}.
914 @c I can't find a config where "EXP_CHARS" is other than 'eE', but in
915 @c principle this can perfectly well be different on different targets.
916 @item
917 Optional sign: either @samp{+} or @samp{-}.
918 @item
919 One or more decimal digits.
920 @end itemize
921 @end itemize
922
923 At least one of @var{integer part} or @var{fraction part} must be
924 present. The floating point number has the usual base-10 value.
925
926 @code{_AS__} does all processing using integers. Flonums are computed
927 independently of any floating point hardware in the computer running
928 @code{_AS__}.
929
930 _if__(_I960__)
931 @c Bit fields are written as a general facility but are also controlled
932 @c by a conditional-compilation flag---which is as of now (21mar91)
933 @c turned on only by the i960 config of GAS.
934 @node Bit Fields,,,
935 @subsubsection Bit Fields
936 You can also define numeric constants as @dfn{bit fields}.
937 specify two numbers separated by a colon---
938 @example
939 @var{mask}:@var{value}
940 @end example
941 @noindent
942 the first will act as a mask; @code{_AS__} will bitwise-and it with the
943 second value.
944
945 The resulting number is then packed
946 _if__(_GENERIC__)
947 (in host-dependent byte order)
948 _fi__(_GENERIC__)
949 into a field whose width depends on which assembler directive has the
950 bit-field as its argument. Overflow (a result from the bitwise and
951 requiring more binary digits to represent) is not an error; instead,
952 more constants are generated, of the specified width, beginning with the
953 least significant digits.@refill
954
955 The directives @code{.byte}, @code{.hword}, @code{.int}, @code{.long},
956 @code{.short}, and @code{.word} accept bit-field arguments.
957 _fi__(_I960__)
958
959 @node Segments, Symbols, Syntax, Top
960 @chapter Segments and Relocation
961
962 @node Segs Background, _LD__ Segments, Segments, Segments
963 @section Background
964 Roughly, a segment is a range of addresses, with no gaps; all data
965 ``in'' those addresses is treated the same for some particular purpose.
966 For example there may be a ``read only'' segment.
967
968 The linker @code{_LD__} reads many object files (partial programs) and
969 combines their contents to form a runnable program. When @code{_AS__}
970 emits an object file, the partial program is assumed to start at address
971 0. @code{_LD__} will assign the final addresses the partial program
972 occupies, so that different partial programs don't overlap. This is
973 actually an over-simplification, but it will suffice to explain how
974 @code{_AS__} uses segments.
975
976 @code{_LD__} moves blocks of bytes of your program to their run-time
977 addresses. These blocks slide to their run-time addresses as rigid
978 units; their length does not change and neither does the order of bytes
979 within them. Such a rigid unit is called a @emph{segment}. Assigning
980 run-time addresses to segments is called @dfn{relocation}. It includes
981 the task of adjusting mentions of object-file addresses so they refer to
982 the proper run-time addresses.
983
984 An object file written by @code{_AS__} has three segments, any of which may
985 be empty. These are named @dfn{text}, @dfn{data} and @dfn{bss}
986 segments.
987 _if__(_COFF__)
988
989 @c Thanks, Rich!
990 @quotation
991 @emph{Warning:} @code{_AS__} can only assign output to one of these
992 three segments, even when configured for COFF output; the
993 @code{.section} directive is not supported.
994 @end quotation
995 _fi__(_COFF__)
996
997 Within the object file, the text segment starts at address @code{0}, the
998 data segment follows, and the bss segment follows the data segment.
999
1000 To let @code{_LD__} know which data will change when the segments are
1001 relocated, and how to change that data, @code{_AS__} also writes to the
1002 object file details of the relocation needed. To perform relocation
1003 @code{_LD__} must know, each time an address in the object
1004 file is mentioned:
1005 @itemize @bullet
1006 @item
1007 Where in the object file is the beginning of this reference to
1008 an address?
1009 @item
1010 How long (in bytes) is this reference?
1011 @item
1012 Which segment does the address refer to? What is the numeric value of
1013 @display
1014 (@var{address}) @minus{} (@var{start-address of segment})?
1015 @end display
1016 @item
1017 Is the reference to an address ``Program-Counter relative''?
1018 @end itemize
1019
1020 In fact, every address @code{_AS__} ever uses is expressed as
1021 @display
1022 (@var{segment}) + (@var{offset into segment})
1023 @end display
1024 @noindent
1025 Further, every expression @code{_AS__} computes is of this segmented
1026 nature. @dfn{Absolute expression} means an expression with segment
1027 ``absolute'' (@pxref{_LD__ Segments}). A @dfn{pass1 expression} means
1028 an expression with segment ``pass1'' (@pxref{_AS__ Segments}). In this
1029 manual we use the notation @{@var{segname} @var{N}@} to mean ``offset
1030 @var{N} into segment @var{segname}''.
1031
1032 Apart from text, data and bss segments you need to know about the
1033 @dfn{absolute} segment. When @code{_LD__} mixes partial programs,
1034 addresses in the absolute segment remain unchanged. That is, address
1035 @code{@{absolute 0@}} is ``relocated'' to run-time address 0 by @code{_LD__}.
1036 Although two partial programs' data segments will not overlap addresses
1037 after linking, @emph{by definition} their absolute segments will overlap.
1038 Address @code{@{absolute@ 239@}} in one partial program will always be the same
1039 address when the program is running as address @code{@{absolute@ 239@}} in any
1040 other partial program.
1041
1042 The idea of segments is extended to the @dfn{undefined} segment. Any
1043 address whose segment is unknown at assembly time is by definition
1044 rendered @{undefined @var{U}@}---where @var{U} will be filled in later.
1045 Since numbers are always defined, the only way to generate an undefined
1046 address is to mention an undefined symbol. A reference to a named
1047 common block would be such a symbol: its value is unknown at assembly
1048 time so it has segment @emph{undefined}.
1049
1050 By analogy the word @emph{segment} is used to describe groups of segments in
1051 the linked program. @code{_LD__} puts all partial programs' text
1052 segments in contiguous addresses in the linked program. It is
1053 customary to refer to the @emph{text segment} of a program, meaning all
1054 the addresses of all partial program's text segments. Likewise for
1055 data and bss segments.
1056
1057 Some segments are manipulated by @code{_LD__}; others are invented for
1058 use of @code{_AS__} and have no meaning except during assembly.
1059
1060 @node _LD__ Segments, _AS__ Segments, Segs Background, Segments
1061 @section _LD__ Segments
1062 @code{_LD__} deals with just five kinds of segments, summarized below.
1063
1064 @table @strong
1065
1066 @item text segment
1067 @itemx data segment
1068 These segments hold your program. @code{_AS__} and @code{_LD__} treat them as
1069 separate but equal segments. Anything you can say of one segment is
1070 true of the other. When the program is running, however, it is
1071 customary for the text segment to be unalterable. The
1072 text segment is often shared among processes: it will contain
1073 instructions, constants and the like. The data segment of a running
1074 program is usually alterable: for example, C variables would be stored
1075 in the data segment.
1076
1077 @item bss segment
1078 This segment contains zeroed bytes when your program begins running. It
1079 is used to hold unitialized variables or common storage. The length of
1080 each partial program's bss segment is important, but because it starts
1081 out containing zeroed bytes there is no need to store explicit zero
1082 bytes in the object file. The bss segment was invented to eliminate
1083 those explicit zeros from object files.
1084
1085 @item absolute segment
1086 Address 0 of this segment is always ``relocated'' to runtime address 0.
1087 This is useful if you want to refer to an address that @code{_LD__} must
1088 not change when relocating. In this sense we speak of absolute
1089 addresses being ``unrelocatable'': they don't change during relocation.
1090
1091 @item undefined segment
1092 This ``segment'' is a catch-all for address references to objects not in
1093 the preceding segments.
1094 @c FIXME: ref to some other doc on obj-file formats could go here.
1095
1096 @end table
1097
1098 An idealized example of the three relocatable segments follows. Memory
1099 addresses are on the horizontal axis.
1100
1101 @ifinfo
1102 @smallexample
1103 +-----+----+--+
1104 partial program # 1: |ttttt|dddd|00|
1105 +-----+----+--+
1106
1107 text data bss
1108 seg. seg. seg.
1109
1110 +---+---+---+
1111 partial program # 2: |TTT|DDD|000|
1112 +---+---+---+
1113
1114 +--+---+-----+--+----+---+-----+~~
1115 linked program: | |TTT|ttttt| |dddd|DDD|00000|
1116 +--+---+-----+--+----+---+-----+~~
1117
1118 addresses: 0 @dots{}
1119 @end smallexample
1120 @end ifinfo
1121 @tex
1122
1123 {\it Partial program \#1: }
1124
1125 \line{\ibox{2.5cm}{\tt text}\ibox{2cm}{\tt data}\ibox{1cm}{\tt bss}\hfil}
1126 \line{\boxit{2.5cm}{\tt ttttt}\boxit{2cm}{\tt dddd}\boxit{1cm}{\tt 00}\hfil}
1127
1128 {\it Partial program \#2:}
1129
1130 \line{\ibox{1cm}{\tt text}\ibox{1.5cm}{\tt data}\ibox{1cm}{\tt bss}\hfil}
1131 \line{\boxit{1cm}{\tt TTT}\boxit{1.5cm}{\tt DDDD}\boxit{1cm}{\tt 000}\hfil}
1132
1133 {\it linked program: }
1134
1135 \line{\ibox{.5cm}{}\ibox{1cm}{\tt text}\ibox{2.5cm}{}\ibox{.75cm}{}\ibox{2cm}{\tt data}\ibox{1.5cm}{}\ibox{2cm}{\tt bss}\hfil}
1136 \line{\boxit{.5cm}{}\boxit{1cm}{\tt TTT}\boxit{2.5cm}{\tt
1137 ttttt}\boxit{.75cm}{}\boxit{2cm}{\tt dddd}\boxit{1.5cm}{\tt
1138 DDDD}\boxit{2cm}{\tt 00000}\ \dots\hfil}
1139
1140 {\it addresses:}
1141
1142 \line{0\dots\hfil}
1143
1144 @end tex
1145
1146 @node _AS__ Segments, Sub-Segments, _LD__ Segments, Segments
1147 @section _AS__ Internal Segments
1148 These segments are invented for the internal use of @code{_AS__}. They
1149 have no meaning at run-time. You don't need to know about these
1150 segments except that they might be mentioned in the @code{_AS__} warning
1151 messages. These segments are invented to permit the value of every
1152 expression in your assembly language program to be a segmented
1153 address.
1154
1155 @table @b
1156 @item absent segment
1157 An expression was expected and none was
1158 found.
1159
1160 @item goof segment
1161 An internal assembler logic error has been
1162 found. This means there is a bug in the assembler.
1163
1164 @item grand segment
1165 A @dfn{grand number} is a bignum or a flonum, but not an integer. If a
1166 number can't be written as a C @code{int} constant, it is a grand
1167 number. @code{_AS__} has to remember that a flonum or a bignum does not
1168 fit into 32 bits, and cannot be an argument (@pxref{Arguments}) in an
1169 expression: this is done by making a flonum or bignum be in segment
1170 grand. This is purely for internal @code{_AS__} convenience; grand
1171 segment behaves similarly to absolute segment.
1172
1173 @item pass1 segment
1174 The expression was impossible to evaluate in the first pass. The
1175 assembler will attempt a second pass (second reading of the source) to
1176 evaluate the expression. Your expression mentioned an undefined symbol
1177 in a way that defies the one-pass (segment + offset in segment) assembly
1178 process. No compiler need emit such an expression.
1179
1180 @quotation
1181 @emph{Warning:} the second pass is currently not implemented. @code{_AS__}
1182 will abort with an error message if one is required.
1183 @end quotation
1184
1185 @item difference segment
1186 As an assist to the C compiler, expressions of the forms
1187 @display
1188 (@var{undefined symbol}) @minus{} (@var{expression})
1189 @var{something} @minus{} (@var{undefined symbol})
1190 (@var{undefined symbol}) @minus{} (@var{undefined symbol})
1191 @end display
1192 are permitted, and belong to the difference segment. @code{_AS__}
1193 re-evaluates such expressions after the source file has been read and
1194 the symbol table built. If by that time there are no undefined symbols
1195 in the expression then the expression assumes a new segment. The
1196 intention is to permit statements like
1197 @samp{.word label - base_of_table}
1198 to be assembled in one pass where both @code{label} and
1199 @code{base_of_table} are undefined. This is useful for compiling C and
1200 Algol switch statements, Pascal case statements, FORTRAN computed goto
1201 statements and the like.
1202 @end table
1203
1204 @node Sub-Segments, bss, _AS__ Segments, Segments
1205 @section Sub-Segments
1206 Assembled bytes fall into two segments: text and data.
1207 Because you may have groups of text or data that you want to end up near
1208 to each other in the object file, @code{_AS__} allows you to use
1209 @dfn{subsegments}. Within each segment, there can be numbered
1210 subsegments with values from 0 to 8192. Objects assembled into the same
1211 subsegment will be grouped with other objects in the same subsegment
1212 when they are all put into the object file. For example, a compiler
1213 might want to store constants in the text segment, but might not want to
1214 have them interspersed with the program being assembled. In this case,
1215 the compiler could issue a @code{text 0} before each section of code
1216 being output, and a @code{text 1} before each group of constants being
1217 output.
1218
1219 Subsegments are optional. If you don't use subsegments, everything
1220 will be stored in subsegment number zero.
1221
1222 _if__(_GENERIC__)
1223 Each subsegment is zero-padded up to a multiple of four bytes.
1224 (Subsegments may be padded a different amount on different flavors
1225 of @code{_AS__}.)
1226 _fi__(_GENERIC__)
1227 _if__(_I960__)
1228 @c Rich Pixley says padding here depends on target obj code format; that
1229 @c doesn't seem particularly useful to say without further elaboration,
1230 @c so for now I say nothing about it. If this is a generic BFD issue,
1231 @c these paragraphs might need to vanish from this manual, and be
1232 @c discussed in BFD chapter of binutils (or some such).
1233 _fi__(_I960__)
1234 _if__(_AMD29K__)
1235 On the AMD 29K family, no particular padding is added to segment sizes;
1236 _AS__ forces no alignment on this platform.
1237 _fi__(_AMD29K__)
1238 Subsegments appear in your object file in numeric order, lowest numbered
1239 to highest. (All this to be compatible with other people's assemblers.)
1240 The object file contains no representation of subsegments; @code{_LD__} and
1241 other programs that manipulate object files will see no trace of them.
1242 They just see all your text subsegments as a text segment, and all your
1243 data subsegments as a data segment.
1244
1245 To specify which subsegment you want subsequent statements assembled
1246 into, use a @samp{.text @var{expression}} or a @samp{.data
1247 @var{expression}} statement. @var{Expression} should be an absolute
1248 expression. (@xref{Expressions}.) If you just say @samp{.text}
1249 then @samp{.text 0} is assumed. Likewise @samp{.data} means
1250 @samp{.data 0}. Assembly begins in @code{text 0}.
1251 For instance:
1252 @smallexample
1253 .text 0 # The default subsegment is text 0 anyway.
1254 .ascii "This lives in the first text subsegment. *"
1255 .text 1
1256 .ascii "But this lives in the second text subsegment."
1257 .data 0
1258 .ascii "This lives in the data segment,"
1259 .ascii "in the first data subsegment."
1260 .text 0
1261 .ascii "This lives in the first text segment,"
1262 .ascii "immediately following the asterisk (*)."
1263 @end smallexample
1264
1265 Each segment has a @dfn{location counter} incremented by one for every
1266 byte assembled into that segment. Because subsegments are merely a
1267 convenience restricted to @code{_AS__} there is no concept of a subsegment
1268 location counter. There is no way to directly manipulate a location
1269 counter---but the @code{.align} directive will change it, and any label
1270 definition will capture its current value. The location counter of the
1271 segment that statements are being assembled into is said to be the
1272 @dfn{active} location counter.
1273
1274 @node bss, , Sub-Segments, Segments
1275 @section bss Segment
1276 The bss segment is used for local common variable storage.
1277 You may allocate address space in the bss segment, but you may
1278 not dictate data to load into it before your program executes. When
1279 your program starts running, all the contents of the bss
1280 segment are zeroed bytes.
1281
1282 Addresses in the bss segment are allocated with special directives;
1283 you may not assemble anything directly into the bss segment. Hence
1284 there are no bss subsegments. @xref{Comm}; @pxref{Lcomm}.
1285
1286 @node Symbols, Expressions, Segments, Top
1287 @chapter Symbols
1288 Symbols are a central concept: the programmer uses symbols to name
1289 things, the linker uses symbols to link, and the debugger uses symbols
1290 to debug.
1291
1292 @quotation
1293 @emph{Warning:} @code{_AS__} does not place symbols in the object file in
1294 the same order they were declared. This may break some debuggers.
1295 @end quotation
1296
1297 @node Labels, Setting Symbols, Symbols, Symbols
1298 @section Labels
1299 A @dfn{label} is written as a symbol immediately followed by a colon
1300 @samp{:}. The symbol then represents the current value of the
1301 active location counter, and is, for example, a suitable instruction
1302 operand. You are warned if you use the same symbol to represent two
1303 different locations: the first definition overrides any other
1304 definitions.
1305
1306 @node Setting Symbols, Symbol Names, Labels, Symbols
1307 @section Giving Symbols Other Values
1308 A symbol can be given an arbitrary value by writing a symbol, followed
1309 by an equals sign @samp{=}, followed by an expression
1310 (@pxref{Expressions}). This is equivalent to using the @code{.set}
1311 directive. @xref{Set}.
1312
1313 @node Symbol Names, Dot, Setting Symbols, Symbols
1314 @section Symbol Names
1315 Symbol names begin with a letter or with one of @samp{$._}. That
1316 character may be followed by any string of digits, letters,
1317 underscores and dollar signs. Case of letters is significant:
1318 @code{foo} is a different symbol name than @code{Foo}.
1319
1320 _if__(_AMD29K__)
1321 For the AMD 29K family, @samp{?} is also allowed in the
1322 body of a symbol name, though not at its beginning.
1323 _fi__(_AMD29K__)
1324
1325 Each symbol has exactly one name. Each name in an assembly language
1326 program refers to exactly one symbol. You may use that symbol name any
1327 number of times in a program.
1328
1329 @node Local Symbols, , Symbol Names, Symbol Names
1330 @subsection Local Symbol Names
1331
1332 Local symbols help compilers and programmers use names temporarily.
1333 There are ten local symbol names, which are re-used throughout the
1334 program. You may refer to them using the names @samp{0} @samp{1}
1335 @dots{} @samp{9}. To define a local symbol, write a label of the form
1336 @samp{@b{N}:} (where @b{N} represents any digit). To refer to the most
1337 recent previous definition of that symbol write @samp{@b{N}b}, using the
1338 same digit as when you defined the label. To refer to the next
1339 definition of a local label, write @samp{@b{N}f}---where @b{N} gives you
1340 a choice of 10 forward references. The @samp{b} stands for
1341 ``backwards'' and the @samp{f} stands for ``forwards''.
1342
1343 Local symbols are not emitted by the current GNU C compiler.
1344
1345 There is no restriction on how you can use these labels, but
1346 remember that at any point in the assembly you can refer to at most
1347 10 prior local labels and to at most 10 forward local labels.
1348
1349 Local symbol names are only a notation device. They are immediately
1350 transformed into more conventional symbol names before the assembler
1351 uses them. The symbol names stored in the symbol table, appearing in
1352 error messages and optionally emitted to the object file have these
1353 parts:
1354
1355 @table @code
1356 @item L
1357 All local labels begin with @samp{L}. Normally both @code{_AS__} and
1358 @code{_LD__} forget symbols that start with @samp{L}. These labels are
1359 used for symbols you are never intended to see. If you give the
1360 @samp{-L} option then @code{_AS__} will retain these symbols in the
1361 object file. If you also instruct @code{_LD__} to retain these symbols,
1362 you may use them in debugging.
1363
1364 @item @var{digit}
1365 If the label is written @samp{0:} then the digit is @samp{0}.
1366 If the label is written @samp{1:} then the digit is @samp{1}.
1367 And so on up through @samp{9:}.
1368
1369 @item @ctrl{A}
1370 This unusual character is included so you don't accidentally invent
1371 a symbol of the same name. The character has ASCII value
1372 @samp{\001}.
1373
1374 @item @emph{ordinal number}
1375 This is a serial number to keep the labels distinct. The first
1376 @samp{0:} gets the number @samp{1}; The 15th @samp{0:} gets the
1377 number @samp{15}; @emph{etc.}. Likewise for the other labels @samp{1:}
1378 through @samp{9:}.
1379 @end table
1380
1381 For instance, the first @code{1:} is named @code{L1@ctrl{A}1}, the 44th
1382 @code{3:} is named @code{L3@ctrl{A}44}.
1383
1384 @node Dot, Symbol Attributes, Symbol Names, Symbols
1385 @section The Special Dot Symbol
1386
1387 The special symbol @samp{.} refers to the current address that
1388 @code{_AS__} is assembling into. Thus, the expression @samp{melvin:
1389 .long .} will cause @code{melvin} to contain its own address.
1390 Assigning a value to @code{.} is treated the same as a @code{.org}
1391 directive. Thus, the expression @samp{.=.+4} is the same as saying
1392 _if__(!_AMD29K__)
1393 @samp{.space 4}.
1394 _fi__(!_AMD29K__)
1395 _if__(_AMD29K__)
1396 @samp{.block 4}.
1397 _fi__(_AMD29K__)
1398
1399 @node Symbol Attributes, , Dot, Symbols
1400 @section Symbol Attributes
1401 Every symbol has, as well as its name, the attributes ``Value'' and
1402 ``Type''. Depending on output format, symbols also have auxiliary attributes.
1403 _if__(_INTERNALS__)
1404 The detailed definitions are in _0__<a.out.h>_1__.
1405 _fi__(_INTERNALS__)
1406
1407 If you use a symbol without defining it, @code{_AS__} assumes zero for
1408 all these attributes, and probably won't warn you. This makes the
1409 symbol an externally defined symbol, which is generally what you
1410 would want.
1411
1412 @node Symbol Value, Symbol Type, Symbol Attributes, Symbol Attributes
1413 @subsection Value
1414 The value of a symbol is (usually) 32 bits, the size of one GNU C
1415 @code{int}. For a symbol which labels a location in the text, data, bss
1416 or absolute segments the value is the number of addresses from the start
1417 of that segment to the label. Naturally for text, data and bss segments
1418 the value of a symbol changes as @code{_LD__} changes segment base
1419 addresses during linking. Absolute symbols' values do not change during
1420 linking: that is why they are called absolute.
1421
1422 The value of an undefined symbol is treated in a special way. If it is
1423 0 then the symbol is not defined in this assembler source program, and
1424 @code{_LD__} will try to determine its value from other programs it is
1425 linked with. You make this kind of symbol simply by mentioning a symbol
1426 name without defining it. A non-zero value represents a @code{.comm}
1427 common declaration. The value is how much common storage to reserve, in
1428 bytes (addresses). The symbol refers to the first address of the
1429 allocated storage.
1430
1431 @node Symbol Type, Symbol Desc, Symbol Value, Symbol Attributes
1432 @subsection Type
1433 The type attribute of a symbol contains relocation (segment)
1434 information, any flag settings indicating that a symbol is external, and
1435 (optionally), other information for linkers and debuggers. The exact
1436 format depends on the object-code output format in use.
1437
1438 _if__(_AOUT__||_BOUT__)
1439 @node a.out Symbols,,,
1440 _if__(_BOUT__)
1441 @subsection Symbol Attributes: @code{a.out}, @code{b.out}
1442 These symbol attributes appear only when @code{_AS__} is configured for
1443 one of the Berkeley-descended object output formats.
1444 _fi__(_BOUT__)
1445 _if__(!_BOUT__)
1446 @subsection Symbol Attributes: @code{a.out}
1447 _fi__(!_BOUT__)
1448
1449 @node Symbol Desc, Symbol Other, Symbol Type, Symbol Attributes
1450 @subsubsection Descriptor
1451 This is an arbitrary 16-bit value. You may establish a symbol's
1452 descriptor value by using a @code{.desc} statement (@pxref{Desc}).
1453 A descriptor value means nothing to @code{_AS__}.
1454
1455 @node Symbol Other, , Symbol Desc, Symbol Attributes
1456 @subsubsection Other
1457 This is an arbitrary 8-bit value. It means nothing to @code{_AS__}.
1458 _fi__(_AOUT__||_BOUT__)
1459
1460 _if__(_COFF__)
1461 @node COFF Symbols,,,
1462 @subsection Symbol Attributes for COFF
1463 The COFF format supports a multitude of auxiliary symbol attributes;
1464 like the primary symbol attributes, they are set between @code{.def} and
1465 @code{.endef} directives.
1466
1467 @subsubsection Primary Attributes
1468 The symbol name is set with @code{.def}; the value and type,
1469 respectively, with @code{.val} and @code{.type}.
1470
1471 @subsubsection Auxiliary Attributes
1472 The @code{_AS__} directives @code{.dim}, @code{.line}, @code{.scl},
1473 @code{.size}, and @code{.tag} can generate auxiliary symbol table
1474 information for COFF.
1475 _fi__(_COFF__)
1476
1477 @node Expressions, Pseudo Ops, Symbols, Top
1478 @chapter Expressions
1479 An @dfn{expression} specifies an address or numeric value.
1480 Whitespace may precede and/or follow an expression.
1481
1482 @node Empty Exprs, Integer Exprs, Expressions, Expressions
1483 @section Empty Expressions
1484 An empty expression has no value: it is just whitespace or null.
1485 Wherever an absolute expression is required, you may omit the
1486 expression and @code{_AS__} will assume a value of (absolute) 0. This
1487 is compatible with other assemblers.
1488
1489 @node Integer Exprs, , Empty Exprs, Expressions
1490 @section Integer Expressions
1491 An @dfn{integer expression} is one or more @emph{arguments} delimited
1492 by @emph{operators}.
1493
1494 @node Arguments, Operators, Integer Exprs, Integer Exprs
1495 @subsection Arguments
1496
1497 @dfn{Arguments} are symbols, numbers or subexpressions. In other
1498 contexts arguments are sometimes called ``arithmetic operands''. In
1499 this manual, to avoid confusing them with the ``instruction operands'' of
1500 the machine language, we use the term ``argument'' to refer to parts of
1501 expressions only, reserving the word ``operand'' to refer only to machine
1502 instruction operands.
1503
1504 Symbols are evaluated to yield @{@var{segment} @var{NNN}@} where
1505 @var{segment} is one of text, data, bss, absolute,
1506 or undefined. @var{NNN} is a signed, 2's complement 32 bit
1507 integer.
1508
1509 Numbers are usually integers.
1510
1511 A number can be a flonum or bignum. In this case, you are warned
1512 that only the low order 32 bits are used, and @code{_AS__} pretends
1513 these 32 bits are an integer. You may write integer-manipulating
1514 instructions that act on exotic constants, compatible with other
1515 assemblers.
1516
1517 Subexpressions are a left parenthesis @samp{(} followed by an integer
1518 expression, followed by a right parenthesis @samp{)}; or a prefix
1519 operator followed by an argument.
1520
1521 @node Operators, Prefix Ops, Arguments, Integer Exprs
1522 @subsection Operators
1523 @dfn{Operators} are arithmetic functions, like @code{+} or @code{%}. Prefix
1524 operators are followed by an argument. Infix operators appear
1525 between their arguments. Operators may be preceded and/or followed by
1526 whitespace.
1527
1528 @node Prefix Ops, Infix Ops, Operators, Integer Exprs
1529 @subsection Prefix Operators
1530 @code{_AS__} has the following @dfn{prefix operators}. They each take
1531 one argument, which must be absolute.
1532
1533 @c the tex/end tex stuff surrounding this small table is meant to make
1534 @c it align, on the printed page, with the similar table in the next
1535 @c section (which is inside an enumerate).
1536 @tex
1537 \global\advance\leftskip by \itemindent
1538 @end tex
1539
1540 @table @code
1541 @item -
1542 @dfn{Negation}. Two's complement negation.
1543 @item ~
1544 @dfn{Complementation}. Bitwise not.
1545 @end table
1546
1547 @tex
1548 \global\advance\leftskip by -\itemindent
1549 @end tex
1550
1551 @node Infix Ops, , Prefix Ops, Integer Exprs
1552 @subsection Infix Operators
1553
1554 @dfn{Infix operators} take two arguments, one on either side. Operators
1555 have precedence, but operations with equal precedence are performed left
1556 to right. Apart from @code{+} or @code{-}, both arguments must be
1557 absolute, and the result is absolute.
1558
1559 @enumerate
1560
1561 @item
1562 Highest Precedence
1563 @table @code
1564 @item *
1565 @dfn{Multiplication}.
1566 @item /
1567 @dfn{Division}. Truncation is the same as the C operator @samp{/}
1568 @item %
1569 @dfn{Remainder}.
1570 @item _0__<_1__
1571 @itemx _0__<<_1__
1572 @dfn{Shift Left}. Same as the C operator @samp{_0__<<_1__}
1573 @item _0__>_1__
1574 @itemx _0__>>_1__
1575 @dfn{Shift Right}. Same as the C operator @samp{_0__>>_1__}
1576 @end table
1577
1578 @item
1579 Intermediate precedence
1580 @table @code
1581 @item |
1582 @dfn{Bitwise Inclusive Or}.
1583 @item &
1584 @dfn{Bitwise And}.
1585 @item ^
1586 @dfn{Bitwise Exclusive Or}.
1587 @item !
1588 @dfn{Bitwise Or Not}.
1589 @end table
1590
1591 @item
1592 Lowest Precedence
1593 @table @code
1594 @item +
1595 @dfn{Addition}. If either argument is absolute, the result
1596 has the segment of the other argument.
1597 If either argument is pass1 or undefined, the result is pass1.
1598 Otherwise @code{+} is illegal.
1599 @item -
1600 @dfn{Subtraction}. If the right argument is absolute, the
1601 result has the segment of the left argument.
1602 If either argument is pass1 the result is pass1.
1603 If either argument is undefined the result is difference segment.
1604 If both arguments are in the same segment, the result is absolute---provided
1605 that segment is one of text, data or bss.
1606 Otherwise subtraction is illegal.
1607 @end table
1608 @end enumerate
1609
1610 The sense of the rule for addition is that it's only meaningful to add
1611 the @emph{offsets} in an address; you can only have a defined segment in
1612 one of the two arguments.
1613
1614 Similarly, you can't subtract quantities from two different segments.
1615
1616 @node Pseudo Ops, _MACH_DEP__, Expressions, Top
1617 @chapter Assembler Directives
1618
1619 All assembler directives have names that begin with a period (@samp{.}).
1620 The rest of the name is letters: their case does not matter.
1621
1622 This chapter discusses directives present regardless of the target
1623 machine configuration for the GNU assembler; @pxref{_MACH_DEP__} for
1624 additional directives.
1625
1626 @node Abort,,,
1627 @section @code{.abort}
1628 This directive stops the assembly immediately. It is for
1629 compatibility with other assemblers. The original idea was that the
1630 assembly language source would be piped into the assembler. If the sender
1631 of the source quit, it could use this directive tells @code{_AS__} to
1632 quit also. One day @code{.abort} will not be supported.
1633
1634 _if__(_COFF__)
1635 @node coff-ABORT,,,
1636 @section @code{.ABORT}
1637 When producing COFF output, @code{_AS__} accepts this directive as a
1638 synonym for @samp{.abort}.
1639 _fi__(_COFF__)
1640 _if__(_BOUT__)
1641 _if__(!_COFF__)
1642 @node bout-ABORT,,,
1643 @section @code{.ABORT}
1644 _fi__(!_COFF__)
1645
1646 When producing @code{b.out} output, @code{_AS__} accepts this directive,
1647 but ignores it.
1648 _fi__(_BOUT__)
1649
1650 @node Align,,,
1651 @section @code{.align @var{abs-expr} , @var{abs-expr}}
1652 Pad the location counter (in the current subsegment) to a particular
1653 storage boundary. The first expression (which must be absolute) is the
1654 number of low-order zero bits the location counter will have after
1655 advancement. For example @samp{.align 3} will advance the location
1656 counter until it a multiple of 8. If the location counter is already a
1657 multiple of 8, no change is needed.
1658
1659 The second expression (also absolute) gives the value to be stored in
1660 the padding bytes. It (and the comma) may be omitted. If it is
1661 omitted, the padding bytes are zero.
1662
1663 @node App-File,,,
1664 @section @code{.app-file @var{string}}
1665 @code{.app-file}
1666 _if__(!_AMD29K__)
1667 (which may also be spelled @samp{.file})
1668 _fi__(!_AMD29K__)
1669 tells @code{_AS__} that we are about to start a new
1670 logical file. @var{string} is the new file name. In general, the
1671 filename is recognized whether or not it is surrounded by quotes @samp{"};
1672 but if you wish to specify an empty file name is permitted,
1673 you must give the quotes--@code{""}. This statement may go away in
1674 future: it is only recognized to be compatible with old @code{_AS__}
1675 programs.@refill
1676
1677 @node Ascii,,,
1678 @section @code{.ascii "@var{string}"}@dots{}
1679 @code{.ascii} expects zero or more string literals (@pxref{Strings})
1680 separated by commas. It assembles each string (with no automatic
1681 trailing zero byte) into consecutive addresses.
1682
1683 @node Asciz, Byte, Ascii, Pseudo Ops
1684 @section @code{.asciz "@var{string}"}@dots{}
1685 @code{.asciz} is just like @code{.ascii}, but each string is followed by
1686 a zero byte. The ``z'' in @samp{.asciz} stands for ``zero''.
1687
1688 @node Byte, Comm, Asciz, Pseudo Ops
1689 @section @code{.byte @var{expressions}}
1690
1691 @code{.byte} expects zero or more expressions, separated by commas.
1692 Each expression is assembled into the next byte.
1693
1694 @node Comm, Data, Byte, Pseudo Ops
1695 @section @code{.comm @var{symbol} , @var{length} }
1696 @code{.comm} declares a named common area in the bss segment. Normally
1697 @code{_LD__} reserves memory addresses for it during linking, so no partial
1698 program defines the location of the symbol. Use @code{.comm} to tell
1699 @code{_LD__} that it must be at least @var{length} bytes long. @code{_LD__}
1700 will allocate space for each @code{.comm} symbol that is at least as
1701 long as the longest @code{.comm} request in any of the partial programs
1702 linked. @var{length} is an absolute expression.
1703
1704 @node Data, Desc, Comm, Pseudo Ops
1705 @section @code{.data @var{subsegment}}
1706 @code{.data} tells @code{_AS__} to assemble the following statements onto the
1707 end of the data subsegment numbered @var{subsegment} (which is an
1708 absolute expression). If @var{subsegment} is omitted, it defaults
1709 to zero.
1710
1711 _if__(_COFF__)
1712 @node Def,,,
1713 @section @code{.def @var{name}}
1714 Begin defining debugging information for a symbol @var{name}; the
1715 definition extends until the @code{.endef} directive is encountered.
1716 _if__(_BOUT__)
1717
1718 This directive is only observed when @code{_AS__} is configured for COFF
1719 format output; when producing @code{b.out}, @samp{.def} is recognized,
1720 but ignored.
1721 _fi__(_BOUT__)
1722 _fi__(_COFF__)
1723
1724 _if__(_AOUT__||_BOUT__)
1725 @node Desc, Double, Data, Pseudo Ops
1726 @section @code{.desc @var{symbol}, @var{abs-expression}}
1727 This directive sets the descriptor of the symbol (@pxref{Symbol Attributes})
1728 to the low 16 bits of an absolute expression.
1729
1730 _if__(_COFF__)
1731 The @samp{.desc} directive is not available when @code{_AS__} is
1732 configured for COFF output; it is only for @code{a.out} or @code{b.out}
1733 object format. For the sake of compatibility, @code{_AS__} will accept
1734 it, but produce no output, when configured for COFF.
1735 _fi__(_COFF__)
1736 _fi__(_AOUT__||_BOUT__)
1737
1738 _if__(_COFF__)
1739 @node Dim,,,
1740 @section @code{.dim}
1741 This directive is generated by compilers to include auxiliary debugging
1742 information in the symbol table. It is only permitted inside
1743 @code{.def}/@code{.endef} pairs.
1744 _if__(_BOUT__)
1745
1746 @samp{.dim} is only meaningful when generating COFF format output; when
1747 @code{_AS__} is generating @code{b.out}, it accepts this directive but
1748 ignores it.
1749 _fi__(_BOUT__)
1750 _fi__(_COFF__)
1751
1752 @node Double, Else, Desc, Pseudo Ops
1753 @section @code{.double @var{flonums}}
1754 @code{.double} expects zero or more flonums, separated by commas. It
1755 assembles floating point numbers.
1756 _if__(_GENERIC__)
1757 The exact kind of floating point numbers emitted depends on how
1758 @code{_AS__} is configured. @xref{_MACH_DEP__}.
1759 _fi__(_GENERIC__)
1760 _if__((!_GENERIC__) && (_AMD29K__ || _I960__))
1761 On the _HOST__ family @samp{.double} emits 64-bit floating-point numbers
1762 in IEEE format.
1763 _fi__((!_GENERIC__) && (_AMD29K__ || _I960__))
1764
1765 @node Else,,,
1766 @section @code{.else}
1767 @code{.else} is part of the @code{_AS__} support for conditional assembly;
1768 @pxref{If}. It marks the beginning of a section of code to be assembled
1769 if the condition for the preceding @code{.if} was false.
1770
1771 _if__(0)
1772 @node End,,,
1773 @section @code{.end}
1774 This doesn't do anything---but isn't an s_ignore, so I suspect it's
1775 meant to do something eventually (which is why it isn't documented here
1776 as "for compatibility with blah").
1777 _fi__(0)
1778
1779 _if__(_COFF__)
1780 @node Endef,,,
1781 @section @code{.endef}
1782 This directive flags the end of a symbol definition begun with
1783 @code{.def}.
1784 _if__(_BOUT__)
1785
1786 @samp{.endef} is only meaningful when generating COFF format output; if
1787 @code{_AS__} is configured to generate @code{b.out}, it accepts this
1788 directive but ignores it.
1789 _fi__(_BOUT__)
1790 _fi__(_COFF__)
1791
1792 @node Endif, Equ, End, Pseudo Ops
1793 @section @code{.endif}
1794 @code{.endif} is part of the @code{_AS__} support for conditional assembly;
1795 it marks the end of a block of code that is only assembled
1796 conditionally. @xref{If}.
1797
1798 @node Equ, Extern, Endif, Pseudo Ops
1799 @section @code{.equ @var{symbol}, @var{expression}}
1800
1801 This directive sets the value of @var{symbol} to @var{expression}.
1802 It is synonymous with @samp{.set}; @pxref{Set}.
1803
1804 @node Extern,,,
1805 @section @code{.extern}
1806 @code{.extern} is accepted in the source program---for compatibility
1807 with other assemblers---but it is ignored. @code{_AS__} treats
1808 all undefined symbols as external.
1809
1810 _if__(!_AMD29K__)
1811 @node File,,,
1812 @section @code{.app-file @var{string}}
1813 @code{.file} (which may also be spelled @samp{.app-file}) tells
1814 @code{_AS__} that we are about to start a new logical file.
1815 @var{string} is the new file name. In general, the filename is
1816 recognized whether or not it is surrounded by quotes @samp{"}; but if
1817 you wish to specify an empty file name, you must give the
1818 quotes--@code{""}. This statement may go away in future: it is only
1819 recognized to be compatible with old @code{_AS__} programs.
1820 _fi__(!_AMD29K__)
1821
1822
1823 @node Fill,,,
1824 @section @code{.fill @var{repeat} , @var{size} , @var{value}}
1825 @var{result}, @var{size} and @var{value} are absolute expressions.
1826 This emits @var{repeat} copies of @var{size} bytes. @var{Repeat}
1827 may be zero or more. @var{Size} may be zero or more, but if it is
1828 more than 8, then it is deemed to have the value 8, compatible with
1829 other people's assemblers. The contents of each @var{repeat} bytes
1830 is taken from an 8-byte number. The highest order 4 bytes are
1831 zero. The lowest order 4 bytes are @var{value} rendered in the
1832 byte-order of an integer on the computer @code{_AS__} is assembling for.
1833 Each @var{size} bytes in a repetition is taken from the lowest order
1834 @var{size} bytes of this number. Again, this bizarre behavior is
1835 compatible with other people's assemblers.
1836
1837 @var{size} and @var{value} are optional.
1838 If the second comma and @var{value} are absent, @var{value} is
1839 assumed zero. If the first comma and following tokens are absent,
1840 @var{size} is assumed to be 1.
1841
1842 @node Float, Global, Fill, Pseudo Ops
1843 @section @code{.float @var{flonums}}
1844 This directive assembles zero or more flonums, separated by commas. It
1845 has the same effect as @code{.single}.
1846 _if__(_GENERIC__)
1847 The exact kind of floating point numbers emitted depends on how
1848 @code{_AS__} is configured.
1849 @xref{_MACH_DEP__}.
1850 _fi__(_GENERIC__)
1851 _if__((!_GENERIC__) && (_AMD29K__ || _I960__))
1852 On the _HOST__ family, @code{.float} emits 32-bit floating point numbers
1853 in IEEE format.
1854 _fi__((!_GENERIC__) && (_AMD29K__ || _I960__))
1855
1856 @node Global, Ident, Float, Pseudo Ops
1857 @section @code{.global @var{symbol}}, @code{.globl @var{symbol}}
1858 @code{.global} makes the symbol visible to @code{_LD__}. If you define
1859 @var{symbol} in your partial program, its value is made available to
1860 other partial programs that are linked with it. Otherwise,
1861 @var{symbol} will take its attributes from a symbol of the same name
1862 from another partial program it is linked with.
1863
1864 _if__(!_I960__)
1865 @c FIXME BFD implications; this is different in COFF.
1866 This is done by setting the @code{N_EXT} bit of that symbol's type byte
1867 to 1. @xref{Symbol Attributes}.
1868 _fi__(!_I960__)
1869
1870 Both spellings (@samp{.globl} and @samp{.global}) are accepted, for
1871 compatibility with other assemblers.
1872
1873 @node hword, line, file, Machine Directives
1874 @section @code{.hword @var{expressions}}
1875 This expects zero or more @var{expressions}, and emits
1876 a 16 bit number for each.
1877
1878 _if__(_GENERIC__)
1879 This directive is a synonym for @samp{.short}; depending on the target
1880 architecture, it may also be a synonym for @samp{.word}.
1881 _fi__(_GENERIC__)
1882 _if__( (_AMD29K__ || _I960__) && !_GENERIC__ )
1883 This directive is a synonym for @samp{.short}.
1884 _fi__( (_AMD29K__ || _I960__) && !_GENERIC__ )
1885
1886 _if__(_AOUT__||_BOUT__||_COFF__)
1887 @node Ident, If, Global, Pseudo Ops
1888 @section @code{.ident}
1889 This directive is used by some assemblers to place tags in object files.
1890 @code{_AS__} simply accepts the directive for source-file
1891 compatibility with such assemblers, but does not actually emit anything
1892 for it.
1893 _fi__(_AOUT__||_BOUT__||_COFF__)
1894
1895 @node If, Include, Ident, Pseudo Ops
1896 @section @code{.if @var{absolute expression}}
1897 @code{.if} marks the beginning of a section of code which is only
1898 considered part of the source program being assembled if the argument
1899 (which must be an @var{absolute expression}) is non-zero. The end of
1900 the conditional section of code must be marked by @code{.endif}
1901 (@pxref{Endif}); optionally, you may include code for the
1902 alternative condition, flagged by @code{.else} (@pxref{Else}.
1903
1904 The following variants of @code{.if} are also supported:
1905 @table @code
1906 @item ifdef @var{symbol}
1907 Assembles the following section of code if the specified @var{symbol}
1908 has been defined.
1909
1910 _if__(0)
1911 @item ifeqs
1912 Not yet implemented.
1913 _fi__(0)
1914
1915 @item ifndef @var{symbol}
1916 @itemx ifnotdef @var{symbol}
1917 Assembles the following section of code if the specified @var{symbol}
1918 has not been defined. Both spelling variants are equivalent.
1919
1920 _if__(0)
1921 @item ifnes
1922 Not yet implemented.
1923 _fi__(0)
1924 @end table
1925
1926 @node Include, Int, If, Pseudo Ops
1927 @section @code{.include "@var{file}"}
1928 This directive provides a way to include supporting files at specified
1929 points in your source program. The code from @var{file} is assembled as
1930 if it followed the point of the @code{.include}; when the end of the
1931 included file is reached, assembly of the original file continues. You
1932 can control the search paths used with the @samp{-I} command-line option
1933 (@pxref{Options}). Quotation marks are required around @var{file}.
1934
1935 @node Int, Lcomm, Include, Pseudo Ops
1936 @section @code{.int @var{expressions}}
1937 Expect zero or more @var{expressions}, of any segment, separated by
1938 commas. For each expression, emit a 32-bit number that will, at run
1939 time, be the value of that expression. The byte order of the
1940 expression depends on what kind of computer will run the program.
1941
1942 @node Lcomm, Line, Int, Pseudo Ops
1943 @section @code{.lcomm @var{symbol} , @var{length}}
1944 Reserve @var{length} (an absolute expression) bytes for a local
1945 common denoted by @var{symbol}. The segment and value of @var{symbol} are
1946 those of the new local common. The addresses are allocated in the
1947 bss segment, so at run-time the bytes will start off zeroed.
1948 @var{Symbol} is not declared global (@pxref{Global}), so is normally
1949 not visible to @code{_LD__}.
1950
1951 _if__(_AOUT__||_BOUT__||_COFF__)
1952 _if__(!_AMD29K__)
1953 @node Line,,,
1954 @section @code{.line @var{line-number}}
1955 _fi__(!_AMD29K__)
1956 _if__(_AMD29K__)
1957 @node Ln,,,
1958 @section @code{.ln @var{line-number}}
1959 _fi__(_AMD29K__)
1960 _fi__(_AOUT__||_BOUT__||_COFF__)
1961 _if__(_AOUT__||_BOUT__)
1962 Tell @code{_AS__} to change the logical line number. @var{line-number} must be
1963 an absolute expression. The next line will have that logical line
1964 number. So any other statements on the current line (after a statement
1965 separator character
1966 _if__(_AMD29K__)
1967 @samp{@@})
1968 _fi__(_AMD29K__)
1969 _if__(!_AMD29K__)
1970 @code{;})
1971 _fi__(!_AMD29K__)
1972 will be reported as on logical line number
1973 @var{line-number} @minus{} 1.
1974 One day this directive will be unsupported: it is used only
1975 for compatibility with existing assembler programs. @refill
1976 _fi__(_AOUT__||_BOUT__)
1977 _if__(_COFF__)
1978
1979 Even though this is a directive associated with the @code{a.out} or
1980 @code{b.out} object-code formats, @code{_AS__} will still recognize it
1981 when producing COFF output, and will treat @samp{.line} as though it
1982 were the COFF @samp{.ln} @emph{if} it is found outside a
1983 @code{.def}/@code{.endef} pair.
1984
1985 Inside a @code{.def}, @samp{.line} is, instead, one of the directives
1986 used by compilers to generate auxiliary symbol information for
1987 debugging.
1988 _fi__(_COFF__)
1989
1990 _if__(_AOUT__&&!_AMD29K__)
1991 @node Ln,,,
1992 @section @code{.ln @var{line-number}}
1993 @samp{.ln} is a synonym for @samp{.line}.
1994 _fi__(_AOUT__&&!_AMD29K__)
1995
1996 _if__(_COFF__&&!_AOUT__)
1997 @node Ln,,,
1998 @section @code{.ln @var{line-number}}
1999 Tell @code{_AS__} to change the logical line number. @var{line-number}
2000 must be an absolute expression. The next line will have that logical
2001 line number. So any other statements on the current line (after a
2002 statement separator character @code{;}) will be reported as on logical
2003 line number @var{line-number} @minus{} 1.
2004 _if__(_BOUT__)
2005
2006 This directive is accepted, but ignored, when @code{_AS__} is configured for
2007 @code{b.out}; its effect is only associated with COFF output format.
2008 _fi__(_BOUT__)
2009 _fi__(_COFF__&&!_AOUT__)
2010
2011 @node List,,,
2012 @section @code{.list} and related directives
2013 @code{_AS__} ignores the directives @code{.list}, @code{.nolist},
2014 @code{.eject}, @code{.lflags}, @code{.title}, @code{.sbttl}; however,
2015 they're accepted for compatibility with assemblers that use them.
2016
2017 @node Long, Lsym, List, Pseudo Ops
2018 @section @code{.long @var{expressions}}
2019 @code{.long} is the same as @samp{.int}, @pxref{Int}.
2020
2021 @node Lsym, Octa, Long, Pseudo Ops
2022 @section @code{.lsym @var{symbol}, @var{expression}}
2023 @code{.lsym} creates a new symbol named @var{symbol}, but does not put it in
2024 the hash table, ensuring it cannot be referenced by name during the
2025 rest of the assembly. This sets the attributes of the symbol to be
2026 the same as the expression value:
2027 @smallexample
2028 @var{other} = @var{descriptor} = 0
2029 @var{type} = @r{(segment of @var{expression})}
2030 @var{value} = @var{expression}
2031 @end smallexample
2032 @noindent
2033 The new symbol is not flagged as external.
2034
2035 @c FIXME: double size emitted for "octa" on i960, others? Or warn?
2036 @node Octa, Org, Lsym, Pseudo Ops
2037 @section @code{.octa @var{bignums}}
2038 This directive expects zero or more bignums, separated by commas. For each
2039 bignum, it emits a 16-byte integer.
2040
2041 The term ``octa'' comes from contexts in which a ``word'' is two bytes;
2042 hence @emph{octa}-word for 16 bytes.
2043
2044 @node Org, Quad, Octa, Pseudo Ops
2045 @section @code{.org @var{new-lc} , @var{fill}}
2046
2047 @code{.org} will advance the location counter of the current segment to
2048 @var{new-lc}. @var{new-lc} is either an absolute expression or an
2049 expression with the same segment as the current subsegment. That is,
2050 you can't use @code{.org} to cross segments: if @var{new-lc} has the
2051 wrong segment, the @code{.org} directive is ignored. To be compatible
2052 with former assemblers, if the segment of @var{new-lc} is absolute,
2053 @code{_AS__} will issue a warning, then pretend the segment of @var{new-lc}
2054 is the same as the current subsegment.
2055
2056 @code{.org} may only increase the location counter, or leave it
2057 unchanged; you cannot use @code{.org} to move the location counter
2058 backwards.
2059
2060 @c double negative used below "not undefined" because this is a specific
2061 @c reference to "undefined" (as SEG_UNKNOWN is called in this manual)
2062 @c segment. pesch@cygnus.com 18feb91
2063 Because @code{_AS__} tries to assemble programs in one pass @var{new-lc}
2064 may not be undefined. If you really detest this restriction we eagerly await
2065 a chance to share your improved assembler.
2066
2067 Beware that the origin is relative to the start of the segment, not
2068 to the start of the subsegment. This is compatible with other
2069 people's assemblers.
2070
2071 When the location counter (of the current subsegment) is advanced, the
2072 intervening bytes are filled with @var{fill} which should be an
2073 absolute expression. If the comma and @var{fill} are omitted,
2074 @var{fill} defaults to zero.
2075
2076 @node Quad, Set, Org, Pseudo Ops
2077 @section @code{.quad @var{bignums}}
2078 @code{.quad} expects zero or more bignums, separated by commas. For
2079 each bignum, it emits
2080 _if__(!_I960__)
2081 an 8-byte integer. If the bignum won't fit in 8
2082 bytes, it prints a warning message; and just takes the lowest order 8
2083 bytes of the bignum.@refill
2084
2085 The term ``quad'' comes from contexts in which a ``word'' is two bytes;
2086 hence @emph{quad}-word for 8 bytes.
2087 _fi__(!_I960__)
2088 _if__(_I960__)
2089 a 16-byte integer. If the bignum won't fit in 16 bytes, it prints a
2090 warning message; and just takes the lowest order 16 bytes of the
2091 bignum.@refill
2092 _fi__(_I960__)
2093
2094 _if__(_COFF__)
2095 @node Scl,,,
2096 @section @code{.scl @var{class}}
2097 Set the storage-class value for a symbol. This directive may only be
2098 used inside a @code{.def}/@code{.endef} pair. Storage class may flag
2099 whether a symbol is static or external, or it may record further
2100 symbolic debugging information.
2101 _if__(_BOUT__)
2102
2103 The @samp{.scl} directive is primarily associated with COFF output; when
2104 configured to generate @code{b.out} output format, @code{_AS__} will
2105 accept this directive but ignore it.
2106 _fi__(_BOUT__)
2107 _fi__(_COFF__)
2108
2109
2110 @node Set,,,
2111 @section @code{.set @var{symbol}, @var{expression}}
2112
2113 This directive sets the value of @var{symbol} to @var{expression}. This
2114 will change @var{symbol}'s value and type to conform to
2115 @var{expression}. If @var{symbol} was flagged as external, it remains
2116 flagged. (@xref{Symbol Attributes}.)
2117
2118 You may @code{.set} a symbol many times in the same assembly.
2119 If the expression's segment is unknowable during pass 1, a second
2120 pass over the source program will be forced. The second pass is
2121 currently not implemented. @code{_AS__} will abort with an error
2122 message if one is required.
2123
2124 If you @code{.set} a global symbol, the value stored in the object
2125 file is the last value stored into it.
2126
2127 @node Short, Single, Set, Pseudo Ops
2128 @section @code{.short @var{expressions}}
2129 _if__(_GENERIC__ && (! (_SPARC__ || _AMD29K__ || _I960__) ))
2130 @code{.short} is the same as @samp{.word}. @xref{Word}.
2131 _fi__(_GENERIC__ && (! (_SPARC__ || _AMD29K__ || _I960__) ))
2132 _if__((!_GENERIC__) && (_SPARC__ || _AMD29K__ || _I960__))
2133 This expects zero or more @var{expressions}, and emits
2134 a 16 bit number for each.
2135 _fi__((!_GENERIC__) && (_SPARC__ || _AMD29K__ || _I960__))
2136
2137 @node Single,,,
2138 @section @code{.single @var{flonums}}
2139 This directive assembles zero or more flonums, separated by commas. It
2140 has the same effect as @code{.float}.
2141 _if__(_GENERIC__)
2142 The exact kind of floating point numbers emitted depends on how
2143 @code{_AS__} is configured. @xref{_MACH_DEP__}.
2144 _fi__(_GENERIC__)
2145 _if__((!_GENERIC__) && (_AMD29K__ || _I960__ || _SPARC__))
2146 On the _HOST__ family, @code{.single} emits 32-bit floating point
2147 numbers in IEEE format.
2148 _fi__((!_GENERIC__) && (_AMD29K__ || _I960__ || _SPARC__))
2149
2150 _if__(_COFF__)
2151 @node Size,,,
2152 @section @code{.size}
2153 This directive is generated by compilers to include auxiliary debugging
2154 information in the symbol table. It is only permitted inside
2155 @code{.def}/@code{.endef} pairs.
2156 _if__(_BOUT__)
2157
2158 @samp{.size} is only meaningful when generating COFF format output; when
2159 @code{_AS__} is generating @code{b.out}, it accepts this directive but
2160 ignores it.
2161 _fi__(_BOUT__)
2162 _fi__(_COFF__)
2163
2164 @node Space,,,
2165 _if__(!_AMD29K__)
2166 @section @code{.space @var{size} , @var{fill}}
2167 This directive emits @var{size} bytes, each of value @var{fill}. Both
2168 @var{size} and @var{fill} are absolute expressions. If the comma
2169 and @var{fill} are omitted, @var{fill} is assumed to be zero.
2170 _fi__(!_AMD29K__)
2171
2172 _if__(_AMD29K__)
2173 @section @code{.space}
2174 This directive is ignored; it is accepted for compatibility with other
2175 AMD 29K assemblers.
2176
2177 @quotation
2178 @emph{Warning:} In other versions of the GNU assembler, the directive
2179 @code{.space} has the effect of @code{.block} @xref{_MACH_DEP__}.
2180 @end quotation
2181 _fi__(_AMD29K__)
2182
2183 _if__(_AOUT__||_BOUT__||_COFF__)
2184 @node Stab, Text, Space, Pseudo Ops
2185 @section @code{.stabd, .stabn, .stabs}
2186 There are three directives that begin @samp{.stab}.
2187 All emit symbols (@pxref{Symbols}), for use by symbolic debuggers.
2188 The symbols are not entered in the @code{_AS__} hash table: they
2189 cannot be referenced elsewhere in the source file.
2190 Up to five fields are required:
2191 @table @var
2192 @item string
2193 This is the symbol's name. It may contain any character except @samp{\000},
2194 so is more general than ordinary symbol names. Some debuggers used to
2195 code arbitrarily complex structures into symbol names using this field.
2196 @item type
2197 An absolute expression. The symbol's type is set to the low 8
2198 bits of this expression.
2199 Any bit pattern is permitted, but @code{_LD__} and debuggers will choke on
2200 silly bit patterns.
2201 @item other
2202 An absolute expression.
2203 The symbol's ``other'' attribute is set to the low 8 bits of this expression.
2204 @item desc
2205 An absolute expression.
2206 The symbol's descriptor is set to the low 16 bits of this expression.
2207 @item value
2208 An absolute expression which becomes the symbol's value.
2209 @end table
2210
2211 If a warning is detected while reading a @code{.stabd}, @code{.stabn},
2212 or @code{.stabs} statement, the symbol has probably already been created
2213 and you will get a half-formed symbol in your object file. This is
2214 compatible with earlier assemblers!
2215
2216 @table @code
2217 @item .stabd @var{type} , @var{other} , @var{desc}
2218
2219 The ``name'' of the symbol generated is not even an empty string.
2220 It is a null pointer, for compatibility. Older assemblers used a
2221 null pointer so they didn't waste space in object files with empty
2222 strings.
2223
2224 The symbol's value is set to the location counter,
2225 relocatably. When your program is linked, the value of this symbol
2226 will be where the location counter was when the @code{.stabd} was
2227 assembled.
2228
2229 @item .stabn @var{type} , @var{other} , @var{desc} , @var{value}
2230
2231 The name of the symbol is set to the empty string @code{""}.
2232
2233 @item .stabs @var{string} , @var{type} , @var{other} , @var{desc} , @var{value}
2234
2235 All five fields are specified.
2236 @end table
2237 _fi__(_AOUT__||_BOUT__||_COFF__)
2238
2239 _if__(_COFF__)
2240 @node Tag,,,
2241 @section @code{.tag @var{structname}}
2242 This directive is generated by compilers to include auxiliary debugging
2243 information in the symbol table. It is only permitted inside
2244 @code{.def}/@code{.endef} pairs. Tags are used to link structure
2245 definitions in the symbol table with instances of those structures.
2246 _if__(_BOUT__)
2247
2248 @samp{.tag} is only used when generating COFF format output; when
2249 @code{_AS__} is generating @code{b.out}, it accepts this directive but
2250 ignores it.
2251 _fi__(_BOUT__)
2252 _fi__(_COFF__)
2253
2254 @node Text,,,
2255 @section @code{.text @var{subsegment}}
2256 Tells @code{_AS__} to assemble the following statements onto the end of
2257 the text subsegment numbered @var{subsegment}, which is an absolute
2258 expression. If @var{subsegment} is omitted, subsegment number zero
2259 is used.
2260
2261 _if__(_COFF__)
2262 @node Type,,,
2263 @section @code{.type @var{int}}
2264 This directive, permitted only within @code{.def}/@code{.endef} pairs,
2265 records the integer @var{int} as the type attribute of a symbol table entry.
2266 _if__(_BOUT__)
2267
2268 @samp{.type} is associated only with COFF format output; when
2269 @code{_AS__} is configured for @code{b.out} output, it accepts this
2270 directive but ignores it.
2271 _fi__(_BOUT__)
2272 _fi__(_COFF__)
2273
2274 _if__(_COFF__)
2275 @node Val,,,
2276 @section @code{.val @var{addr}}
2277 This directive, permitted only within @code{.def}/@code{.endef} pairs,
2278 records the address @var{addr} as the value attribute of a symbol table
2279 entry.
2280 _if__(_BOUT__)
2281
2282 @samp{.val} is used only for COFF output; when @code{_AS__} is
2283 configured for @code{b.out}, it accepts this directive but ignores it.
2284 _fi__(_BOUT__)
2285 _fi__(_COFF__)
2286
2287 @node Word,,,
2288 @section @code{.word @var{expressions}}
2289 This directive expects zero or more @var{expressions}, of any segment,
2290 separated by commas.
2291 _if__((!_GENERIC__) && (_SPARC__ || _AMD29K__ || _I960__))
2292 For each expression, @code{_AS__} emits a 32-bit number.
2293 _fi__((!_GENERIC__) && (_SPARC__ || _AMD29K__ || _I960__))
2294 _if__((!_GENERIC__) && (! (_SPARC__ || _AMD29K__ || _I960__) ))
2295 For each expression, @code{_AS__} emits a 16-bit number.
2296 _fi__((!_GENERIC__) && (! (_SPARC__ || _AMD29K__ || _I960__) ))
2297
2298 _if__(_GENERIC__)
2299 The size of the number emitted, and its byte order,
2300 depends on what kind of computer will run the program.
2301 _fi__(_GENERIC__)
2302
2303 @c on these boxes the "special treatment to support compilers" doesn't
2304 @c happen---32-bit addressability, period; no long/short jumps.
2305 _if__(_GENERIC__ || (! (_AMD29K__ || _I960__) ))
2306 @quotation
2307 @emph{Warning: Special Treatment to support Compilers}
2308 @end quotation
2309
2310 In order to assemble compiler output into something that will work,
2311 @code{_AS__} will occasionlly do strange things to @samp{.word} directives.
2312 Directives of the form @samp{.word sym1-sym2} are often emitted by
2313 compilers as part of jump tables. Therefore, when @code{_AS__} assembles a
2314 directive of the form @samp{.word sym1-sym2}, and the difference between
2315 @code{sym1} and @code{sym2} does not fit in 16 bits, @code{_AS__} will
2316 create a @dfn{secondary jump table}, immediately before the next label.
2317 This @var{secondary jump table} will be preceded by a short-jump to the
2318 first byte after the secondary table. This short-jump prevents the flow
2319 of control from accidentally falling into the new table. Inside the
2320 table will be a long-jump to @code{sym2}. The original @samp{.word}
2321 will contain @code{sym1} minus the address of the long-jump to
2322 @code{sym2}.
2323
2324 If there were several occurrences of @samp{.word sym1-sym2} before the
2325 secondary jump table, all of them will be adjusted. If there was a
2326 @samp{.word sym3-sym4}, that also did not fit in sixteen bits, a
2327 long-jump to @code{sym4} will be included in the secondary jump table,
2328 and the @code{.word} directives will be adjusted to contain @code{sym3}
2329 minus the address of the long-jump to @code{sym4}; and so on, for as many
2330 entries in the original jump table as necessary.
2331
2332 _if__(_INTERNALS__)
2333 @emph{This feature may be disabled by compiling @code{_AS__} with the
2334 @samp{-DWORKING_DOT_WORD} option.} This feature is likely to confuse
2335 assembly language programmers.
2336 _fi__(_INTERNALS__)
2337 _fi__(_GENERIC__ || (! (_AMD29K__ || _I960__) ))
2338
2339 @node Deprecated, _MACH_DEP__, Word, Pseudo Ops
2340 @section Deprecated Directives
2341 One day these directives won't work.
2342 They are included for compatibility with older assemblers.
2343 @table @t
2344 @item .abort
2345 @item .app-file
2346 @item .line
2347 @end table
2348
2349 @node _MACH_DEP__,,,
2350 _if__(_GENERIC__)
2351 @chapter Machine Dependent Features
2352 _fi__(_GENERIC__)
2353 _if__(_VAX__)
2354 @group
2355 _CHAPSEC__(0+_GENERIC__) VAX Dependent Features
2356 _CHAPSEC__(1+_GENERIC__) Options
2357
2358 The Vax version of @code{_AS__} accepts any of the following options,
2359 gives a warning message that the option was ignored and proceeds.
2360 These options are for compatibility with scripts designed for other
2361 people's assemblers.
2362 @end group
2363
2364 @table @asis
2365 @item @kbd{-D} (Debug)
2366 @itemx @kbd{-S} (Symbol Table)
2367 @itemx @kbd{-T} (Token Trace)
2368 These are obsolete options used to debug old assemblers.
2369
2370 @item @kbd{-d} (Displacement size for JUMPs)
2371 This option expects a number following the @kbd{-d}. Like options
2372 that expect filenames, the number may immediately follow the
2373 @kbd{-d} (old standard) or constitute the whole of the command line
2374 argument that follows @kbd{-d} (GNU standard).
2375
2376 @item @kbd{-V} (Virtualize Interpass Temporary File)
2377 Some other assemblers use a temporary file. This option
2378 commanded them to keep the information in active memory rather
2379 than in a disk file. @code{_AS__} always does this, so this
2380 option is redundant.
2381
2382 @item @kbd{-J} (JUMPify Longer Branches)
2383 Many 32-bit computers permit a variety of branch instructions
2384 to do the same job. Some of these instructions are short (and
2385 fast) but have a limited range; others are long (and slow) but
2386 can branch anywhere in virtual memory. Often there are 3
2387 flavors of branch: short, medium and long. Some other
2388 assemblers would emit short and medium branches, unless told by
2389 this option to emit short and long branches.
2390
2391 @item @kbd{-t} (Temporary File Directory)
2392 Some other assemblers may use a temporary file, and this option
2393 takes a filename being the directory to site the temporary
2394 file. @code{_AS__} does not use a temporary disk file, so this
2395 option makes no difference. @kbd{-t} needs exactly one
2396 filename.
2397 @end table
2398
2399 The Vax version of the assembler accepts two options when
2400 compiled for VMS. They are @kbd{-h}, and @kbd{-+}. The
2401 @kbd{-h} option prevents @code{_AS__} from modifying the
2402 symbol-table entries for symbols that contain lowercase
2403 characters (I think). The @kbd{-+} option causes @code{_AS__} to
2404 print warning messages if the FILENAME part of the object file,
2405 or any symbol name is larger than 31 characters. The @kbd{-+}
2406 option also insertes some code following the @samp{_main}
2407 symbol so that the object file will be compatible with Vax-11
2408 "C".
2409
2410 _CHAPSEC__(1+_GENERIC__) Floating Point
2411 Conversion of flonums to floating point is correct, and
2412 compatible with previous assemblers. Rounding is
2413 towards zero if the remainder is exactly half the least significant bit.
2414
2415 @code{D}, @code{F}, @code{G} and @code{H} floating point formats
2416 are understood.
2417
2418 Immediate floating literals (@emph{e.g.} @samp{S`$6.9})
2419 are rendered correctly. Again, rounding is towards zero in the
2420 boundary case.
2421
2422 The @code{.float} directive produces @code{f} format numbers.
2423 The @code{.double} directive produces @code{d} format numbers.
2424
2425 _CHAPSEC__(1+_GENERIC__) Vax Machine Directives
2426 The Vax version of the assembler supports four directives for
2427 generating Vax floating point constants. They are described in the
2428 table below.
2429
2430 @table @code
2431 @item .dfloat
2432 This expects zero or more flonums, separated by commas, and
2433 assembles Vax @code{d} format 64-bit floating point constants.
2434
2435 @item .ffloat
2436 This expects zero or more flonums, separated by commas, and
2437 assembles Vax @code{f} format 32-bit floating point constants.
2438
2439 @item .gfloat
2440 This expects zero or more flonums, separated by commas, and
2441 assembles Vax @code{g} format 64-bit floating point constants.
2442
2443 @item .hfloat
2444 This expects zero or more flonums, separated by commas, and
2445 assembles Vax @code{h} format 128-bit floating point constants.
2446
2447 @end table
2448
2449 _CHAPSEC__(1+_GENERIC__) Opcodes
2450 All DEC mnemonics are supported. Beware that @code{case@dots{}}
2451 instructions have exactly 3 operands. The dispatch table that
2452 follows the @code{case@dots{}} instruction should be made with
2453 @code{.word} statements. This is compatible with all unix
2454 assemblers we know of.
2455
2456 _CHAPSEC__(1+_GENERIC__) Branch Improvement
2457 Certain pseudo opcodes are permitted. They are for branch
2458 instructions. They expand to the shortest branch instruction that
2459 will reach the target. Generally these mnemonics are made by
2460 substituting @samp{j} for @samp{b} at the start of a DEC mnemonic.
2461 This feature is included both for compatibility and to help
2462 compilers. If you don't need this feature, don't use these
2463 opcodes. Here are the mnemonics, and the code they can expand into.
2464
2465 @table @code
2466 @item jbsb
2467 @samp{Jsb} is already an instruction mnemonic, so we chose @samp{jbsb}.
2468 @table @asis
2469 @item (byte displacement)
2470 @kbd{bsbb @dots{}}
2471 @item (word displacement)
2472 @kbd{bsbw @dots{}}
2473 @item (long displacement)
2474 @kbd{jsb @dots{}}
2475 @end table
2476 @item jbr
2477 @itemx jr
2478 Unconditional branch.
2479 @table @asis
2480 @item (byte displacement)
2481 @kbd{brb @dots{}}
2482 @item (word displacement)
2483 @kbd{brw @dots{}}
2484 @item (long displacement)
2485 @kbd{jmp @dots{}}
2486 @end table
2487 @item j@var{COND}
2488 @var{COND} may be any one of the conditional branches
2489 @code{neq nequ eql eqlu gtr geq lss gtru lequ vc vs gequ cc lssu cs}.
2490 @var{COND} may also be one of the bit tests
2491 @code{bs bc bss bcs bsc bcc bssi bcci lbs lbc}.
2492 @var{NOTCOND} is the opposite condition to @var{COND}.
2493 @table @asis
2494 @item (byte displacement)
2495 @kbd{b@var{COND} @dots{}}
2496 @item (word displacement)
2497 @kbd{b@var{NOTCOND} foo ; brw @dots{} ; foo:}
2498 @item (long displacement)
2499 @kbd{b@var{NOTCOND} foo ; jmp @dots{} ; foo:}
2500 @end table
2501 @item jacb@var{X}
2502 @var{X} may be one of @code{b d f g h l w}.
2503 @table @asis
2504 @item (word displacement)
2505 @kbd{@var{OPCODE} @dots{}}
2506 @item (long displacement)
2507 @example
2508 @var{OPCODE} @dots{}, foo ;
2509 brb bar ;
2510 foo: jmp @dots{} ;
2511 bar:
2512 @end example
2513 @end table
2514 @item jaob@var{YYY}
2515 @var{YYY} may be one of @code{lss leq}.
2516 @item jsob@var{ZZZ}
2517 @var{ZZZ} may be one of @code{geq gtr}.
2518 @table @asis
2519 @item (byte displacement)
2520 @kbd{@var{OPCODE} @dots{}}
2521 @item (word displacement)
2522 @example
2523 @var{OPCODE} @dots{}, foo ;
2524 brb bar ;
2525 foo: brw @var{destination} ;
2526 bar:
2527 @end example
2528 @item (long displacement)
2529 @example
2530 @var{OPCODE} @dots{}, foo ;
2531 brb bar ;
2532 foo: jmp @var{destination} ;
2533 bar:
2534 @end example
2535 @end table
2536 @item aobleq
2537 @itemx aoblss
2538 @itemx sobgeq
2539 @itemx sobgtr
2540 @table @asis
2541 @item (byte displacement)
2542 @kbd{@var{OPCODE} @dots{}}
2543 @item (word displacement)
2544 @example
2545 @var{OPCODE} @dots{}, foo ;
2546 brb bar ;
2547 foo: brw @var{destination} ;
2548 bar:
2549 @end example
2550 @item (long displacement)
2551 @example
2552 @var{OPCODE} @dots{}, foo ;
2553 brb bar ;
2554 foo: jmp @var{destination} ;
2555 bar:
2556 @end example
2557 @end table
2558 @end table
2559
2560 _CHAPSEC__(1+_GENERIC__) operands
2561 The immediate character is @samp{$} for Unix compatibility, not
2562 @samp{#} as DEC writes it.
2563
2564 The indirect character is @samp{*} for Unix compatibility, not
2565 @samp{@@} as DEC writes it.
2566
2567 The displacement sizing character is @samp{`} (an accent grave) for
2568 Unix compatibility, not @samp{^} as DEC writes it. The letter
2569 preceding @samp{`} may have either case. @samp{G} is not
2570 understood, but all other letters (@code{b i l s w}) are understood.
2571
2572 Register names understood are @code{r0 r1 r2 @dots{} r15 ap fp sp
2573 pc}. Any case of letters will do.
2574
2575 For instance
2576 @smallexample
2577 tstb *w`$4(r5)
2578 @end smallexample
2579
2580 Any expression is permitted in an operand. Operands are comma
2581 separated.
2582
2583 @c There is some bug to do with recognizing expressions
2584 @c in operands, but I forget what it is. It is
2585 @c a syntax clash because () is used as an address mode
2586 @c and to encapsulate sub-expressions.
2587 _CHAPSEC__(1+_GENERIC__) Not Supported
2588 Vax bit fields can not be assembled with @code{_AS__}. Someone
2589 can add the required code if they really need it.
2590
2591 _fi__(_VAX__)
2592 _if__(_AMD29K__)
2593 @group
2594 _CHAPSEC__(0+_GENERIC__) AMD 29K Dependent Features
2595 @node AMD29K Options, AMD29K Syntax, _MACH_DEP__, _MACH_DEP__
2596 _CHAPSEC__(1+_GENERIC__) Options
2597 @code{_AS__} has no additional command-line options for the AMD
2598 29K family.
2599 @end group
2600
2601 @node AMD29K Syntax, AMD29K Floating Point, AMD29K Options, _MACH_DEP__
2602 @group
2603 _CHAPSEC__(1+_GENERIC__) Syntax
2604 _CHAPSEC__(2+_GENERIC__) Special Characters
2605 @samp{;} is the line comment character.
2606
2607 @samp{@@} can be used instead of a newline to separate statements.
2608
2609 The character @samp{?} is permitted in identifiers (but may not begin
2610 an identifier).
2611 @end group
2612
2613 _CHAPSEC__(2+_GENERIC__) Register Names
2614 General-purpose registers are represented by predefined symbols of the
2615 form @samp{GR@var{nnn}} (for global registers) or @samp{LR@var{nnn}}
2616 (for local registers), where @var{nnn} represents a number between
2617 @code{0} and @code{127}, written with no leading zeros. The leading
2618 letters may be in either upper or lower case; for example, @samp{gr13}
2619 and @samp{LR7} are both valid register names.
2620
2621 You may also refer to general-purpose registers by specifying the
2622 register number as the result of an expression (prefixed with @samp{%%}
2623 to flag the expression as a register number):
2624 @smallexample
2625 %%@var{expression}
2626 @end smallexample
2627 @noindent---where @var{expression} must be an absolute expression
2628 evaluating to a number between @code{0} and @code{255}. The range
2629 [0, 127] refers to global registers, and the range [128, 255] to local
2630 registers.
2631
2632 In addition, @code{_AS__} understands the following protected
2633 special-purpose register names for the AMD 29K family:
2634
2635 @smallexample
2636 vab chd pc0
2637 ops chc pc1
2638 cps rbp pc2
2639 cfg tmc mmu
2640 cha tmr lru
2641 @end smallexample
2642
2643 These unprotected special-purpose register names are also recognized:
2644 @smallexample
2645 ipc alu fpe
2646 ipa bp inte
2647 ipb fc fps
2648 q cr exop
2649 @end smallexample
2650
2651 @node AMD29K Floating Point, AMD29K Directives, AMD29K Syntax, _MACH_DEP__
2652 _CHAPSEC__(1+_GENERIC__) Floating Point
2653 The AMD 29K family uses IEEE floating-point numbers.
2654
2655 @group
2656 @node AMD29K Directives, AMD29K Opcodes, AMD29K Floating Point, _MACH_DEP__
2657 _CHAPSEC__(1+_GENERIC__) AMD 29K Machine Directives
2658
2659 @table @code
2660 @item .block @var{size} , @var{fill}
2661 This directive emits @var{size} bytes, each of value @var{fill}. Both
2662 @var{size} and @var{fill} are absolute expressions. If the comma
2663 and @var{fill} are omitted, @var{fill} is assumed to be zero.
2664
2665 In other versions of the GNU assembler, this directive is called
2666 @samp{.space}.
2667 @end table
2668 @end group
2669
2670 @table @code
2671 @item .cputype
2672 This directive is ignored; it is accepted for compatibility with other
2673 AMD 29K assemblers.
2674
2675 @item .file
2676 This directive is ignored; it is accepted for compatibility with other
2677 AMD 29K assemblers.
2678
2679 @quotation
2680 @emph{Warning:} in other versions of the GNU assembler, @code{.file} is
2681 used for the directive called @code{.app-file} in the AMD 29K support.
2682 @end quotation
2683
2684 @item .line
2685 This directive is ignored; it is accepted for compatibility with other
2686 AMD 29K assemblers.
2687
2688 @item .reg @var{symbol}, @var{expression}
2689 @code{.reg} has the same effect as @code{.lsym}; @pxref{Lsym}.
2690
2691 @item .sect
2692 This directive is ignored; it is accepted for compatibility with other
2693 AMD 29K assemblers.
2694
2695 @item .use @var{segment name}
2696 Establishes the segment and subsegment for the following code;
2697 @var{segment name} may be one of @code{.text}, @code{.data},
2698 @code{.data1}, or @code{.lit}. With one of the first three @var{segment
2699 name} options, @samp{.use} is equivalent to the machine directive
2700 @var{segment name}; the remaining case, @samp{.use .lit}, is the same as
2701 @samp{.data 200}.
2702 @end table
2703
2704 @node AMD29K Opcodes, , AMD29K Directives, _MACH_DEP__
2705 @section Opcodes
2706 @code{_AS__} implements all the standard AMD 29K opcodes. No
2707 additional pseudo-instructions are needed on this family.
2708
2709 For information on the 29K machine instruction set, see @cite{Am29000
2710 User's Manual}, Advanced Micro Devices, Inc.
2711
2712 _fi__(_AMD29K__)
2713 _if__(_I960__)
2714 _CHAPSEC__(0+_GENERIC__) Intel 80960 Dependent Features
2715 @node Options-i960,,,
2716 _CHAPSEC__(1+_GENERIC__) Command-line Options
2717 @table @code
2718
2719 @item -ACA | -ACA_A | -ACB | -ACC | -AKA | -AKB | -AKC | -AMC
2720 Select the 80960 architecture. Instructions or features not supported
2721 by the selected architecture cause fatal errors.
2722
2723 @samp{-ACA} is equivalent to @samp{-ACA_A}; @samp{-AKC} is equivalent to
2724 @samp{-AMC}. Synonyms are provided for compatibility with other tools.
2725
2726 If none of these options is specified, @code{_AS__} will generate code for any
2727 instruction or feature that is supported by @emph{some} version of the
2728 960 (even if this means mixing architectures!). In principle,
2729 @code{_AS__} will attempt to deduce the minimal sufficient processor
2730 type if none is specified; depending on the object code format, the
2731 processor type may be recorded in the object file. If it is critical
2732 that the @code{_AS__} output match a specific architecture, specify that
2733 architecture explicitly.
2734
2735
2736 @item -b
2737 Add code to collect information about conditional branches taken, for
2738 later optimization using branch prediction bits. (The conditional branch
2739 instructions have branch prediction bits in the CA, CB, and CC
2740 architectures.) If @var{BR} represents a conditional branch instruction,
2741 the following represents the code generated by the assembler when
2742 @samp{-b} is specified:
2743
2744 @smallexample
2745 call @var{increment routine}
2746 .word 0 # pre-counter
2747 Label: @var{BR}
2748 call @var{increment routine}
2749 .word 0 # post-counter
2750 @end smallexample
2751
2752 The counter following a branch records the number of times that branch
2753 was @emph{not} taken; the differenc between the two counters is the
2754 number of times the branch @emph{was} taken.
2755
2756 A table of all such @code{Label}s is also generated, so that the
2757 external postprocessor @samp{gbr960} (supplied by Intel) can locate all
2758 the counters. This table is always labelled @samp{__BRANCH_TABLE__};
2759 this is a local symbol to permit collecting statistics for many separate
2760 object files. The table is word aligned, and begins with a two-word
2761 header. The first word, initialized to 0, is used in maintaining linked
2762 lists of branch tables. The second word is a count of the number of
2763 entries in the table, which follow immediately: each is a word, pointing
2764 to one of the labels illustrated above.
2765
2766 @ifinfo
2767 @example
2768 +------------+------------+------------+ ... +------------+
2769 | | | | | |
2770 | *NEXT | COUNT: N | *BRLAB 1 | | *BRLAB N |
2771 | | | | | |
2772 +------------+------------+------------+ ... +------------+
2773
2774 __BRANCH_TABLE__ layout
2775 @end example
2776 @end ifinfo
2777 @tex
2778 \vskip 1pc
2779 \line{\leftskip=0pt\hskip\tableindent
2780 \boxit{2cm}{\tt *NEXT}\boxit{2cm}{\tt COUNT: \it N}\boxit{2cm}{\tt
2781 *BRLAB 1}\ibox{1cm}{\quad\dots}\boxit{2cm}{\tt *BRLAB \it N}\hfil}
2782 \centerline{\it {\tt \_\_BRANCH\_TABLE\_\_} layout}
2783 @end tex
2784
2785 The first word of the header is used to locate multiple branch tables,
2786 since each object file may contain one. Normally the links are
2787 maintained with a call to an initialization routine, placed at the
2788 beginning of each function in the file. The GNU C compiler will
2789 generate these calls automatically when you give it a @samp{-b} option.
2790 For further details, see the documentation of @samp{gbr960}.
2791
2792 @item -norelax
2793 Normally, Compare-and-Branch instructions with targets that require
2794 displacements greater than 13 bits (or that have external targets) are
2795 replaced with the corresponding compare (or @samp{chkbit}) and branch
2796 instructions. You can use the @samp{-norelax} option to specify that
2797 @code{_AS__} should generate errors instead, if the target displacement
2798 is larger than 13 bits.
2799
2800 This option does not affect the Compare-and-Jump instructions; the code
2801 emitted for them is @emph{always} adjusted when necessary (depending on
2802 displacement size), regardless of whether you use @samp{-norelax}.
2803 @end table
2804
2805 @node Floating Point-i960,,,
2806 _CHAPSEC__(1+_GENERIC__) Floating Point
2807 @code{_AS__} generates IEEE floating-point numbers for the directives
2808 @samp{.float}, @samp{.double}, @samp{extended}, and @samp{.single}.
2809
2810 @group
2811 @node Directives-i960,,,
2812 _CHAPSEC__(1+_GENERIC__) i960 Machine Directives
2813
2814 @table @code
2815 @item .bss @var{symbol}, @var{length}, @var{align}
2816 Reserve @var{length} bytes in the bss segment for a local @var{symbol},
2817 aligned to the power of two specified by @var{align}. @var{length} and
2818 @var{align} must be positive absolute expressions. This directive
2819 differs from @samp{.lcomm} only in that it permits you to specify
2820 an alignment. @xref{Lcomm}.
2821 @end table
2822 @end group
2823
2824 @table @code
2825 @item .extended @var{flonums}
2826 @code{.extended} expects zero or more flonums, separated by commas; for
2827 each flonum, @samp{.extended} emits an IEEE extended-format (80-bit)
2828 floating-point number.
2829
2830 @item .leafproc @var{call-lab}, @var{bal-lab}
2831 You can use the @samp{.leafproc} directive in conjunction with the
2832 optimized @code{callj} instruction to enable faster calls of leaf
2833 procedures. If a procedure is known to call no other procedures, you
2834 may define an entry point that skips procedure prolog code (and that does
2835 not depend on system-supplied saved context), and declare it as the
2836 @var{bal-lab} using @samp{.leafproc}. If the procedure also has an
2837 entry point that goes through the normal prolog, you can specify that
2838 entry point as @var{call-lab}.
2839
2840 A @samp{.leafproc} declaration is meant for use in conjunction with the
2841 optimized call instruction @samp{callj}; the directive records the data
2842 needed later to choose between converting the @samp{callj} into a
2843 @code{bal} or a @code{call}.
2844
2845 @var{call-lab} is optional; if only one argument is present, or if the
2846 two arguments are identical, the single argument is assumed to be the
2847 @code{bal} entry point.
2848
2849 @item .sysproc @var{name}, @var{index}
2850 The @samp{.sysproc} directive defines a name for a system procedure.
2851 After you define it using @samp{.sysproc}, you can use @var{name} to
2852 refer to the system procedure identified by @var{index} when calling
2853 procedures with the optimized call instruction @samp{callj}.
2854
2855 Both arguments are required; @var{index} must be between 0 and 31
2856 (inclusive).
2857 @end table
2858
2859 @node Opcodes for i960,,,
2860 _CHAPSEC__(1+_GENERIC__) i960 Opcodes
2861 All Intel 960 machine instructions are supported; @pxref{Options-i960}
2862 for a discussion of selecting the instruction subset for a particular
2863 960 architecture.@refill
2864
2865 Some opcodes are processed beyond simply emitting a single corresponding
2866 instruction: @samp{callj}, and Compare-and-Branch or Compare-and-Jump
2867 instructions with target displacements larger than 13 bits.
2868
2869 @node callj-i960
2870 _CHAPSEC__(2+_GENERIC__) @code{callj}
2871 You can write @code{callj} to have the assembler or the linker determine
2872 the most appropriate form of subroutine call: @samp{call},
2873 @samp{bal}, or @samp{calls}. If the assembly source contains
2874 enough information---a @samp{.leafproc} or @samp{.sysproc} directive
2875 defining the operand---then @code{_AS__} will translate the
2876 @code{callj}; if not, it will simply emit the @code{callj}, leaving it
2877 for the linker to resolve.
2878
2879 @node Compare-and-branch-i960
2880 _CHAPSEC__(2+_GENERIC__) Compare-and-Branch
2881
2882 The 960 architectures provide combined Compare-and-Branch instructions
2883 that permit you to store the branch target in the lower 13 bits of the
2884 instruction word itself. However, if you specify a branch target far
2885 enough away that its address won't fit in 13 bits, the assembler can
2886 either issue an error, or convert your Compare-and-Branch instruction
2887 into separate instructions to do the compare and the branch.
2888
2889 Whether @code{_AS__} gives an error or expands the instruction depends
2890 on two choices you can make: whether you use the @samp{-norelax} option,
2891 and whether you use a ``Compare and Branch'' instruction or a ``Compare
2892 and Jump'' instruction. The ``Jump'' instructions are @emph{always}
2893 expanded if necessary; the ``Branch'' instructions are expanded when
2894 necessary @emph{unless} you specify @code{-norelax}---in which case
2895 @code{_AS__} gives an error instead.
2896
2897 @group
2898 These are the Compare-and-Branch instructions, their ``Jump'' variants,
2899 and the instruction pairs they may expand into:
2900
2901 @ifinfo
2902 @example
2903 Compare and
2904 Branch Jump Expanded to
2905 ------ ------ ------------
2906 bbc chkbit; bno
2907 bbs chkbit; bo
2908 cmpibe cmpije cmpi; be
2909 cmpibg cmpijg cmpi; bg
2910 cmpibge cmpijge cmpi; bge
2911 cmpibl cmpijl cmpi; bl
2912 cmpible cmpijle cmpi; ble
2913 cmpibno cmpijno cmpi; bno
2914 cmpibne cmpijne cmpi; bne
2915 cmpibo cmpijo cmpi; bo
2916 cmpobe cmpoje cmpo; be
2917 cmpobg cmpojg cmpo; bg
2918 cmpobge cmpojge cmpo; bge
2919 cmpobl cmpojl cmpo; bl
2920 cmpoble cmpojle cmpo; ble
2921 cmpobne cmpojne cmpo; bne
2922 @end example
2923 @end ifinfo
2924 @tex
2925 \hskip\tableindent
2926 \halign{\hfil {\tt #}\quad&\hfil {\tt #}\qquad&{\tt #}\hfil\cr
2927 \omit{\hfil\it Compare and\hfil}\span\omit&\cr
2928 {\it Branch}&{\it Jump}&{\it Expanded to}\cr
2929 bbc& & chkbit; bno\cr
2930 bbs& & chkbit; bo\cr
2931 cmpibe& cmpije& cmpi; be\cr
2932 cmpibg& cmpijg& cmpi; bg\cr
2933 cmpibge& cmpijge& cmpi; bge\cr
2934 cmpibl& cmpijl& cmpi; bl\cr
2935 cmpible& cmpijle& cmpi; ble\cr
2936 cmpibno& cmpijno& cmpi; bno\cr
2937 cmpibne& cmpijne& cmpi; bne\cr
2938 cmpibo& cmpijo& cmpi; bo\cr
2939 cmpobe& cmpoje& cmpo; be\cr
2940 cmpobg& cmpojg& cmpo; bg\cr
2941 cmpobge& cmpojge& cmpo; bge\cr
2942 cmpobl& cmpojl& cmpo; bl\cr
2943 cmpoble& cmpojle& cmpo; ble\cr
2944 cmpobne& cmpojne& cmpo; bne\cr}
2945 @end tex
2946 @end group
2947
2948 _fi__(_I960__)
2949 _if__(_M680X0__)
2950 @group
2951 _CHAPSEC__(0+_GENERIC__) M680x0 Dependent Features
2952 _CHAPSEC__(1+_GENERIC__) M680x0 Options
2953 The Motorola 680x0 version of @code{_AS__} has two machine dependent options.
2954 One shortens undefined references from 32 to 16 bits, while the
2955 other is used to tell @code{_AS__} what kind of machine it is
2956 assembling for.
2957 @end group
2958
2959 You can use the @kbd{-l} option to shorten the size of references to
2960 undefined symbols. If the @kbd{-l} option is not given, references to
2961 undefined symbols will be a full long (32 bits) wide. (Since @code{_AS__}
2962 cannot know where these symbols will end up, @code{_AS__} can only allocate
2963 space for the linker to fill in later. Since @code{_AS__} doesn't know how
2964 far away these symbols will be, it allocates as much space as it can.)
2965 If this option is given, the references will only be one word wide (16
2966 bits). This may be useful if you want the object file to be as small as
2967 possible, and you know that the relevant symbols will be less than 17
2968 bits away.
2969
2970 The 680x0 version of @code{_AS__} is most frequently used to assemble
2971 programs for the Motorola MC68020 microprocessor. Occasionally it is
2972 used to assemble programs for the mostly similar, but slightly different
2973 MC68000 or MC68010 microprocessors. You can give @code{_AS__} the options
2974 @samp{-m68000}, @samp{-mc68000}, @samp{-m68010}, @samp{-mc68010},
2975 @samp{-m68020}, and @samp{-mc68020} to tell it what processor is the
2976 target.
2977
2978 _CHAPSEC__(1+_GENERIC__) Syntax
2979
2980 The 680x0 version of @code{_AS__} uses syntax similar to the Sun assembler.
2981 Size modifiers are appended directly to the end of the opcode without an
2982 intervening period. For example, write @samp{movl} rather than
2983 @samp{move.l}.
2984
2985 _if__(_INTERNALS__)
2986 If @code{_AS__} is compiled with SUN_ASM_SYNTAX defined, it will also allow
2987 Sun-style local labels of the form @samp{1$} through @samp{$9}.
2988 _fi__(_INTERNALS__)
2989
2990 In the following table @dfn{apc} stands for any of the address
2991 registers (@samp{a0} through @samp{a7}), nothing, (@samp{}), the
2992 Program Counter (@samp{pc}), or the zero-address relative to the
2993 program counter (@samp{zpc}).
2994
2995 The following addressing modes are understood:
2996 @table @dfn
2997 @item Immediate
2998 @samp{#@var{digits}}
2999
3000 @item Data Register
3001 @samp{d0} through @samp{d7}
3002
3003 @item Address Register
3004 @samp{a0} through @samp{a7}
3005
3006 @item Address Register Indirect
3007 @samp{a0@@} through @samp{a7@@}
3008
3009 @item Address Register Postincrement
3010 @samp{a0@@+} through @samp{a7@@+}
3011
3012 @item Address Register Predecrement
3013 @samp{a0@@-} through @samp{a7@@-}
3014
3015 @item Indirect Plus Offset
3016 @samp{@var{apc}@@(@var{digits})}
3017
3018 @item Index
3019 @samp{@var{apc}@@(@var{digits},@var{register}:@var{size}:@var{scale})}
3020
3021 or @samp{@var{apc}@@(@var{register}:@var{size}:@var{scale})}
3022
3023 @item Postindex
3024 @samp{@var{apc}@@(@var{digits})@@(@var{digits},@var{register}:@var{size}:@var{scale})}
3025
3026 or @samp{@var{apc}@@(@var{digits})@@(@var{register}:@var{size}:@var{scale})}
3027
3028 @item Preindex
3029 @samp{@var{apc}@@(@var{digits},@var{register}:@var{size}:@var{scale})@@(@var{digits})}
3030
3031 or @samp{@var{apc}@@(@var{register}:@var{size}:@var{scale})@@(@var{digits})}
3032
3033 @item Memory Indirect
3034 @samp{@var{apc}@@(@var{digits})@@(@var{digits})}
3035
3036 @item Absolute
3037 @samp{@var{symbol}}, or @samp{@var{digits}}
3038 @ignore
3039 @c pesch@cygnus.com: gnu, rich concur the following needs careful
3040 @c research before documenting.
3041 , or either of the above followed
3042 by @samp{:b}, @samp{:w}, or @samp{:l}.
3043 @end ignore
3044 @end table
3045
3046 _CHAPSEC__(1+_GENERIC__) Floating Point
3047 The floating point code is not too well tested, and may have
3048 subtle bugs in it.
3049
3050 Packed decimal (P) format floating literals are not supported.
3051 Feel free to add the code!
3052
3053 The floating point formats generated by directives are these.
3054 @table @code
3055 @item .float
3056 @code{Single} precision floating point constants.
3057 @item .double
3058 @code{Double} precision floating point constants.
3059 @end table
3060
3061 There is no directive to produce regions of memory holding
3062 extended precision numbers, however they can be used as
3063 immediate operands to floating-point instructions. Adding a
3064 directive to create extended precision numbers would not be
3065 hard, but it has not yet seemed necessary.
3066
3067 _CHAPSEC__(1+_GENERIC__) 680x0 Machine Directives
3068 In order to be compatible with the Sun assembler the 680x0 assembler
3069 understands the following directives.
3070 @table @code
3071 @item .data1
3072 This directive is identical to a @code{.data 1} directive.
3073 @item .data2
3074 This directive is identical to a @code{.data 2} directive.
3075 @item .even
3076 This directive is identical to a @code{.align 1} directive.
3077 @c Is this true? does it work???
3078 @item .skip
3079 This directive is identical to a @code{.space} directive.
3080 @end table
3081
3082 _CHAPSEC__(1+_GENERIC__) Opcodes
3083 @c pesch@cygnus.com: I don't see any point in the following
3084 @c paragraph. Bugs are bugs; how does saying this
3085 @c help anyone?
3086 @ignore
3087 Danger: Several bugs have been found in the opcode table (and
3088 fixed). More bugs may exist. Be careful when using obscure
3089 instructions.
3090 @end ignore
3091
3092 _CHAPSEC__(2+_GENERIC__) Branch Improvement
3093
3094 Certain pseudo opcodes are permitted for branch instructions.
3095 They expand to the shortest branch instruction that will reach the
3096 target. Generally these mnemonics are made by substituting @samp{j} for
3097 @samp{b} at the start of a Motorola mnemonic.
3098
3099 The following table summarizes the pseudo-operations. A @code{*} flags
3100 cases that are more fully described after the table:
3101
3102 @smallexample
3103 Displacement
3104 +---------------------------------------------------------
3105 | 68020 68000/10
3106 Pseudo-Op |BYTE WORD LONG LONG non-PC relative
3107 +---------------------------------------------------------
3108 jbsr |bsrs bsr bsrl jsr jsr
3109 jra |bras bra bral jmp jmp
3110 * jXX |bXXs bXX bXXl bNXs;jmpl bNXs;jmp
3111 * dbXX |dbXX dbXX dbXX; bra; jmpl
3112 * fjXX |fbXXw fbXXw fbXXl fbNXw;jmp
3113
3114 XX: condition
3115 NX: negative of condition XX
3116
3117 @end smallexample
3118 @center{@code{*}---see full description below}
3119
3120 @table @code
3121 @item jbsr
3122 @itemx jra
3123 These are the simplest jump pseudo-operations; they always map to one
3124 particular machine instruction, depending on the displacement to the
3125 branch target.
3126
3127 @item j@var{XX}
3128 Here, @samp{j@var{XX}} stands for an entire family of pseudo-operations,
3129 where @var{XX} is a conditional branch or condition-code test. The full
3130 list of pseudo-ops in this family is:
3131 @smallexample
3132 jhi jls jcc jcs jne jeq jvc
3133 jvs jpl jmi jge jlt jgt jle
3134 @end smallexample
3135
3136 For the cases of non-PC relative displacements and long displacements on
3137 the 68000 or 68010, @code{_AS__} will issue a longer code fragment in terms of
3138 @var{NX}, the opposite condition to @var{XX}:
3139 @smallexample
3140 j@var{XX} foo
3141 @end smallexample
3142 gives
3143 @smallexample
3144 b@var{NX}s oof
3145 jmp foo
3146 oof:
3147 @end smallexample
3148
3149 @item db@var{XX}
3150 The full family of pseudo-operations covered here is
3151 @smallexample
3152 dbhi dbls dbcc dbcs dbne dbeq dbvc
3153 dbvs dbpl dbmi dbge dblt dbgt dble
3154 dbf dbra dbt
3155 @end smallexample
3156
3157 Other than for word and byte displacements, when the source reads
3158 @samp{db@var{XX} foo}, @code{_AS__} will emit
3159 @smallexample
3160 db@var{XX} oo1
3161 bra oo2
3162 oo1:jmpl foo
3163 oo2:
3164 @end smallexample
3165
3166 @item fj@var{XX}
3167 This family includes
3168 @smallexample
3169 fjne fjeq fjge fjlt fjgt fjle fjf
3170 fjt fjgl fjgle fjnge fjngl fjngle fjngt
3171 fjnle fjnlt fjoge fjogl fjogt fjole fjolt
3172 fjor fjseq fjsf fjsne fjst fjueq fjuge
3173 fjugt fjule fjult fjun
3174 @end smallexample
3175
3176 For branch targets that are not PC relative, @code{_AS__} emits
3177 @smallexample
3178 fb@var{NX} oof
3179 jmp foo
3180 oof:
3181 @end smallexample
3182 when it encounters @samp{fj@var{XX} foo}.
3183
3184 @end table
3185
3186 _CHAPSEC__(2+_GENERIC__) Special Characters
3187 The immediate character is @samp{#} for Sun compatibility. The
3188 line-comment character is @samp{|}. If a @samp{#} appears at the
3189 beginning of a line, it is treated as a comment unless it looks like
3190 @samp{# line file}, in which case it is treated normally.
3191
3192 _fi__(_M680X0__)
3193 @c pesch@cygnus.com: conditionalize on something other than 0 when filled in.
3194 _if__(0)
3195 @section 32x32
3196 @section Options
3197 The 32x32 version of @code{_AS__} accepts a @kbd{-m32032} option to
3198 specify thiat it is compiling for a 32032 processor, or a
3199 @kbd{-m32532} to specify that it is compiling for a 32532 option.
3200 The default (if neither is specified) is chosen when the assembler
3201 is compiled.
3202
3203 @subsection Syntax
3204 I don't know anything about the 32x32 syntax assembled by
3205 @code{_AS__}. Someone who undersands the processor (I've never seen
3206 one) and the possible syntaxes should write this section.
3207
3208 @subsection Floating Point
3209 The 32x32 uses IEEE floating point numbers, but @code{_AS__} will only
3210 create single or double precision values. I don't know if the 32x32
3211 understands extended precision numbers.
3212
3213 @subsection 32x32 Machine Directives
3214 The 32x32 has no machine dependent directives.
3215
3216 _fi__(0)
3217 _if__(_SPARC__)
3218 @group
3219 _CHAPSEC__(0+_GENERIC__) SPARC Dependent Features
3220 @subsection Options
3221 The sparc has no machine dependent options.
3222 @end group
3223
3224 @ignore
3225 @c FIXME: (sparc) Fill in "syntax" section!
3226 @subsection syntax
3227 I don't know anything about Sparc syntax. Someone who does
3228 will have to write this section.
3229 @end ignore
3230
3231 @subsection Floating Point
3232 The Sparc uses ieee floating-point numbers.
3233
3234 @subsection Sparc Machine Directives
3235 The Sparc version of @code{_AS__} supports the following additional
3236 machine directives:
3237
3238 @table @code
3239 @item .common
3240 This must be followed by a symbol name, a positive number, and
3241 @code{"bss"}. This behaves somewhat like @code{.comm}, but the
3242 syntax is different.
3243
3244 @item .global
3245 This is functionally identical to @code{.globl}.
3246
3247 @item .half
3248 This is functionally identical to @code{.short}.
3249
3250 @item .proc
3251 This directive is ignored. Any text following it on the same
3252 line is also ignored.
3253
3254 @item .reserve
3255 This must be followed by a symbol name, a positive number, and
3256 @code{"bss"}. This behaves somewhat like @code{.lcomm}, but the
3257 syntax is different.
3258
3259 @item .seg
3260 This must be followed by @code{"text"}, @code{"data"}, or
3261 @code{"data1"}. It behaves like @code{.text}, @code{.data}, or
3262 @code{.data 1}.
3263
3264 @item .skip
3265 This is functionally identical to the .space directive.
3266
3267 @item .word
3268 On the Sparc, the .word directive produces 32 bit values,
3269 instead of the 16 bit values it produces on every other machine.
3270
3271 @end table
3272
3273 _fi__(_SPARC__)
3274 _if__(_I80386__)
3275 _CHAPSEC__(0+_GENERIC__) 80386 Dependent Features
3276 _CHAPSEC__(1+_GENERIC__) Options
3277 The 80386 has no machine dependent options.
3278
3279 _CHAPSEC__(1+_GENERIC__) AT&T Syntax versus Intel Syntax
3280 In order to maintain compatibility with the output of @code{_GCC__},
3281 @code{_AS__} supports AT&T System V/386 assembler syntax. This is quite
3282 different from Intel syntax. We mention these differences because
3283 almost all 80386 documents used only Intel syntax. Notable differences
3284 between the two syntaxes are:
3285 @itemize @bullet
3286 @item
3287 AT&T immediate operands are preceded by @samp{$}; Intel immediate
3288 operands are undelimited (Intel @samp{push 4} is AT&T @samp{pushl $4}).
3289 AT&T register operands are preceded by @samp{%}; Intel register operands
3290 are undelimited. AT&T absolute (as opposed to PC relative) jump/call
3291 operands are prefixed by @samp{*}; they are undelimited in Intel syntax.
3292
3293 @item
3294 AT&T and Intel syntax use the opposite order for source and destination
3295 operands. Intel @samp{add eax, 4} is @samp{addl $4, %eax}. The
3296 @samp{source, dest} convention is maintained for compatibility with
3297 previous Unix assemblers.
3298
3299 @item
3300 In AT&T syntax the size of memory operands is determined from the last
3301 character of the opcode name. Opcode suffixes of @samp{b}, @samp{w},
3302 and @samp{l} specify byte (8-bit), word (16-bit), and long (32-bit)
3303 memory references. Intel syntax accomplishes this by prefixes memory
3304 operands (@emph{not} the opcodes themselves) with @samp{byte ptr},
3305 @samp{word ptr}, and @samp{dword ptr}. Thus, Intel @samp{mov al, byte
3306 ptr @var{foo}} is @samp{movb @var{foo}, %al} in AT&T syntax.
3307
3308 @item
3309 Immediate form long jumps and calls are
3310 @samp{lcall/ljmp $@var{segment}, $@var{offset}} in AT&T syntax; the
3311 Intel syntax is
3312 @samp{call/jmp far @var{segment}:@var{offset}}. Also, the far return
3313 instruction
3314 is @samp{lret $@var{stack-adjust}} in AT&T syntax; Intel syntax is
3315 @samp{ret far @var{stack-adjust}}.
3316
3317 @item
3318 The AT&T assembler does not provide support for multiple segment
3319 programs. Unix style systems expect all programs to be single segments.
3320 @end itemize
3321
3322 _CHAPSEC__(1+_GENERIC__) Opcode Naming
3323 Opcode names are suffixed with one character modifiers which specify the
3324 size of operands. The letters @samp{b}, @samp{w}, and @samp{l} specify
3325 byte, word, and long operands. If no suffix is specified by an
3326 instruction and it contains no memory operands then @code{_AS__} tries to
3327 fill in the missing suffix based on the destination register operand
3328 (the last one by convention). Thus, @samp{mov %ax, %bx} is equivalent
3329 to @samp{movw %ax, %bx}; also, @samp{mov $1, %bx} is equivalent to
3330 @samp{movw $1, %bx}. Note that this is incompatible with the AT&T Unix
3331 assembler which assumes that a missing opcode suffix implies long
3332 operand size. (This incompatibility does not affect compiler output
3333 since compilers always explicitly specify the opcode suffix.)
3334
3335 Almost all opcodes have the same names in AT&T and Intel format. There
3336 are a few exceptions. The sign extend and zero extend instructions need
3337 two sizes to specify them. They need a size to sign/zero extend
3338 @emph{from} and a size to zero extend @emph{to}. This is accomplished
3339 by using two opcode suffixes in AT&T syntax. Base names for sign extend
3340 and zero extend are @samp{movs@dots{}} and @samp{movz@dots{}} in AT&T
3341 syntax (@samp{movsx} and @samp{movzx} in Intel syntax). The opcode
3342 suffixes are tacked on to this base name, the @emph{from} suffix before
3343 the @emph{to} suffix. Thus, @samp{movsbl %al, %edx} is AT&T syntax for
3344 ``move sign extend @emph{from} %al @emph{to} %edx.'' Possible suffixes,
3345 thus, are @samp{bl} (from byte to long), @samp{bw} (from byte to word),
3346 and @samp{wl} (from word to long).
3347
3348 The Intel syntax conversion instructions
3349 @itemize @bullet
3350 @item
3351 @samp{cbw} --- sign-extend byte in @samp{%al} to word in @samp{%ax},
3352 @item
3353 @samp{cwde} --- sign-extend word in @samp{%ax} to long in @samp{%eax},
3354 @item
3355 @samp{cwd} --- sign-extend word in @samp{%ax} to long in @samp{%dx:%ax},
3356 @item
3357 @samp{cdq} --- sign-extend dword in @samp{%eax} to quad in @samp{%edx:%eax},
3358 @end itemize
3359 are called @samp{cbtw}, @samp{cwtl}, @samp{cwtd}, and @samp{cltd} in
3360 AT&T naming. @code{_AS__} accepts either naming for these instructions.
3361
3362 Far call/jump instructions are @samp{lcall} and @samp{ljmp} in
3363 AT&T syntax, but are @samp{call far} and @samp{jump far} in Intel
3364 convention.
3365
3366 _CHAPSEC__(1+_GENERIC__) Register Naming
3367 Register operands are always prefixes with @samp{%}. The 80386 registers
3368 consist of
3369 @itemize @bullet
3370 @item
3371 the 8 32-bit registers @samp{%eax} (the accumulator), @samp{%ebx},
3372 @samp{%ecx}, @samp{%edx}, @samp{%edi}, @samp{%esi}, @samp{%ebp} (the
3373 frame pointer), and @samp{%esp} (the stack pointer).
3374
3375 @item
3376 the 8 16-bit low-ends of these: @samp{%ax}, @samp{%bx}, @samp{%cx},
3377 @samp{%dx}, @samp{%di}, @samp{%si}, @samp{%bp}, and @samp{%sp}.
3378
3379 @item
3380 the 8 8-bit registers: @samp{%ah}, @samp{%al}, @samp{%bh},
3381 @samp{%bl}, @samp{%ch}, @samp{%cl}, @samp{%dh}, and @samp{%dl} (These
3382 are the high-bytes and low-bytes of @samp{%ax}, @samp{%bx},
3383 @samp{%cx}, and @samp{%dx})
3384
3385 @item
3386 the 6 segment registers @samp{%cs} (code segment), @samp{%ds}
3387 (data segment), @samp{%ss} (stack segment), @samp{%es}, @samp{%fs},
3388 and @samp{%gs}.
3389
3390 @item
3391 the 3 processor control registers @samp{%cr0}, @samp{%cr2}, and
3392 @samp{%cr3}.
3393
3394 @item
3395 the 6 debug registers @samp{%db0}, @samp{%db1}, @samp{%db2},
3396 @samp{%db3}, @samp{%db6}, and @samp{%db7}.
3397
3398 @item
3399 the 2 test registers @samp{%tr6} and @samp{%tr7}.
3400
3401 @item
3402 the 8 floating point register stack @samp{%st} or equivalently
3403 @samp{%st(0)}, @samp{%st(1)}, @samp{%st(2)}, @samp{%st(3)},
3404 @samp{%st(4)}, @samp{%st(5)}, @samp{%st(6)}, and @samp{%st(7)}.
3405 @end itemize
3406
3407 _CHAPSEC__(1+_GENERIC__) Opcode Prefixes
3408 Opcode prefixes are used to modify the following opcode. They are used
3409 to repeat string instructions, to provide segment overrides, to perform
3410 bus lock operations, and to give operand and address size (16-bit
3411 operands are specified in an instruction by prefixing what would
3412 normally be 32-bit operands with a ``operand size'' opcode prefix).
3413 Opcode prefixes are usually given as single-line instructions with no
3414 operands, and must directly precede the instruction they act upon. For
3415 example, the @samp{scas} (scan string) instruction is repeated with:
3416 @smallexample
3417 repne
3418 scas
3419 @end smallexample
3420
3421 Here is a list of opcode prefixes:
3422 @itemize @bullet
3423 @item
3424 Segment override prefixes @samp{cs}, @samp{ds}, @samp{ss}, @samp{es},
3425 @samp{fs}, @samp{gs}. These are automatically added by specifying
3426 using the @var{segment}:@var{memory-operand} form for memory references.
3427
3428 @item
3429 Operand/Address size prefixes @samp{data16} and @samp{addr16}
3430 change 32-bit operands/addresses into 16-bit operands/addresses. Note
3431 that 16-bit addressing modes (i.e. 8086 and 80286 addressing modes)
3432 are not supported (yet).
3433
3434 @item
3435 The bus lock prefix @samp{lock} inhibits interrupts during
3436 execution of the instruction it precedes. (This is only valid with
3437 certain instructions; see a 80386 manual for details).
3438
3439 @item
3440 The wait for coprocessor prefix @samp{wait} waits for the
3441 coprocessor to complete the current instruction. This should never be
3442 needed for the 80386/80387 combination.
3443
3444 @item
3445 The @samp{rep}, @samp{repe}, and @samp{repne} prefixes are added
3446 to string instructions to make them repeat @samp{%ecx} times.
3447 @end itemize
3448
3449 _CHAPSEC__(1+_GENERIC__) Memory References
3450 An Intel syntax indirect memory reference of the form
3451 @smallexample
3452 @var{segment}:[@var{base} + @var{index}*@var{scale} + @var{disp}]
3453 @end smallexample
3454 is translated into the AT&T syntax
3455 @smallexample
3456 @var{segment}:@var{disp}(@var{base}, @var{index}, @var{scale})
3457 @end smallexample
3458 where @var{base} and @var{index} are the optional 32-bit base and
3459 index registers, @var{disp} is the optional displacement, and
3460 @var{scale}, taking the values 1, 2, 4, and 8, multiplies @var{index}
3461 to calculate the address of the operand. If no @var{scale} is
3462 specified, @var{scale} is taken to be 1. @var{segment} specifies the
3463 optional segment register for the memory operand, and may override the
3464 default segment register (see a 80386 manual for segment register
3465 defaults). Note that segment overrides in AT&T syntax @emph{must} have
3466 be preceded by a @samp{%}. If you specify a segment override which
3467 coincides with the default segment register, @code{_AS__} will @emph{not}
3468 output any segment register override prefixes to assemble the given
3469 instruction. Thus, segment overrides can be specified to emphasize which
3470 segment register is used for a given memory operand.
3471
3472 Here are some examples of Intel and AT&T style memory references:
3473 @table @asis
3474
3475 @item AT&T: @samp{-4(%ebp)}, Intel: @samp{[ebp - 4]}
3476 @var{base} is @samp{%ebp}; @var{disp} is @samp{-4}. @var{segment} is
3477 missing, and the default segment is used (@samp{%ss} for addressing with
3478 @samp{%ebp} as the base register). @var{index}, @var{scale} are both missing.
3479
3480 @item AT&T: @samp{foo(,%eax,4)}, Intel: @samp{[foo + eax*4]}
3481 @var{index} is @samp{%eax} (scaled by a @var{scale} 4); @var{disp} is
3482 @samp{foo}. All other fields are missing. The segment register here
3483 defaults to @samp{%ds}.
3484
3485 @item AT&T: @samp{foo(,1)}; Intel @samp{[foo]}
3486 This uses the value pointed to by @samp{foo} as a memory operand.
3487 Note that @var{base} and @var{index} are both missing, but there is only
3488 @emph{one} @samp{,}. This is a syntactic exception.
3489
3490 @item AT&T: @samp{%gs:foo}; Intel @samp{gs:foo}
3491 This selects the contents of the variable @samp{foo} with segment
3492 register @var{segment} being @samp{%gs}.
3493
3494 @end table
3495
3496 Absolute (as opposed to PC relative) call and jump operands must be
3497 prefixed with @samp{*}. If no @samp{*} is specified, @code{_AS__} will
3498 always choose PC relative addressing for jump/call labels.
3499
3500 Any instruction that has a memory operand @emph{must} specify its size (byte,
3501 word, or long) with an opcode suffix (@samp{b}, @samp{w}, or @samp{l},
3502 respectively).
3503
3504 _CHAPSEC__(1+_GENERIC__) Handling of Jump Instructions
3505 Jump instructions are always optimized to use the smallest possible
3506 displacements. This is accomplished by using byte (8-bit) displacement
3507 jumps whenever the target is sufficiently close. If a byte displacement
3508 is insufficient a long (32-bit) displacement is used. We do not support
3509 word (16-bit) displacement jumps (i.e. prefixing the jump instruction
3510 with the @samp{addr16} opcode prefix), since the 80386 insists upon masking
3511 @samp{%eip} to 16 bits after the word displacement is added.
3512
3513 Note that the @samp{jcxz}, @samp{jecxz}, @samp{loop}, @samp{loopz},
3514 @samp{loope}, @samp{loopnz} and @samp{loopne} instructions only come in
3515 byte displacements, so that it is possible that use of these
3516 instructions (@code{_GCC__} does not use them) will cause the assembler to
3517 print an error message (and generate incorrect code). The AT&T 80386
3518 assembler tries to get around this problem by expanding @samp{jcxz foo} to
3519 @smallexample
3520 jcxz cx_zero
3521 jmp cx_nonzero
3522 cx_zero: jmp foo
3523 cx_nonzero:
3524 @end smallexample
3525
3526 _CHAPSEC__(1+_GENERIC__) Floating Point
3527 All 80387 floating point types except packed BCD are supported.
3528 (BCD support may be added without much difficulty). These data
3529 types are 16-, 32-, and 64- bit integers, and single (32-bit),
3530 double (64-bit), and extended (80-bit) precision floating point.
3531 Each supported type has an opcode suffix and a constructor
3532 associated with it. Opcode suffixes specify operand's data
3533 types. Constructors build these data types into memory.
3534
3535 @itemize @bullet
3536 @item
3537 Floating point constructors are @samp{.float} or @samp{.single},
3538 @samp{.double}, and @samp{.tfloat} for 32-, 64-, and 80-bit formats.
3539 These correspond to opcode suffixes @samp{s}, @samp{l}, and @samp{t}.
3540 @samp{t} stands for temporary real, and that the 80387 only supports
3541 this format via the @samp{fldt} (load temporary real to stack top) and
3542 @samp{fstpt} (store temporary real and pop stack) instructions.
3543
3544 @item
3545 Integer constructors are @samp{.word}, @samp{.long} or @samp{.int}, and
3546 @samp{.quad} for the 16-, 32-, and 64-bit integer formats. The corresponding
3547 opcode suffixes are @samp{s} (single), @samp{l} (long), and @samp{q}
3548 (quad). As with the temporary real format the 64-bit @samp{q} format is
3549 only present in the @samp{fildq} (load quad integer to stack top) and
3550 @samp{fistpq} (store quad integer and pop stack) instructions.
3551 @end itemize
3552
3553 Register to register operations do not require opcode suffixes,
3554 so that @samp{fst %st, %st(1)} is equivalent to @samp{fstl %st, %st(1)}.
3555
3556 Since the 80387 automatically synchronizes with the 80386 @samp{fwait}
3557 instructions are almost never needed (this is not the case for the
3558 80286/80287 and 8086/8087 combinations). Therefore, @code{_AS__} suppresses
3559 the @samp{fwait} instruction whenever it is implicitly selected by one
3560 of the @samp{fn@dots{}} instructions. For example, @samp{fsave} and
3561 @samp{fnsave} are treated identically. In general, all the @samp{fn@dots{}}
3562 instructions are made equivalent to @samp{f@dots{}} instructions. If
3563 @samp{fwait} is desired it must be explicitly coded.
3564
3565 _CHAPSEC__(1+_GENERIC__) Notes
3566 There is some trickery concerning the @samp{mul} and @samp{imul}
3567 instructions that deserves mention. The 16-, 32-, and 64-bit expanding
3568 multiplies (base opcode @samp{0xf6}; extension 4 for @samp{mul} and 5
3569 for @samp{imul}) can be output only in the one operand form. Thus,
3570 @samp{imul %ebx, %eax} does @emph{not} select the expanding multiply;
3571 the expanding multiply would clobber the @samp{%edx} register, and this
3572 would confuse @code{_GCC__} output. Use @samp{imul %ebx} to get the
3573 64-bit product in @samp{%edx:%eax}.
3574
3575 We have added a two operand form of @samp{imul} when the first operand
3576 is an immediate mode expression and the second operand is a register.
3577 This is just a shorthand, so that, multiplying @samp{%eax} by 69, for
3578 example, can be done with @samp{imul $69, %eax} rather than @samp{imul
3579 $69, %eax, %eax}.
3580
3581 _fi__(_I80386__)
3582 _if__(0)
3583 @c pesch@cygnus.com: we ignore the following chapters, since internals are
3584 @c changing rapidly. These may need to be moved to another
3585 @c book anyhow, if we adopt the model of user/modifier
3586 @c books.
3587 @node Maintenance, Retargeting, _MACH_DEP__, Top
3588 @chapter Maintaining the Assembler
3589 [[this chapter is still being built]]
3590
3591 @section Design
3592 We had these goals, in descending priority:
3593 @table @b
3594 @item Accuracy.
3595 For every program composed by a compiler, @code{_AS__} should emit
3596 ``correct'' code. This leaves some latitude in choosing addressing
3597 modes, order of @code{relocation_info} structures in the object
3598 file, @emph{etc}.
3599
3600 @item Speed, for usual case.
3601 By far the most common use of @code{_AS__} will be assembling compiler
3602 emissions.
3603
3604 @item Upward compatibility for existing assembler code.
3605 Well @dots{} we don't support Vax bit fields but everything else
3606 seems to be upward compatible.
3607
3608 @item Readability.
3609 The code should be maintainable with few surprises. (JF: ha!)
3610
3611 @end table
3612
3613 We assumed that disk I/O was slow and expensive while memory was
3614 fast and access to memory was cheap. We expect the in-memory data
3615 structures to be less than 10 times the size of the emitted object
3616 file. (Contrast this with the C compiler where in-memory structures
3617 might be 100 times object file size!)
3618 This suggests:
3619 @itemize @bullet
3620 @item
3621 Try to read the source file from disk only one time. For other
3622 reasons, we keep large chunks of the source file in memory during
3623 assembly so this is not a problem. Also the assembly algorithm
3624 should only scan the source text once if the compiler composed the
3625 text according to a few simple rules.
3626 @item
3627 Emit the object code bytes only once. Don't store values and then
3628 backpatch later.
3629 @item
3630 Build the object file in memory and do direct writes to disk of
3631 large buffers.
3632 @end itemize
3633
3634 RMS suggested a one-pass algorithm which seems to work well. By not
3635 parsing text during a second pass considerable time is saved on
3636 large programs (@emph{e.g.} the sort of C program @code{yacc} would
3637 emit).
3638
3639 It happened that the data structures needed to emit relocation
3640 information to the object file were neatly subsumed into the data
3641 structures that do backpatching of addresses after pass 1.
3642
3643 Many of the functions began life as re-usable modules, loosely
3644 connected. RMS changed this to gain speed. For example, input
3645 parsing routines which used to work on pre-sanitized strings now
3646 must parse raw data. Hence they have to import knowledge of the
3647 assemblers' comment conventions @emph{etc}.
3648
3649 @section Deprecated Feature(?)s
3650 We have stopped supporting some features:
3651 @itemize @bullet
3652 @item
3653 @code{.org} statements must have @b{defined} expressions.
3654 @item
3655 Vax Bit fields (@kbd{:} operator) are entirely unsupported.
3656 @end itemize
3657
3658 It might be a good idea to not support these features in a future release:
3659 @itemize @bullet
3660 @item
3661 @kbd{#} should begin a comment, even in column 1.
3662 @item
3663 Why support the logical line & file concept any more?
3664 @item
3665 Subsegments are a good candidate for flushing.
3666 Depends on which compilers need them I guess.
3667 @end itemize
3668
3669 @section Bugs, Ideas, Further Work
3670 Clearly the major improvement is DON'T USE A TEXT-READING
3671 ASSEMBLER for the back end of a compiler. It is much faster to
3672 interpret binary gobbledygook from a compiler's tables than to
3673 ask the compiler to write out human-readable code just so the
3674 assembler can parse it back to binary.
3675
3676 Assuming you use @code{_AS__} for human written programs: here are
3677 some ideas:
3678 @itemize @bullet
3679 @item
3680 Document (here) @code{APP}.
3681 @item
3682 Take advantage of knowing no spaces except after opcode
3683 to speed up @code{_AS__}. (Modify @code{app.c} to flush useless spaces:
3684 only keep space/tabs at begin of line or between 2
3685 symbols.)
3686 @item
3687 Put pointers in this documentation to @file{a.out} documentation.
3688 @item
3689 Split the assembler into parts so it can gobble direct binary
3690 from @emph{e.g.} @code{cc}. It is silly for@code{cc} to compose text
3691 just so @code{_AS__} can parse it back to binary.
3692 @item
3693 Rewrite hash functions: I want a more modular, faster library.
3694 @item
3695 Clean up LOTS of code.
3696 @item
3697 Include all the non-@file{.c} files in the maintenance chapter.
3698 @item
3699 Document flonums.
3700 @item
3701 Implement flonum short literals.
3702 @item
3703 Change all talk of expression operands to expression quantities,
3704 or perhaps to expression arguments.
3705 @item
3706 Implement pass 2.
3707 @item
3708 Whenever a @code{.text} or @code{.data} statement is seen, we close
3709 of the current frag with an imaginary @code{.fill 0}. This is
3710 because we only have one obstack for frags, and we can't grow new
3711 frags for a new subsegment, then go back to the old subsegment and
3712 append bytes to the old frag. All this nonsense goes away if we
3713 give each subsegment its own obstack. It makes code simpler in
3714 about 10 places, but nobody has bothered to do it because C compiler
3715 output rarely changes subsegments (compared to ending frags with
3716 relaxable addresses, which is common).
3717 @end itemize
3718
3719 @section Sources
3720 @c The following files in the @file{_AS__} directory
3721 @c are symbolic links to other files, of
3722 @c the same name, in a different directory.
3723 @c @itemize @bullet
3724 @c @item
3725 @c @file{atof_generic.c}
3726 @c @item
3727 @c @file{atof_vax.c}
3728 @c @item
3729 @c @file{flonum_const.c}
3730 @c @item
3731 @c @file{flonum_copy.c}
3732 @c @item
3733 @c @file{flonum_get.c}
3734 @c @item
3735 @c @file{flonum_multip.c}
3736 @c @item
3737 @c @file{flonum_normal.c}
3738 @c @item
3739 @c @file{flonum_print.c}
3740 @c @end itemize
3741
3742 Here is a list of the source files in the @file{_AS__} directory.
3743
3744 @table @file
3745 @item app.c
3746 This contains the pre-processing phase, which deletes comments,
3747 handles whitespace, etc. This was recently re-written, since app
3748 used to be a separate program, but RMS wanted it to be inline.
3749
3750 @item append.c
3751 This is a subroutine to append a string to another string returning a
3752 pointer just after the last @code{char} appended. (JF: All these
3753 little routines should probably all be put in one file.)
3754
3755 @item as.c
3756 Here you will find the main program of the assembler @code{_AS__}.
3757
3758 @item expr.c
3759 This is a branch office of @file{read.c}. This understands
3760 expressions, arguments. Inside @code{_AS__}, arguments are called
3761 (expression) @emph{operands}. This is confusing, because we also talk
3762 (elsewhere) about instruction @emph{operands}. Also, expression
3763 operands are called @emph{quantities} explicitly to avoid confusion
3764 with instruction operands. What a mess.
3765
3766 @item frags.c
3767 This implements the @b{frag} concept. Without frags, finding the
3768 right size for branch instructions would be a lot harder.
3769
3770 @item hash.c
3771 This contains the symbol table, opcode table @emph{etc.} hashing
3772 functions.
3773
3774 @item hex_value.c
3775 This is a table of values of digits, for use in atoi() type
3776 functions. Could probably be flushed by using calls to strtol(), or
3777 something similar.
3778
3779 @item input-file.c
3780 This contains Operating system dependent source file reading
3781 routines. Since error messages often say where we are in reading
3782 the source file, they live here too. Since @code{_AS__} is intended to
3783 run under GNU and Unix only, this might be worth flushing. Anyway,
3784 almost all C compilers support stdio.
3785
3786 @item input-scrub.c
3787 This deals with calling the pre-processor (if needed) and feeding the
3788 chunks back to the rest of the assembler the right way.
3789
3790 @item messages.c
3791 This contains operating system independent parts of fatal and
3792 warning message reporting. See @file{append.c} above.
3793
3794 @item output-file.c
3795 This contains operating system dependent functions that write an
3796 object file for @code{_AS__}. See @file{input-file.c} above.
3797
3798 @item read.c
3799 This implements all the directives of @code{_AS__}. This also deals
3800 with passing input lines to the machine dependent part of the
3801 assembler.
3802
3803 @item strstr.c
3804 This is a C library function that isn't in most C libraries yet.
3805 See @file{append.c} above.
3806
3807 @item subsegs.c
3808 This implements subsegments.
3809
3810 @item symbols.c
3811 This implements symbols.
3812
3813 @item write.c
3814 This contains the code to perform relaxation, and to write out
3815 the object file. It is mostly operating system independent, but
3816 different OSes have different object file formats in any case.
3817
3818 @item xmalloc.c
3819 This implements @code{malloc()} or bust. See @file{append.c} above.
3820
3821 @item xrealloc.c
3822 This implements @code{realloc()} or bust. See @file{append.c} above.
3823
3824 @item atof-generic.c
3825 The following files were taken from a machine-independent subroutine
3826 library for manipulating floating point numbers and very large
3827 integers.
3828
3829 @file{atof-generic.c} turns a string into a flonum internal format
3830 floating-point number.
3831
3832 @item flonum-const.c
3833 This contains some potentially useful floating point numbers in
3834 flonum format.
3835
3836 @item flonum-copy.c
3837 This copies a flonum.
3838
3839 @item flonum-multip.c
3840 This multiplies two flonums together.
3841
3842 @item bignum-copy.c
3843 This copies a bignum.
3844
3845 @end table
3846
3847 Here is a table of all the machine-specific files (this includes
3848 both source and header files). Typically, there is a
3849 @var{machine}.c file, a @var{machine}-opcode.h file, and an
3850 atof-@var{machine}.c file. The @var{machine}-opcode.h file should
3851 be identical to the one used by GDB (which uses it for disassembly.)
3852
3853 @table @file
3854
3855 @item atof-ieee.c
3856 This contains code to turn a flonum into a ieee literal constant.
3857 This is used by tye 680x0, 32x32, sparc, and i386 versions of @code{_AS__}.
3858
3859 @item i386-opcode.h
3860 This is the opcode-table for the i386 version of the assembler.
3861
3862 @item i386.c
3863 This contains all the code for the i386 version of the assembler.
3864
3865 @item i386.h
3866 This defines constants and macros used by the i386 version of the assembler.
3867
3868 @item m-generic.h
3869 generic 68020 header file. To be linked to m68k.h on a
3870 non-sun3, non-hpux system.
3871
3872 @item m-sun2.h
3873 68010 header file for Sun2 workstations. Not well tested. To be linked
3874 to m68k.h on a sun2. (See also @samp{-DSUN_ASM_SYNTAX} in the
3875 @file{Makefile}.)
3876
3877 @item m-sun3.h
3878 68020 header file for Sun3 workstations. To be linked to m68k.h before
3879 compiling on a Sun3 system. (See also @samp{-DSUN_ASM_SYNTAX} in the
3880 @file{Makefile}.)
3881
3882 @item m-hpux.h
3883 68020 header file for a HPUX (system 5?) box. Which box, which
3884 version of HPUX, etc? I don't know.
3885
3886 @item m68k.h
3887 A hard- or symbolic- link to one of @file{m-generic.h},
3888 @file{m-hpux.h} or @file{m-sun3.h} depending on which kind of
3889 680x0 you are assembling for. (See also @samp{-DSUN_ASM_SYNTAX} in the
3890 @file{Makefile}.)
3891
3892 @item m68k-opcode.h
3893 Opcode table for 68020. This is now a link to the opcode table
3894 in the @code{GDB} source directory.
3895
3896 @item m68k.c
3897 All the mc680x0 code, in one huge, slow-to-compile file.
3898
3899 @item ns32k.c
3900 This contains the code for the ns32032/ns32532 version of the
3901 assembler.
3902
3903 @item ns32k-opcode.h
3904 This contains the opcode table for the ns32032/ns32532 version
3905 of the assembler.
3906
3907 @item vax-inst.h
3908 Vax specific file for describing Vax operands and other Vax-ish things.
3909
3910 @item vax-opcode.h
3911 Vax opcode table.
3912
3913 @item vax.c
3914 Vax specific parts of @code{_AS__}. Also includes the former files
3915 @file{vax-ins-parse.c}, @file{vax-reg-parse.c} and @file{vip-op.c}.
3916
3917 @item atof-vax.c
3918 Turns a flonum into a Vax constant.
3919
3920 @item vms.c
3921 This file contains the special code needed to put out a VMS
3922 style object file for the Vax.
3923
3924 @end table
3925
3926 Here is a list of the header files in the source directory.
3927 (Warning: This section may not be very accurate. I didn't
3928 write the header files; I just report them.) Also note that I
3929 think many of these header files could be cleaned up or
3930 eliminated.
3931
3932 @table @file
3933
3934 @item a.out.h
3935 This describes the structures used to create the binary header data
3936 inside the object file. Perhaps we should use the one in
3937 @file{/usr/include}?
3938
3939 @item as.h
3940 This defines all the globally useful things, and pulls in _0__<stdio.h>_1__
3941 and _0__<assert.h>_1__.
3942
3943 @item bignum.h
3944 This defines macros useful for dealing with bignums.
3945
3946 @item expr.h
3947 Structure and macros for dealing with expression()
3948
3949 @item flonum.h
3950 This defines the structure for dealing with floating point
3951 numbers. It #includes @file{bignum.h}.
3952
3953 @item frags.h
3954 This contains macro for appending a byte to the current frag.
3955
3956 @item hash.h
3957 Structures and function definitions for the hashing functions.
3958
3959 @item input-file.h
3960 Function headers for the input-file.c functions.
3961
3962 @item md.h
3963 structures and function headers for things defined in the
3964 machine dependent part of the assembler.
3965
3966 @item obstack.h
3967 This is the GNU systemwide include file for manipulating obstacks.
3968 Since nobody is running under real GNU yet, we include this file.
3969
3970 @item read.h
3971 Macros and function headers for reading in source files.
3972
3973 @item struct-symbol.h
3974 Structure definition and macros for dealing with the _AS__
3975 internal form of a symbol.
3976
3977 @item subsegs.h
3978 structure definition for dealing with the numbered subsegments
3979 of the text and data segments.
3980
3981 @item symbols.h
3982 Macros and function headers for dealing with symbols.
3983
3984 @item write.h
3985 Structure for doing segment fixups.
3986 @end table
3987
3988 @comment ~subsection Test Directory
3989 @comment (Note: The test directory seems to have disappeared somewhere
3990 @comment along the line. If you want it, you'll probably have to find a
3991 @comment REALLY OLD dump tape~dots{})
3992 @comment
3993 @comment The ~file{test/} directory is used for regression testing.
3994 @comment After you modify ~@code{_AS__}, you can get a quick go/nogo
3995 @comment confidence test by running the new ~@code{_AS__} over the source
3996 @comment files in this directory. You use a shell script ~file{test/do}.
3997 @comment
3998 @comment The tests in this suite are evolving. They are not comprehensive.
3999 @comment They have, however, caught hundreds of bugs early in the debugging
4000 @comment cycle of ~@code{_AS__}. Most test statements in this suite were naturally
4001 @comment selected: they were used to demonstrate actual ~@code{_AS__} bugs rather
4002 @comment than being written ~i{a prioi}.
4003 @comment
4004 @comment Another testing suggestion: over 30 bugs have been found simply by
4005 @comment running examples from this manual through ~@code{_AS__}.
4006 @comment Some examples in this manual are selected
4007 @comment to distinguish boundary conditions; they are good for testing ~@code{_AS__}.
4008 @comment
4009 @comment ~subsubsection Regression Testing
4010 @comment Each regression test involves assembling a file and comparing the
4011 @comment actual output of ~@code{_AS__} to ``known good'' output files. Both
4012 @comment the object file and the error/warning message file (stderr) are
4013 @comment inspected. Optionally the ~@code{_AS__} exit status may be checked.
4014 @comment Discrepencies are reported. Each discrepency means either that
4015 @comment you broke some part of ~@code{_AS__} or that the ``known good'' files
4016 @comment are now out of date and should be changed to reflect the new
4017 @comment definition of ``good''.
4018 @comment
4019 @comment Each regression test lives in its own directory, in a tree
4020 @comment rooted in the directory ~file{test/}. Each such directory
4021 @comment has a name ending in ~file{.ret}, where `ret' stands for
4022 @comment REgression Test. The ~file{.ret} ending allows ~code{find
4023 @comment (1)} to find all regression tests in the tree, without
4024 @comment needing to list them explicitly.
4025 @comment
4026 @comment Any ~file{.ret} directory must contain a file called
4027 @comment ~file{input} which is the source file to assemble. During
4028 @comment testing an object file ~file{output} is created, as well as
4029 @comment a file ~file{stdouterr} which contains the output to both
4030 @comment stderr and stderr. If there is a file ~file{output.good} in
4031 @comment the directory, and if ~file{output} contains exactly the
4032 @comment same data as ~file{output.good}, the file ~file{output} is
4033 @comment deleted. Likewise ~file{stdouterr} is removed if it exactly
4034 @comment matches a file ~file{stdouterr.good}. If file
4035 @comment ~file{status.good} is present, containing a decimal number
4036 @comment before a newline, the exit status of ~@code{_AS__} is compared
4037 @comment to this number. If the status numbers are not equal, a file
4038 @comment ~file{status} is written to the directory, containing the
4039 @comment actual status as a decimal number followed by newline.
4040 @comment
4041 @comment Should any of the ~file{*.good} files fail to match their corresponding
4042 @comment actual files, this is noted by a 1-line message on the screen during
4043 @comment the regression test, and you can use ~@code{find (1)} to find any
4044 @comment files named ~file{status}, ~file {output} or ~file{stdouterr}.
4045 @comment
4046 @node Retargeting, License, Maintenance, Top
4047 @chapter Teaching the Assembler about a New Machine
4048
4049 This chapter describes the steps required in order to make the
4050 assembler work with another machine's assembly language. This
4051 chapter is not complete, and only describes the steps in the
4052 broadest terms. You should look at the source for the
4053 currently supported machine in order to discover some of the
4054 details that aren't mentioned here.
4055
4056 You should create a new file called @file{@var{machine}.c}, and
4057 add the appropriate lines to the file @file{Makefile} so that
4058 you can compile your new version of the assembler. This should
4059 be straighforward; simply add lines similar to the ones there
4060 for the four current versions of the assembler.
4061
4062 If you want to be compatible with GDB, (and the current
4063 machine-dependent versions of the assembler), you should create
4064 a file called @file{@var{machine}-opcode.h} which should
4065 contain all the information about the names of the machine
4066 instructions, their opcodes, and what addressing modes they
4067 support. If you do this right, the assembler and GDB can share
4068 this file, and you'll only have to write it once. Note that
4069 while you're writing @code{_AS__}, you may want to use an
4070 independent program (if you have access to one), to make sure
4071 that @code{_AS__} is emitting the correct bytes. Since @code{_AS__}
4072 and @code{GDB} share the opcode table, an incorrect opcode
4073 table entry may make invalid bytes look OK when you disassemble
4074 them with @code{GDB}.
4075
4076 @section Functions You will Have to Write
4077
4078 Your file @file{@var{machine}.c} should contain definitions for
4079 the following functions and variables. It will need to include
4080 some header files in order to use some of the structures
4081 defined in the machine-independent part of the assembler. The
4082 needed header files are mentioned in the descriptions of the
4083 functions that will need them.
4084
4085 @table @code
4086
4087 @item long omagic;
4088 This long integer holds the value to place at the beginning of
4089 the @file{a.out} file. It is usually @samp{OMAGIC}, except on
4090 machines that store additional information in the magic-number.
4091
4092 @item char comment_chars[];
4093 This character array holds the values of the characters that
4094 start a comment anywhere in a line. Comments are stripped off
4095 automatically by the machine independent part of the
4096 assembler. Note that the @samp{/*} will always start a
4097 comment, and that only @samp{*/} will end a comment started by
4098 @samp{*/}.
4099
4100 @item char line_comment_chars[];
4101 This character array holds the values of the chars that start a
4102 comment only if they are the first (non-whitespace) character
4103 on a line. If the character @samp{#} does not appear in this
4104 list, you may get unexpected results. (Various
4105 machine-independent parts of the assembler treat the comments
4106 @samp{#APP} and @samp{#NO_APP} specially, and assume that lines
4107 that start with @samp{#} are comments.)
4108
4109 @item char EXP_CHARS[];
4110 This character array holds the letters that can separate the
4111 mantissa and the exponent of a floating point number. Typical
4112 values are @samp{e} and @samp{E}.
4113
4114 @item char FLT_CHARS[];
4115 This character array holds the letters that--when they appear
4116 immediately after a leading zero--indicate that a number is a
4117 floating-point number. (Sort of how 0x indicates that a
4118 hexadecimal number follows.)
4119
4120 @item pseudo_typeS md_pseudo_table[];
4121 (@var{pseudo_typeS} is defined in @file{md.h})
4122 This array contains a list of the machine_dependent directives
4123 the assembler must support. It contains the name of each
4124 pseudo op (Without the leading @samp{.}), a pointer to a
4125 function to be called when that directive is encountered, and
4126 an integer argument to be passed to that function.
4127
4128 @item void md_begin(void)
4129 This function is called as part of the assembler's
4130 initialization. It should do any initialization required by
4131 any of your other routines.
4132
4133 @item int md_parse_option(char **optionPTR, int *argcPTR, char ***argvPTR)
4134 This routine is called once for each option on the command line
4135 that the machine-independent part of @code{_AS__} does not
4136 understand. This function should return non-zero if the option
4137 pointed to by @var{optionPTR} is a valid option. If it is not
4138 a valid option, this routine should return zero. The variables
4139 @var{argcPTR} and @var{argvPTR} are provided in case the option
4140 requires a filename or something similar as an argument. If
4141 the option is multi-character, @var{optionPTR} should be
4142 advanced past the end of the option, otherwise every letter in
4143 the option will be treated as a separate single-character
4144 option.
4145
4146 @item void md_assemble(char *string)
4147 This routine is called for every machine-dependent
4148 non-directive line in the source file. It does all the real
4149 work involved in reading the opcode, parsing the operands,
4150 etc. @var{string} is a pointer to a null-terminated string,
4151 that comprises the input line, with all excess whitespace and
4152 comments removed.
4153
4154 @item void md_number_to_chars(char *outputPTR,long value,int nbytes)
4155 This routine is called to turn a C long int, short int, or char
4156 into the series of bytes that represents that number on the
4157 target machine. @var{outputPTR} points to an array where the
4158 result should be stored; @var{value} is the value to store; and
4159 @var{nbytes} is the number of bytes in 'value' that should be
4160 stored.
4161
4162 @item void md_number_to_imm(char *outputPTR,long value,int nbytes)
4163 This routine is called to turn a C long int, short int, or char
4164 into the series of bytes that represent an immediate value on
4165 the target machine. It is identical to the function @code{md_number_to_chars},
4166 except on NS32K machines.@refill
4167
4168 @item void md_number_to_disp(char *outputPTR,long value,int nbytes)
4169 This routine is called to turn a C long int, short int, or char
4170 into the series of bytes that represent an displacement value on
4171 the target machine. It is identical to the function @code{md_number_to_chars},
4172 except on NS32K machines.@refill
4173
4174 @item void md_number_to_field(char *outputPTR,long value,int nbytes)
4175 This routine is identical to @code{md_number_to_chars},
4176 except on NS32K machines.
4177
4178 @item void md_ri_to_chars(struct relocation_info *riPTR,ri)
4179 (@code{struct relocation_info} is defined in @file{a.out.h})
4180 This routine emits the relocation info in @var{ri}
4181 in the appropriate bit-pattern for the target machine.
4182 The result should be stored in the location pointed
4183 to by @var{riPTR}. This routine may be a no-op unless you are
4184 attempting to do cross-assembly.
4185
4186 @item char *md_atof(char type,char *outputPTR,int *sizePTR)
4187 This routine turns a series of digits into the appropriate
4188 internal representation for a floating-point number.
4189 @var{type} is a character from @var{FLT_CHARS[]} that describes
4190 what kind of floating point number is wanted; @var{outputPTR}
4191 is a pointer to an array that the result should be stored in;
4192 and @var{sizePTR} is a pointer to an integer where the size (in
4193 bytes) of the result should be stored. This routine should
4194 return an error message, or an empty string (not (char *)0) for
4195 success.
4196
4197 @item int md_short_jump_size;
4198 This variable holds the (maximum) size in bytes of a short (16
4199 bit or so) jump created by @code{md_create_short_jump()}. This
4200 variable is used as part of the broken-word feature, and isn't
4201 needed if the assembler is compiled with
4202 @samp{-DWORKING_DOT_WORD}.
4203
4204 @item int md_long_jump_size;
4205 This variable holds the (maximum) size in bytes of a long (32
4206 bit or so) jump created by @code{md_create_long_jump()}. This
4207 variable is used as part of the broken-word feature, and isn't
4208 needed if the assembler is compiled with
4209 @samp{-DWORKING_DOT_WORD}.
4210
4211 @item void md_create_short_jump(char *resultPTR,long from_addr,
4212 @code{long to_addr,fragS *frag,symbolS *to_symbol)}
4213 This function emits a jump from @var{from_addr} to @var{to_addr} in
4214 the array of bytes pointed to by @var{resultPTR}. If this creates a
4215 type of jump that must be relocated, this function should call
4216 @code{fix_new()} with @var{frag} and @var{to_symbol}. The jump
4217 emitted by this function may be smaller than @var{md_short_jump_size},
4218 but it must never create a larger one.
4219 (If it creates a smaller jump, the extra bytes of memory will not be
4220 used.) This function is used as part of the broken-word feature,
4221 and isn't needed if the assembler is compiled with
4222 @samp{-DWORKING_DOT_WORD}.@refill
4223
4224 @item void md_create_long_jump(char *ptr,long from_addr,
4225 @code{long to_addr,fragS *frag,symbolS *to_symbol)}
4226 This function is similar to the previous function,
4227 @code{md_create_short_jump()}, except that it creates a long
4228 jump instead of a short one. This function is used as part of
4229 the broken-word feature, and isn't needed if the assembler is
4230 compiled with @samp{-DWORKING_DOT_WORD}.
4231
4232 @item int md_estimate_size_before_relax(fragS *fragPTR,int segment_type)
4233 This function does the initial setting up for relaxation. This
4234 includes forcing references to still-undefined symbols to the
4235 appropriate addressing modes.
4236
4237 @item relax_typeS md_relax_table[];
4238 (relax_typeS is defined in md.h)
4239 This array describes the various machine dependent states a
4240 frag may be in before relaxation. You will need one group of
4241 entries for each type of addressing mode you intend to relax.
4242
4243 @item void md_convert_frag(fragS *fragPTR)
4244 (@var{fragS} is defined in @file{as.h})
4245 This routine does the required cleanup after relaxation.
4246 Relaxation has changed the type of the frag to a type that can
4247 reach its destination. This function should adjust the opcode
4248 of the frag to use the appropriate addressing mode.
4249 @var{fragPTR} points to the frag to clean up.
4250
4251 @item void md_end(void)
4252 This function is called just before the assembler exits. It
4253 need not free up memory unless the operating system doesn't do
4254 it automatically on exit. (In which case you'll also have to
4255 track down all the other places where the assembler allocates
4256 space but never frees it.)
4257
4258 @end table
4259
4260 @section External Variables You will Need to Use
4261
4262 You will need to refer to or change the following external variables
4263 from within the machine-dependent part of the assembler.
4264
4265 @table @code
4266 @item extern char flagseen[];
4267 This array holds non-zero values in locations corresponding to
4268 the options that were on the command line. Thus, if the
4269 assembler was called with @samp{-W}, @var{flagseen['W']} would
4270 be non-zero.
4271
4272 @item extern fragS *frag_now;
4273 This pointer points to the current frag--the frag that bytes
4274 are currently being added to. If nothing else, you will need
4275 to pass it as an argument to various machine-independent
4276 functions. It is maintained automatically by the
4277 frag-manipulating functions; you should never have to change it
4278 yourself.
4279
4280 @item extern LITTLENUM_TYPE generic_bignum[];
4281 (@var{LITTLENUM_TYPE} is defined in @file{bignum.h}.
4282 This is where @dfn{bignums}--numbers larger than 32 bits--are
4283 returned when they are encountered in an expression. You will
4284 need to use this if you need to implement directives (or
4285 anything else) that must deal with these large numbers.
4286 @code{Bignums} are of @code{segT} @code{SEG_BIG} (defined in
4287 @file{as.h}, and have a positive @code{X_add_number}. The
4288 @code{X_add_number} of a @code{bignum} is the number of
4289 @code{LITTLENUMS} in @var{generic_bignum} that the number takes
4290 up.
4291
4292 @item extern FLONUM_TYPE generic_floating_point_number;
4293 (@var{FLONUM_TYPE} is defined in @file{flonum.h}.
4294 The is where @dfn{flonums}--floating-point numbers within
4295 expressions--are returned. @code{Flonums} are of @code{segT}
4296 @code{SEG_BIG}, and have a negative @code{X_add_number}.
4297 @code{Flonums} are returned in a generic format. You will have
4298 to write a routine to turn this generic format into the
4299 appropriate floating-point format for your machine.
4300
4301 @item extern int need_pass_2;
4302 If this variable is non-zero, the assembler has encountered an
4303 expression that cannot be assembled in a single pass. Since
4304 the second pass isn't implemented, this flag means that the
4305 assembler is punting, and is only looking for additional syntax
4306 errors. (Or something like that.)
4307
4308 @item extern segT now_seg;
4309 This variable holds the value of the segment the assembler is
4310 currently assembling into.
4311
4312 @end table
4313
4314 @section External functions will you need
4315
4316 You will find the following external functions useful (or
4317 indispensable) when you're writing the machine-dependent part
4318 of the assembler.
4319
4320 @table @code
4321
4322 @item char *frag_more(int bytes)
4323 This function allocates @var{bytes} more bytes in the current
4324 frag (or starts a new frag, if it can't expand the current frag
4325 any more.) for you to store some object-file bytes in. It
4326 returns a pointer to the bytes, ready for you to store data in.
4327
4328 @item void fix_new(fragS *frag, int where, short size, symbolS *add_symbol, symbolS *sub_symbol, long offset, int pcrel)
4329 This function stores a relocation fixup to be acted on later.
4330 @var{frag} points to the frag the relocation belongs in;
4331 @var{where} is the location within the frag where the relocation begins;
4332 @var{size} is the size of the relocation, and is usually 1 (a single byte),
4333 2 (sixteen bits), or 4 (a longword).
4334 The value @var{add_symbol} @minus{} @var{sub_symbol} + @var{offset}, is added to the byte(s)
4335 at _0__@var{frag->literal[where]}_1__. If @var{pcrel} is non-zero, the address of the
4336 location is subtracted from the result. A relocation entry is also added
4337 to the @file{a.out} file. @var{add_symbol}, @var{sub_symbol}, and/or
4338 @var{offset} may be NULL.@refill
4339
4340 @item char *frag_var(relax_stateT type, int max_chars, int var,
4341 @code{relax_substateT subtype, symbolS *symbol, char *opcode)}
4342 This function creates a machine-dependent frag of type @var{type}
4343 (usually @code{rs_machine_dependent}).
4344 @var{max_chars} is the maximum size in bytes that the frag may grow by;
4345 @var{var} is the current size of the variable end of the frag;
4346 @var{subtype} is the sub-type of the frag. The sub-type is used to index into
4347 @var{md_relax_table[]} during @code{relaxation}.
4348 @var{symbol} is the symbol whose value should be used to when relax-ing this frag.
4349 @var{opcode} points into a byte whose value may have to be modified if the
4350 addressing mode used by this frag changes. It typically points into the
4351 @var{fr_literal[]} of the previous frag, and is used to point to a location
4352 that @code{md_convert_frag()}, may have to change.@refill
4353
4354 @item void frag_wane(fragS *fragPTR)
4355 This function is useful from within @code{md_convert_frag}. It
4356 changes a frag to type rs_fill, and sets the variable-sized
4357 piece of the frag to zero. The frag will never change in size
4358 again.
4359
4360 @item segT expression(expressionS *retval)
4361 (@var{segT} is defined in @file{as.h}; @var{expressionS} is defined in @file{expr.h})
4362 This function parses the string pointed to by the external char
4363 pointer @var{input_line_pointer}, and returns the segment-type
4364 of the expression. It also stores the results in the
4365 @var{expressionS} pointed to by @var{retval}.
4366 @var{input_line_pointer} is advanced to point past the end of
4367 the expression. (@var{input_line_pointer} is used by other
4368 parts of the assembler. If you modify it, be sure to restore
4369 it to its original value.)
4370
4371 @item as_warn(char *message,@dots{})
4372 If warning messages are disabled, this function does nothing.
4373 Otherwise, it prints out the current file name, and the current
4374 line number, then uses @code{fprintf} to print the
4375 @var{message} and any arguments it was passed.
4376
4377 @item as_bad(char *message,@dots{})
4378 This function should be called when @code{_AS__} encounters
4379 conditions that are bad enough that @code{_AS__} should not
4380 produce an object file, but should continue reading input and
4381 printing warning and bad error messages.
4382
4383 @item as_fatal(char *message,@dots{})
4384 This function prints out the current file name and line number,
4385 prints the word @samp{FATAL:}, then uses @code{fprintf} to
4386 print the @var{message} and any arguments it was passed. Then
4387 the assembler exits. This function should only be used for
4388 serious, unrecoverable errors.
4389
4390 @item void float_const(int float_type)
4391 This function reads floating-point constants from the current
4392 input line, and calls @code{md_atof} to assemble them. It is
4393 useful as the function to call for the directives
4394 @samp{.single}, @samp{.double}, @samp{.float}, etc.
4395 @var{float_type} must be a character from @var{FLT_CHARS}.
4396
4397 @item void demand_empty_rest_of_line(void);
4398 This function can be used by machine-dependent directives to
4399 make sure the rest of the input line is empty. It prints a
4400 warning message if there are additional characters on the line.
4401
4402 @item long int get_absolute_expression(void)
4403 This function can be used by machine-dependent directives to
4404 read an absolute number from the current input line. It
4405 returns the result. If it isn't given an absolute expression,
4406 it prints a warning message and returns zero.
4407
4408 @end table
4409
4410
4411 @section The concept of Frags
4412
4413 This assembler works to optimize the size of certain addressing
4414 modes. (e.g. branch instructions) This means the size of many
4415 pieces of object code cannot be determined until after assembly
4416 is finished. (This means that the addresses of symbols cannot be
4417 determined until assembly is finished.) In order to do this,
4418 @code{_AS__} stores the output bytes as @dfn{frags}.
4419
4420 Here is the definition of a frag (from @file{as.h})
4421 @smallexample
4422 struct frag
4423 @{
4424 long int fr_fix;
4425 long int fr_var;
4426 relax_stateT fr_type;
4427 relax_substateT fr_substate;
4428 unsigned long fr_address;
4429 long int fr_offset;
4430 struct symbol *fr_symbol;
4431 char *fr_opcode;
4432 struct frag *fr_next;
4433 char fr_literal[];
4434 @}
4435 @end smallexample
4436
4437 @table @var
4438 @item fr_fix
4439 is the size of the fixed-size piece of the frag.
4440
4441 @item fr_var
4442 is the maximum (?) size of the variable-sized piece of the frag.
4443
4444 @item fr_type
4445 is the type of the frag.
4446 Current types are:
4447 rs_fill
4448 rs_align
4449 rs_org
4450 rs_machine_dependent
4451
4452 @item fr_substate
4453 This stores the type of machine-dependent frag this is. (what
4454 kind of addressing mode is being used, and what size is being
4455 tried/will fit/etc.
4456
4457 @item fr_address
4458 @var{fr_address} is only valid after relaxation is finished.
4459 Before relaxation, the only way to store an address is (pointer
4460 to frag containing the address) plus (offset into the frag).
4461
4462 @item fr_offset
4463 This contains a number, whose meaning depends on the type of
4464 the frag.
4465 for machine_dependent frags, this contains the offset from
4466 fr_symbol that the frag wants to go to. Thus, for branch
4467 instructions it is usually zero. (unless the instruction was
4468 @samp{jba foo+12} or something like that.)
4469
4470 @item fr_symbol
4471 for machine_dependent frags, this points to the symbol the frag
4472 needs to reach.
4473
4474 @item fr_opcode
4475 This points to the location in the frag (or in a previous frag)
4476 of the opcode for the instruction that caused this to be a frag.
4477 @var{fr_opcode} is needed if the actual opcode must be changed
4478 in order to use a different form of the addressing mode.
4479 (For example, if a conditional branch only comes in size tiny,
4480 a large-size branch could be implemented by reversing the sense
4481 of the test, and turning it into a tiny branch over a large jump.
4482 This would require changing the opcode.)
4483
4484 @var{fr_literal} is a variable-size array that contains the
4485 actual object bytes. A frag consists of a fixed size piece of
4486 object data, (which may be zero bytes long), followed by a
4487 piece of object data whose size may not have been determined
4488 yet. Other information includes the type of the frag (which
4489 controls how it is relaxed),
4490
4491 @item fr_next
4492 This is the next frag in the singly-linked list. This is
4493 usually only needed by the machine-independent part of
4494 @code{_AS__}.
4495
4496 @end table
4497 _fi__(0)
4498
4499 @node License, , Retargeting, Top
4500 @unnumbered GNU GENERAL PUBLIC LICENSE
4501 @center Version 1, February 1989
4502
4503 @display
4504 Copyright @copyright{} 1989 Free Software Foundation, Inc.
4505 675 Mass Ave, Cambridge, MA 02139, USA
4506
4507 Everyone is permitted to copy and distribute verbatim copies
4508 of this license document, but changing it is not allowed.
4509 @end display
4510
4511 @unnumberedsec Preamble
4512
4513 The license agreements of most software companies try to keep users
4514 at the mercy of those companies. By contrast, our General Public
4515 License is intended to guarantee your freedom to share and change free
4516 software---to make sure the software is free for all its users. The
4517 General Public License applies to the Free Software Foundation's
4518 software and to any other program whose authors commit to using it.
4519 You can use it for your programs, too.
4520
4521 When we speak of free software, we are referring to freedom, not
4522 price. Specifically, the General Public License is designed to make
4523 sure that you have the freedom to give away or sell copies of free
4524 software, that you receive source code or can get it if you want it,
4525 that you can change the software or use pieces of it in new free
4526 programs; and that you know you can do these things.
4527
4528 To protect your rights, we need to make restrictions that forbid
4529 anyone to deny you these rights or to ask you to surrender the rights.
4530 These restrictions translate to certain responsibilities for you if you
4531 distribute copies of the software, or if you modify it.
4532
4533 For example, if you distribute copies of a such a program, whether
4534 gratis or for a fee, you must give the recipients all the rights that
4535 you have. You must make sure that they, too, receive or can get the
4536 source code. And you must tell them their rights.
4537
4538 We protect your rights with two steps: (1) copyright the software, and
4539 (2) offer you this license which gives you legal permission to copy,
4540 distribute and/or modify the software.
4541
4542 Also, for each author's protection and ours, we want to make certain
4543 that everyone understands that there is no warranty for this free
4544 software. If the software is modified by someone else and passed on, we
4545 want its recipients to know that what they have is not the original, so
4546 that any problems introduced by others will not reflect on the original
4547 authors' reputations.
4548
4549 The precise terms and conditions for copying, distribution and
4550 modification follow.
4551
4552 @iftex
4553 @unnumberedsec TERMS AND CONDITIONS
4554 @end iftex
4555 @ifinfo
4556 @center TERMS AND CONDITIONS
4557 @end ifinfo
4558
4559 @enumerate
4560 @item
4561 This License Agreement applies to any program or other work which
4562 contains a notice placed by the copyright holder saying it may be
4563 distributed under the terms of this General Public License. The
4564 ``Program'', below, refers to any such program or work, and a ``work based
4565 on the Program'' means either the Program or any work containing the
4566 Program or a portion of it, either verbatim or with modifications. Each
4567 licensee is addressed as ``you''.
4568
4569 @item
4570 You may copy and distribute verbatim copies of the Program's source
4571 code as you receive it, in any medium, provided that you conspicuously and
4572 appropriately publish on each copy an appropriate copyright notice and
4573 disclaimer of warranty; keep intact all the notices that refer to this
4574 General Public License and to the absence of any warranty; and give any
4575 other recipients of the Program a copy of this General Public License
4576 along with the Program. You may charge a fee for the physical act of
4577 transferring a copy.
4578
4579 @item
4580 You may modify your copy or copies of the Program or any portion of
4581 it, and copy and distribute such modifications under the terms of Paragraph
4582 1 above, provided that you also do the following:
4583
4584 @itemize @bullet
4585 @item
4586 cause the modified files to carry prominent notices stating that
4587 you changed the files and the date of any change; and
4588
4589 @item
4590 cause the whole of any work that you distribute or publish, that
4591 in whole or in part contains the Program or any part thereof, either
4592 with or without modifications, to be licensed at no charge to all
4593 third parties under the terms of this General Public License (except
4594 that you may choose to grant warranty protection to some or all
4595 third parties, at your option).
4596
4597 @item
4598 If the modified program normally reads commands interactively when
4599 run, you must cause it, when started running for such interactive use
4600 in the simplest and most usual way, to print or display an
4601 announcement including an appropriate copyright notice and a notice
4602 that there is no warranty (or else, saying that you provide a
4603 warranty) and that users may redistribute the program under these
4604 conditions, and telling the user how to view a copy of this General
4605 Public License.
4606
4607 @item
4608 You may charge a fee for the physical act of transferring a
4609 copy, and you may at your option offer warranty protection in
4610 exchange for a fee.
4611 @end itemize
4612
4613 Mere aggregation of another independent work with the Program (or its
4614 derivative) on a volume of a storage or distribution medium does not bring
4615 the other work under the scope of these terms.
4616
4617 @item
4618 You may copy and distribute the Program (or a portion or derivative of
4619 it, under Paragraph 2) in object code or executable form under the terms of
4620 Paragraphs 1 and 2 above provided that you also do one of the following:
4621
4622 @itemize @bullet
4623 @item
4624 accompany it with the complete corresponding machine-readable
4625 source code, which must be distributed under the terms of
4626 Paragraphs 1 and 2 above; or,
4627
4628 @item
4629 accompany it with a written offer, valid for at least three
4630 years, to give any third party free (except for a nominal charge
4631 for the cost of distribution) a complete machine-readable copy of the
4632 corresponding source code, to be distributed under the terms of
4633 Paragraphs 1 and 2 above; or,
4634
4635 @item
4636 accompany it with the information you received as to where the
4637 corresponding source code may be obtained. (This alternative is
4638 allowed only for noncommercial distribution and only if you
4639 received the program in object code or executable form alone.)
4640 @end itemize
4641
4642 Source code for a work means the preferred form of the work for making
4643 modifications to it. For an executable file, complete source code means
4644 all the source code for all modules it contains; but, as a special
4645 exception, it need not include source code for modules which are standard
4646 libraries that accompany the operating system on which the executable
4647 file runs, or for standard header files or definitions files that
4648 accompany that operating system.
4649
4650 @item
4651 You may not copy, modify, sublicense, distribute or transfer the
4652 Program except as expressly provided under this General Public License.
4653 Any attempt otherwise to copy, modify, sublicense, distribute or transfer
4654 the Program is void, and will automatically terminate your rights to use
4655 the Program under this License. However, parties who have received
4656 copies, or rights to use copies, from you under this General Public
4657 License will not have their licenses terminated so long as such parties
4658 remain in full compliance.
4659
4660 @item
4661 By copying, distributing or modifying the Program (or any work based
4662 on the Program) you indicate your acceptance of this license to do so,
4663 and all its terms and conditions.
4664
4665 @item
4666 Each time you redistribute the Program (or any work based on the
4667 Program), the recipient automatically receives a license from the original
4668 licensor to copy, distribute or modify the Program subject to these
4669 terms and conditions. You may not impose any further restrictions on the
4670 recipients' exercise of the rights granted herein.
4671
4672 @item
4673 The Free Software Foundation may publish revised and/or new versions
4674 of the General Public License from time to time. Such new versions will
4675 be similar in spirit to the present version, but may differ in detail to
4676 address new problems or concerns.
4677
4678 Each version is given a distinguishing version number. If the Program
4679 specifies a version number of the license which applies to it and ``any
4680 later version'', you have the option of following the terms and conditions
4681 either of that version or of any later version published by the Free
4682 Software Foundation. If the Program does not specify a version number of
4683 the license, you may choose any version ever published by the Free Software
4684 Foundation.
4685
4686 @item
4687 If you wish to incorporate parts of the Program into other free
4688 programs whose distribution conditions are different, write to the author
4689 to ask for permission. For software which is copyrighted by the Free
4690 Software Foundation, write to the Free Software Foundation; we sometimes
4691 make exceptions for this. Our decision will be guided by the two goals
4692 of preserving the free status of all derivatives of our free software and
4693 of promoting the sharing and reuse of software generally.
4694
4695 @iftex
4696 @heading NO WARRANTY
4697 @end iftex
4698 @ifinfo
4699 @center NO WARRANTY
4700 @end ifinfo
4701
4702 @item
4703 BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
4704 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
4705 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
4706 PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
4707 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
4708 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
4709 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
4710 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
4711 REPAIR OR CORRECTION.
4712
4713 @item
4714 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
4715 ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
4716 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
4717 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
4718 ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT
4719 LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES
4720 SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
4721 WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
4722 ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
4723 @end enumerate
4724
4725 @iftex
4726 @heading END OF TERMS AND CONDITIONS
4727 @end iftex
4728 @ifinfo
4729 @center END OF TERMS AND CONDITIONS
4730 @end ifinfo
4731
4732 @page
4733 @unnumberedsec Applying These Terms to Your New Programs
4734
4735 If you develop a new program, and you want it to be of the greatest
4736 possible use to humanity, the best way to achieve this is to make it
4737 free software which everyone can redistribute and change under these
4738 terms.
4739
4740 To do so, attach the following notices to the program. It is safest to
4741 attach them to the start of each source file to most effectively convey
4742 the exclusion of warranty; and each file should have at least the
4743 ``copyright'' line and a pointer to where the full notice is found.
4744
4745 @smallexample
4746 @var{one line to give the program's name and a brief idea of what it does.}
4747 Copyright (C) 19@var{yy} @var{name of author}
4748
4749 This program is free software; you can redistribute it and/or modify
4750 it under the terms of the GNU General Public License as published by
4751 the Free Software Foundation; either version 1, or (at your option)
4752 any later version.
4753
4754 This program is distributed in the hope that it will be useful,
4755 but WITHOUT ANY WARRANTY; without even the implied warranty of
4756 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4757 GNU General Public License for more details.
4758
4759 You should have received a copy of the GNU General Public License
4760 along with this program; if not, write to the Free Software
4761 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4762 @end smallexample
4763
4764 Also add information on how to contact you by electronic and paper mail.
4765
4766 If the program is interactive, make it output a short notice like this
4767 when it starts in an interactive mode:
4768
4769 @smallexample
4770 Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
4771 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
4772 This is free software, and you are welcome to redistribute it
4773 under certain conditions; type `show c' for details.
4774 @end smallexample
4775
4776 The hypothetical commands `show w' and `show c' should show the
4777 appropriate parts of the General Public License. Of course, the
4778 commands you use may be called something other than `show w' and `show
4779 c'; they could even be mouse-clicks or menu items---whatever suits your
4780 program.
4781
4782 You should also get your employer (if you work as a programmer) or your
4783 school, if any, to sign a ``copyright disclaimer'' for the program, if
4784 necessary. Here is a sample; alter the names:
4785
4786 @smallexample
4787 Yoyodyne, Inc., hereby disclaims all copyright interest in the
4788 program `Gnomovision' (a program to direct compilers to make passes
4789 at assemblers) written by James Hacker.
4790
4791 @var{signature of Ty Coon}, 1 April 1989
4792 Ty Coon, President of Vice
4793 @end smallexample
4794
4795 That's all there is to it!
4796
4797
4798 @summarycontents
4799 @contents
4800 @bye