]> Git Repo - binutils.git/blame - gas/doc/as.texinfo
* gdb-int.texinfo: Add text on how to define a new host or target
[binutils.git] / gas / doc / as.texinfo
CommitLineData
93b45514
RP
1\input texinfo @c -*-texinfo-*-
2@tex
3\special{twoside}
4@end tex
5@setfilename as
6@settitle as
7@titlepage
8@center @titlefont{as}
9@sp 1
10@center The GNU Assembler
11@sp 2
12@center Dean Elsner, Jay Fenlason & friends
13@sp 13
14The Free Software Foundation Inc. thanks The Nice Computer
15Company of Australia for loaning Dean Elsner to write the
16first (Vax) version of @code{as} for Project GNU.
17The proprietors, management and staff of TNCCA thank FSF for
18distracting the boss while they got some work
19done.
20@sp 3
21
22Copyright @copyright{} 1986,1987 Free Software Foundation, Inc.
23
24Permission is granted to make and distribute verbatim copies of
25this manual provided the copyright notice and this permission notice
26are preserved on all copies.
27
28@ignore
29Permission is granted to process this file through Tex and print the
30results, provided the printed document carries copying permission
31notice identical to this one except for the removal of this paragraph
32(this paragraph not being relevant to the printed manual).
33
34@end ignore
35Permission is granted to copy and distribute modified versions of this
36manual under the conditions for verbatim copying, provided that the entire
37resulting derived work is distributed under the terms of a permission
38notice identical to this one.
39
40Permission is granted to copy and distribute translations of this manual
41into another language, under the same conditions as for modified versions.
42
43@end titlepage
44@node top, Syntax, top, top
45@chapter Overview, Usage
46@menu
47* Syntax:: The (machine independent) syntax that assembly language
48 files must follow. The machine dependent syntax
49 can be found in the machine dependent section of
50 the manual for the machine that you are using.
51* Segments:: How to use segments and subsegments, and how the
52 assembler and linker will relocate things.
53* Symbols:: How to set up and manipulate symbols.
54* Expressions:: And how the assembler deals with them.
55* PseudoOps:: The assorted machine directives that tell the
56 assembler exactly what to do with its input.
57* MachineDependent:: Information specific to each machine.
58* Maintenance:: Keeping the assembler running.
59* Retargeting:: Teaching the assembler about new machines.
60@end menu
61
62This document describes the GNU assembler @code{as}. This document
63does @emph{not} describe what an assembler does, or how it works.
64This document also does @emph{not} describe the opcodes, registers
65or addressing modes that @code{as} uses on any paticular computer
66that @code{as} runs on. Consult a good book on assemblers or the
67machine's architecture if you need that information.
68
69This document describes the directives that @code{as} understands,
70and their syntax. This document also describes some of the
71machine-dependent features of various flavors of the assembler.
72This document also describes how the assembler works internally, and
73provides some information that may be useful to people attempting to
74port the assembler to another machine.
75
76
77Throughout this document, we assume that you are running @dfn{GNU},
78the portable operating system from the @dfn{Free Software
79Foundation, Inc.}. This restricts our attention to certain kinds of
80computer (in paticular, the kinds of computers that GNU can run on);
81once this assumption is granted examples and definitions need less
82qualification.
83
84Readers should already comprehend:
85@itemize @bullet
86@item
87Central processing unit
88@item
89registers
90@item
91memory address
92@item
93contents of memory address
94@item
95bit
96@item
978-bit byte
98@item
992's complement arithmetic
100@end itemize
101
102@code{as} is part of a team of programs that turn a high-level
103human-readable series of instructions into a low-level
104computer-readable series of instructions. Different versions of
105@code{as} are used for different kinds of computer. In paticular,
106at the moment, @code{as} only works for the DEC Vax, the Motorola
107680x0, the Intel 80386, the Sparc, and the National Semiconductor
10832032/32532.
109
110@section Notation
111GNU and @code{as} assume the computer that will run the programs it
112assembles will obey these rules.
113
114A (memory) @dfn{address} is 32 bits. The lowest address is zero.
115
116The @dfn{contents} of any memory address is one @dfn{byte} of
117exactly 8 bits.
118
119A @dfn{word} is 16 bits stored in two bytes of memory. The addresses
120of the bytes differ by exactly 1. Notice that the interpretation of
121the bits in a word and of how to address a word depends on which
122particular computer you are assembling for.
123
124A @dfn{long word}, or @dfn{long}, is 32 bits composed of four bytes.
125It is stored in 4 bytes of memory; these bytes have contiguous
126addresses. Again the interpretation and addressing of those bits is
127machine dependent. National Semiconductor 32x32 computers say
128@i{double word} where we say @i{long}.
129
130Numeric quantities are usually @i{unsigned} or @i{2's complement}.
131Bytes, words and longs may store numbers. @code{as} manipulates
132integer expressions as 32-bit numbers in 2's complement format.
133When asked to store an integer in a byte or word, the lowest order
134bits are stored. The order of bytes in a word or long in memory is
135determined by what kind of computer will run the assembled program.
136We won't mention this important @i{caveat} again.
137
138The meaning of these terms has changed over time. Although @i{byte}
139used to mean any length of contiguous bits, @i{byte} now pervasively
140means exactly 8 contiguous bits. A @i{word} of 16 bits made sense
141for 16-bit computers. Even on 32-bit computers, a @i{word} still
142means 16 bits (to machine language programmers). To many other
143programmers of GNU a @i{word} means 32 bits, so beware. Similarly
144@i{long} means 32 bits: from ``long word''. National Semiconductor
14532x32 machine language calls a 32-bit number a ``double word''.
146
147@example
148
149 Names for integers of different sizes: some conventions
150
151
152length as vax 32x32 680x0 GNU C
153(bits)
154
155 8 byte byte byte byte char
156 16 word word word word short (int)
157 32 long long(-word) double-word long(-word) long (int)
158 64 quad quad(-word)
159128 octa octa-word
160
161@end example
162
163@section as, the GNU Assembler
164@dfn{As} is an assembler; it is one of the team of programs that
165`compile' your programs into the binary numbers that a computer uses
166to `run' your program. Often @code{as} reads a @i{source} program
167written by a compiler and writes an @dfn{object} program for the
168linker (sometimes referred to as a @dfn{loader}) @code{ld} to read.
169
170The source program consists of @dfn{statements} and comments. Each
171statement might @dfn{assemble} to one (and only one) machine
172language instruction or to one very simple datum.
173
174Mostly you don't have to think about the assembler because the
175compiler invokes it as needed; in that sense the assembler is just
176another part of the compiler. If you write your own assembly
177language program, then you must run the assembler yourself to get an
178object file suitable for linking. You can read below how to do this.
179
180@code{as} is only intended to assemble the output of the C compiler
181@code{cc} for use by the linker @code{ld}. @code{as} tries to
182assemble correctly everything that the standard assembler would
183assemble, with a few exceptions (described in the machine-dependent
184chapters.) Note that this doesn't mean @code{as} will use the same
185syntax as the standard assembler. For example, we know of several
186incompatable syntaxes for the 680x0.
187
188Each version of the assembler knows about just one kind of machine
189language, but much is common between the versions, including object
190file formats, (most) assembler directives (often called
191@dfn{pseudo-ops)} and assembler syntax.
192
193Unlike older assemblers, @code{as} tries to assemble a source program
194in one pass of the source file. This subtly changes the meaning of
195the @kbd{.org} directive (@xref{Org}.).
196
197If you want to write assembly language programs, you must tell
198@code{as} what numbers should be in a computer's memory, and which
199addresses should contain them, so that the program may be executed
200by the computer. Using symbols will prevent many bookkeeping
201mistakes that can occur if you use raw numbers.
202
203@section Command Line Synopsis
204@example
205as [ options @dots{} ] [ file1 @dots{} ]
206@end example
207
208After the program name @code{as}, the command line may contain
209options and file names. Options may be in any order, and may be
210before, after, or between file names. The order of file names is
211significant.
212
213@subsection Options
214
215Except for @samp{--} any command line argument that begins with a
216hyphen (@samp{-}) is an option. Each option changes the behavior of
217@code{as}. No option changes the way another option works. An
218option is a @samp{-} followed by one ore more letters; the case of
219the letter is important. No option (letter) should be used twice on
220the same command line. (Nobody has decided what two copies of the
221same option should mean.) All options are optional.
222
223Some options expect exactly one file name to follow them. The file
224name may either immediately follow the option's letter (compatible
225with older assemblers) or it may be the next command argument (GNU
226standard). These two command lines are equivalent:
227
228@example
229as -o my-object-file.o mumble
230as -omy-object-file.o mumble
231@end example
232
233Always, @file{--} (that's two hyphens, not one) by itself names the
234standard input file.
235
236@section Input File(s)
237
238We use the words @dfn{source program}, abbreviated @dfn{source}, to
239describe the program input to one run of @code{as}. The program may
240be in one or more files; how the source is partitioned into files
241doesn't change the meaning of the source.
242
243The source text is a catenation of the text in each file.
244
245Each time you run @code{as} it assembles exactly one source
246program. A source program text is made of one or more files.
247(The standard input is also a file.)
248
249You give @code{as} a command line that has zero or more input file
250names. The input files are read (from left file name to right). A
251command line argument (in any position) that has no special meaning
252is taken to be an input file name. If @code{as} is given no file
253names it attempts to read one input file from @code{as}'s standard
254input.
255
256Use @file{--} if you need to explicitly name the standard input file
257in your command line.
258
259It is OK to assemble an empty source. @code{as} will produce a
260small, empty object file.
261
262If you try to assemble no files then @code{as} will try to read
263standard input, which is normally your terminal. You may have to
264type @key{ctl-D} to tell @code{as} there is no more program to
265assemble.
266
267@subsection Input Filenames and Line-numbers
268A line is text up to and including the next newline. The first line
269of a file is numbered @b{1}, the next @b{2} and so on.
270
271There are two ways of locating a line in the input file(s) and both
272are used in reporting error messages. One way refers to a line
273number in a physical file; the other refers to a line number in a
274logical file.
275
276@dfn{Physical files} are those files named in the command line given
277to @code{as}.
278
279@dfn{Logical files} are ``pretend'' files which bear no relation to
280physical files. Logical file names help error messages reflect the
281proper source file. Often they are used when @code{as}' source is
282itself synthesized from other files.
283
284@section Output (Object) File
285Every time you run @code{as} it produces an output file, which is
286your assembly language program translated into numbers. This file
287is the object file; named @code{a.out} unless you tell @code{as} to
288give it another name by using the @code{-o} option. Conventionally,
289object file names end with @file{.o}. The default name of
290@file{a.out} is used for historical reasons. Older assemblers were
291capable of assembling self-contained programs directly into a
292runnable program. This may still work, but hasn't been tested.
293
294The object file is for input to the linker @code{ld}. It contains
295assembled program code, information to help @code{ld} to integrate
296the assembled program into a runnable file and (optionally) symbolic
297information for the debugger. The precise format of object files is
298described elsewhere.
299
300@comment link above to some info file(s) like the description of a.out.
301@comment don't forget to describe GNU info as well as Unix lossage.
302
303@section Error and Warning Messages
304
305@code{as} may write warnings and error messages to the standard
306error file (usually your terminal). This should not happen when
307@code{as} is run automatically by a compiler. Error messages are
308useful for those (few) people who still write in assembly language.
309
310Warnings report an assumption made so that @code{as} could keep
311assembling a flawed program.
312
313Errors report a grave problem that stops the assembly.
314
315Warning messages have the format
316@example
317file_name:line_number:Warning Message Text
318@end example
319If a logical file name has been given (@xref{File}.) it is used for
320the filename, otherwise the name of the current input file is used.
321If a logical line number was given (@xref{Line}.) then it is used to
322calculate the number printed, otherwise the actual line in the
323current source file is printed. The message text is intended to be
324self explanatory (In the grand Unix tradition).
325
326Error messages have the format
327@example
328file_name:line_number:FATAL:Error Message Text
329@end example
330The file name and line number are derived the same as for warning
331messages. The actual message text may be rather less explanatory
332because many of them aren't supposed to happen.
333
334@section Options
335@subsection -f Works Faster
336@samp{-f} should only be used when assembling programs written by a
337(trusted) compiler. @samp{-f} causes the assembler to not bother
338pre-processing the input file(s) before assembling them. Needless
339to say, if the files actually need to be pre-processed (if the
340contain comments, for example), @code{as} will not work correctly if
341@samp{-f} is used.
342
343@subsection -L Includes Local Labels
344For historical reasons, labels beginning with @samp{L} (upper case
345only) are called @dfn{local labels}. Normally you don't see such
346labels because they are intended for the use of programs (like
347compilers) that compose assembler programs, not for your notice.
348Normally both @code{as} and @code{ld} discard such labels, so you
349don't normally debug with them.
350
351This option tells @code{as} to retain those @samp{L@dots{}} symbols
352in the object file. Usually if you do this you also tell the linker
353@code{ld} to preserve symbols whose names begin with @samp{L}.
354
355@subsection -o Names the Object File
356There is always one object file output when you run @code{as}. By
357default it has the name @file{a.out}. You use this option (which
358takes exactly one filename) to give the object file a different name.
359
360Whatever the object file is called, @code{as} will overwrite any
361existing file of the same name.
362
363@subsection -R Folds Data Segment into Text Segment
364@code{-R} tells @code{as} to write the object file as if all
365data-segment data lives in the text segment. This is only done at
366the very last moment: your binary data are the same, but data
367segment parts are relocated differently. The data segment part of
368your object file is zero bytes long because all it bytes are
369appended to the text segment. (@xref{Segments}.)
370
371When you use @code{-R} it would be nice to generate shorter address
372displacements (possible because we don't have to cross segments)
373between text and data segment. We don't do this simply for
374compatibility with older versions of @code{as}. @code{-R} may work
375this way in future.
376
377@subsection -W Represses Warnings
378@code{as} should never give a warning or error message when
379assembling compiler output. But programs written by people often
380cause @code{as} to give a warning that a particular assumption was
381made. All such warnings are directed to the standard error file.
382If you use this option, any warning is repressed. This option only
383affects warning messages: it cannot change any detail of how
384@code{as} assembles your file. Errors, which stop the assembly, are
385still reported.
386
387@section Special Features to support Compilers
388
389In order to assemble compiler output into something that will work,
390@code{as} will occasionlly do strange things to @samp{.word}
391directives. In particular, when @code{gas} assembles a directive of
392the form @samp{.word sym1-sym2}, and the difference between
393@code{sym1} and @code{sym2} does not fit in 16 bits, @code{as} will
394create a @dfn{secondary jump table}, immediately before the next
395label. This @var{secondary jump table} will be preceeded by a
396short-jump to the first byte after the table. The short-jump
397prevents the flow-of-control from accidentally falling into the
398table. Inside the table will be a long-jump to @code{sym2}. The
399original @samp{.word} will contain @code{sym1} minus (the address of
400the long-jump to sym2) If there were several @samp{.word sym1-sym2}
401before the secondary jump table, all of them will be adjusted. If
402ther was a @samp{.word sym3-sym4}, that also did not fit in sixteen
403bits, a long-jump to @code{sym4} will be included in the secondary
404jump table, and the @code{.word}(s), will be adjusted to contain
405@code{sym3} minus (the address of the long-jump to sym4), etc.
406
407@emph{This feature may be disabled by compiling @code{as} with the
408@samp{-DWORKING_DOT_WORD} option.} This feature is likely to confuse
409assembly language programmers.
410
411@node Syntax, Segments, top, top
412@chapter Syntax
413This chapter informally defines the machine-independent syntax
414allowed in a source file. @code{as} has ordinary syntax; it tries
415to be upward compatible from BSD 4.2 assembler except @code{as} does
416not assemble Vax bit-fields.
417
418@section The Pre-processor
419The preprocess phase handles several aspects of the syntax. The
420pre-processor will be disabled by the @samp{-f} option, or if the
421first line of the source file is @code{#NO_APP}. The option to
422disable the pre-processor was designed to make compiler output
423assemble as fast as possible.
424
425The pre-processor adjusts and removes extra whitespace. It leaves
426one space or tab before the keywords on a line, and turns any other
427whitespace on the line into a single space.
428
429The pre-processor removes all comments, replacing them with a single
430space (for /* @dots{} */ comments), or an appropriate number of
431newlines.
432
433The pre-processor converts character constants into the appropriate
434numeric values.
435
436This means that excess whitespace, comments, and character constants
437cannot be used in the portions of the input text that are not
438pre-processed.
439
440If the first line of an input file is @code{#NO_APP} or the
441@samp{-f} option is given, the input file will not be
442pre-processed. Within such an input file, parts of the file can be
443pre-processed by putting a line that says @code{#APP} before the
444text that should be pre-processed, and putting a line that says
445@code{#NO_APP} after them. This feature is mainly intend to support
446asm statements in compilers whose output normally does not need to
447be pre-processed.
448
449@section Whitespace
450@dfn{Whitespace} is one or more blanks or tabs, in any order.
451Whitespace is used to separate symbols, and to make programs neater
452for people to read. Unless within character constants
453(@xref{Characters}.), any whitespace means the same as exactly one
454space.
455
456@section Comments
457There are two ways of rendering comments to @code{as}. In both
458cases the comment is equivalent to one space.
459
460Anything from @samp{/*} through the next @samp{*/} is a comment.
461
462@example
463/*
464 The only way to include a newline ('\n') in a comment
465 is to use this sort of comment.
466*/
467/* This sort of comment does not nest. */
468@end example
469
470Anything from the @dfn{line comment} character to the next newline
471considered a comment and is ignored. The line comment character is
472@samp{#} on the Vax, and @samp{|} on the 680x0.
473@xref{MachineDependent}. On some machines there are two different
474line comment characters. One will only begin a comment if it is the
475first non-whitespace character on a line, while the other will
476always begin a comment.
477
478To be compatible with past assemblers a special interpretation is
479given to lines that begin with @samp{#}. Following the @samp{#} an
480absolute expression (@pxref{Expressions}) is expected: this will be
481the logical line number of the @b{next} line. Then a string
482(@xref{Strings}.) is allowed: if present it is a new logical file
483name. The rest of the line, if any, should be whitespace.
484
485If the first non-whitespace characters on the line are not numeric,
486the line is ignored. (Just like a comment.)
487@example
488 # This is an ordinary comment.
489# 42-6 "new_file_name" # New logical file name
490 # This is logical line # 36.
491@end example
492This feature is deprecated, and may disappear from future versions
493of @code{as}.
494
495@section Symbols
496A @dfn{symbol} is one or more characters chosen from the set of all
497letters (both upper and lower case), digits and the three characters
498@samp{_.$}. No symbol may begin with a digit. Case is
499significant. There is no length limit: all characters are
500significant. Symbols are delimited by characters not in that set,
501or by begin/end-of-file. (@xref{Symbols}.)
502
503@section Statements
504A @dfn{statement} ends at a newline character (@samp{\n}) or at a
505semicolon (@samp{;}). The newline or semicolon is considered part
506of the preceding statement. Newlines and semicolons within
507character constants are an exception: they don't end statements.
508It is an error to end any statement with end-of-file: the last
509character of any input file should be a newline.
510
511You may write a statement on more than one line if you put a
512backslash (@kbd{\}) immediately in front of any newlines within the
513statement. When @code{as} reads a backslashed newline both
514characters are ignored. You can even put backslashed newlines in
515the middle of symbol names without changing the meaning of your
516source program.
517
518An empty statement is OK, and may include whitespace. It is ignored.
519
520Statements begin with zero or more labels, followed by a @dfn{key
521symbol} which determines what kind of statement it is. The key
522symbol determines the syntax of the rest of the statement. If the
523symbol begins with a dot (@t{.}) then the statement is an assembler
524directive: typically valid for any computer. If the symbol begins
525with a letter the statement is an assembly language
526@dfn{instruction}: it will assemble into a machine language
527instruction. Different versions of @code{as} for different
528computers will recognize different instructions. In fact, the same
529symbol may represent a different instruction in a different
530computer's assembly language.
531
532A label is usually a symbol immediately followed by a colon
533(@code{:}). Whitespace before a label or after a colon is OK. You
534may not have whitespace between a label's symbol and its colon.
535Labels are explained below.
536@xref{Labels}.
537
538@example
539label: .directive followed by something
540another$label: # This is an empty statement.
541 instruction operand_1, operand_2, @dots{}
542@end example
543
544@section Constants
545A constant is a number, written so that its value is known by
546inspection, without knowing any context. Like this:
547@example
548.byte 74, 0112, 092, 0x4A, 0X4a, 'J, '\J # All the same value.
549.ascii "Ring the bell\7" # A string constant.
550.octa 0x123456789abcdef0123456789ABCDEF0 # A bignum.
551.float 0f-314159265358979323846264338327\
55295028841971.693993751E-40 # - pi, a flonum.
553@end example
554
555@node Characters, Strings, , Syntax
556@subsection Character Constants
557There are two kinds of character constants. @dfn{Characters} stand
558for one character in one byte and their values may be used in
559numeric expressions. String constants (properly called string
560@i{literals}) are potentially many bytes and their values may not be
561used in arithmetic expressions.
562
563@node Strings, , Characters, Syntax
564@subsubsection Strings
565A @dfn{string} is written between double-quotes. It may contain
566double-quotes or null characters. The way to get weird characters
567into a string is to @dfn{escape} these characters: precede them with
568a backslash (@code{\}) character. For example @samp{\\} represents
569one backslash: the first @code{\} is an escape which tells
570@code{as} to interpret the second character literally as a backslash
571(which prevents @code{as} from recognizing the second @code{\} as an
572escape character). The complete list of escapes follows.
573
574@table @kbd
575@item \EOF
576A @kbd{\} followed by end-of-file erroneous. It is treated just
577like an end-of-file without a preceding backslash.
578@c @item \a
579@c Mnemonic for ACKnowledge; for ASCII this is octal code 007.
580@item \b
581Mnemonic for backspace; for ASCII this is octal code 010.
582@c @item \e
583@c Mnemonic for EOText; for ASCII this is octal code 004.
584@item \f
585Mnemonic for FormFeed; for ASCII this is octal code 014.
586@item \n
587Mnemonic for newline; for ASCII this is octal code 012.
588@c @item \p
589@c Mnemonic for prefix; for ASCII this is octal code 033, usually known as @code{escape}.
590@item \r
591Mnemonic for carriage-Return; for ASCII this is octal code 015.
592@c @item \s
593@c Mnemonic for space; for ASCII this is octal code 040. Included for compliance with
594@c other assemblers.
595@item \t
596Mnemonic for horizontal Tab; for ASCII this is octal code 011.
597@c @item \v
598@c Mnemonic for Vertical tab; for ASCII this is octal code 013.
599@c @item \x @var{digit} @var{digit} @var{digit}
600@c A hexadecimal character code. The numeric code is 3 hexadecimal digits.
601@item \ @var{digit} @var{digit} @var{digit}
602An octal character code. The numeric code is 3 octal digits.
603For compatibility with other Unix systems, 8 and 9 are legal digits
604with values 010 and 011 respectively.
605@item \\
606Represents one @samp{\} character.
607@c @item \'
608@c Represents one @samp{'} (accent acute) character.
609@c This is needed in single character literals
610@c (@xref{Characters}.) to represent
611@c a @samp{'}.
612@item \"
613Represents one @samp{"} character. Needed in strings to represent
614this character, because an unescaped @samp{"} would end the string.
615@item \ @var{anything-else}
616Any other character when escaped by @kbd{\} will give a warning, but
617assemble as if the @samp{\} was not present. The idea is that if
618you used an escape sequence you clearly didn't want the literal
619interpretation of the following character. However @code{as} has no
620other interpretation, so @code{as} knows it is giving you the wrong
621code and warns you of the fact.
622@end table
623
624Which characters are escapable, and what those escapes represent,
625varies widely among assemblers. The current set is what we think
626BSD 4.2 @code{as} recognizes, and is a subset of what most C
627compilers recognize. If you are in doubt, don't use an escape
628sequence.
629
630@subsubsection Characters
631A single character may be written as a single quote immediately
632followed by that character. The same escapes apply to characters as
633to strings. So if you want to write the character backslash, you
634must write @kbd{'\\} where the first @code{\} escapes the second
635@code{\}. As you can see, the quote is an accent acute, not an
636accent grave. A newline (or semicolon (@samp{;})) immediately
637following an accent acute is taken as a literal character and does
638not count as the end of a statement. The value of a character
639constant in a numeric expression is the machine's byte-wide code for
640that character. @code{as} assumes your character code is ASCII: @kbd{'A}
641means 65, @kbd{'B} means 66, and so on.
642
643@subsection Number Constants
644@code{as} distinguishes 3 flavors of numbers according to how they
645are stored in the target machine. @i{Integers} are numbers that
646would fit into an @code{int} in the C language. @i{Bignums} are
647integers, but they are stored in a more than 32 bits. @i{Flonums}
648are floating point numbers, described below.
649
650@subsubsection Integers
651An octal integer is @samp{0} followed by zero or more of the octal
652digits (@samp{01234567}).
653
654A decimal integer starts with a non-zero digit followed by zero or
655more digits (@samp{0123456789}).
656
657A hexadecimal integer is @samp{0x} or @samp{0X} followed by one or
658more hexadecimal digits chosen from @samp{0123456789abcdefABCDEF}.
659
660Integers have the obvious values. To denote a negative integer, use
661the unary operator @samp{-} discussed under expressions
662(@xref{Unops}.).
663
664@subsubsection Bignums
665A @dfn{bignum} has the same syntax and semantics as an integer
666except that the number (or its negative) takes more than 32 bits to
667represent in binary. The distinction is made because in some places
668integers are permitted while bignums are not.
669
670@subsubsection Flonums
671A @dfn{flonum} represents a floating point number. The translation
672is complex: a decimal floating point number from the text is
673converted by @code{as} to a generic binary floating point number of
674more than sufficient precision. This generic floating point number
675is converted to the particular computer's floating point format(s)
676by a portion of @code{as} specialized to that computer.
677
678A flonum is written by writing (in order)
679@itemize @bullet
680@item
681The digit @samp{0}.
682@item
683A letter, to tell @code{as} the rest of the number is a flonum.
684@kbd{e}
685is recommended. Case is not important.
686(Any otherwise illegal letter will work here,
687but that might be changed. Vax BSD 4.2 assembler
688seems to allow any of @samp{defghDEFGH}.)
689@item
690An optional sign: either @samp{+} or @samp{-}.
691@item
692An optional integer part: zero or more decimal digits.
693@item
694An optional fraction part: @samp{.} followed by zero
695or more decimal digits.
696@item
697An optional exponent, consisting of:
698@itemize @bullet
699@item
700A letter; the exact significance varies according to
701the computer that executes the program. @code{as}
702accepts any letter for now. Case is not important.
703@item
704Optional sign: either @samp{+} or @samp{-}.
705@item
706One or more decimal digits.
707@end itemize
708@end itemize
709
710At least one of @var{integer part} or @var{fraction part} must be
711present. The floating point number has the obvious value.
712
713The computer running @code{as} needs no floating point hardware.
714@code{as} does all processing using integers.
715
716@node Segments, Symbols, Syntax, top
717@chapter (Sub)Segments & Relocation
718Roughly, a @dfn{segment} is a range of addresses, with no gaps, with
719all data ``in'' those addresses being treated the same. For example
720there may be a ``read only'' segment.
721
722The linker @code{ld} reads many object files (partial programs) and
723combines their contents to form a runnable program. When @code{as}
724emits an object file, the partial program is assumed to start at
725address 0. @code{ld} will assign the final addresses the partial
726program occupies, so that different partial programs don't overlap.
727That explanation is too simple, but it will suffice to explain how
728@code{as} works.
729
730@code{ld} moves blocks of bytes of your program to their run-time
731addresses. These blocks slide to their run-time addresses as rigid
732units; their length does not change and neither does the order of
733bytes within them. Such a rigid unit is called a @i{segment}.
734Assigning run-time addresses to segments is called
735@dfn{relocation}. It includes the task of adjusting mentions of
736object-file addresses so they refer to the proper run-time addresses.
737
738An object file written by @code{as} has three segments, any of which
739may be empty. These are named @i{text}, @i{data} and @i{bss}
740segments. Within the object file, the text segment starts at
741address 0, the data segment follows, and the bss segment follows the
742data segment.
743
744To let @code{ld} know which data will change when the segments are
745relocated, and how to change that data, @code{as} also writes to the
746object file details of the relocation needed. To perform relocation
747@code{ld} must know for each mention of an address in the object
748file:
749@itemize @bullet
750@item
751At what address in the object file does this mention of
752an address begin?
753@item
754How long (in bytes) is this mention?
755@item
756Which segment does the address refer to?
757What is the numeric value of (@var{address} @t{-}
758@var{start-address of segment})?
759@item
760Is the mention of an address ``Program counter relative''?
761@end itemize
762
763In fact, every address @code{as} ever thinks about is expressed as
764(@var{segment} @t{+} @var{offset into segment}). Further, every
765expression @code{as} computes is of this segmented nature. So
766@dfn{absolute expression} means an expression with segment
767``absolute'' (@xref{LdSegs}.). A @dfn{pass1 expression} means an
768expression with segment ``pass1'' (@xref{MythSegs}.). In this
769document ``(segment, offset)'' will be written as @{ segment-name
770(offset into segment) @}.
771
772Apart from text, data and bss segments you need to know about the
773@dfn{absolute} segment. When @code{ld} mixes partial programs,
774addresses in the absolute segment remain unchanged. That is,
775address @{absolute 0@} is ``relocated'' to run-time address 0 by
776@code{ld}. Although two partial programs' data segments will not
777overlap addresses after linking, @b{by definition} their absolute
778segments will overlap. Address @{absolute 239@} in one partial
779program will always be the same address when the program is running
780as address @{absolute 239@} in any other partial program.
781
782The idea of segments is extended to the @dfn{undefined} segment.
783Any address whose segment is unknown at assembly time is by
784definition rendered @{undefined (something, unknown yet)@}. Since
785numbers are always defined, the only way to generate an undefined
786address is to mention an undefined symbol. A reference to a named
787common block would be such a symbol: its value is unknown at assembly
788time so it has segment @i{undefined}.
789
790By analogy the word @i{segment} is to describe groups of segments in
791the linked program. @code{ld} puts all partial program's text
792segments in contiguous addresses in the linked program. It is
793customary to refer to the @i{text segment} of a program, meaning all
794the addresses of all partial program's text segments. Likewise for
795data and bss segments.
796
797@section Segments
798Some segments are manipulated by @code{ld}; others are invented for
799use of @code{as} and have no meaning except during assembly.
800
801@node LdSegs, , ,
802@subsection ld segments
803@code{ld} deals with just 5 kinds of segments, summarized below.
804@table @b
805@item text segment
806@itemx data segment
807These segments hold your program bytes. @code{as} and @code{ld}
808treat them as separate but equal segments. Anything you can say of
809one segment is true of the other. When the program is running
810however it is customary for the text segment to be unalterable: it
811will contain instructions, constants and the like. The data segment
812of a running program is usually alterable: for example, C variables
813would be stored in the data segment.
814@item bss segment
815This segment contains zeroed bytes when your program begins
816running. It is used to hold unitialized variables or common
817storage. The length of each partial program's bss segment is
818important, but because it starts out containing zeroed bytes there
819is no need to store explicit zero bytes in the object file. The Bss
820segment was invented to eliminate those explicit zeros from object
821files.
822@item absolute segment
823Address 0 of this segment is always ``relocated'' to runtime address
8240. This is useful if you want to refer to an address that @code{ld}
825must not change when relocating. In this sense we speak of absolute
826addresses being ``unrelocatable'': they don't change during
827relocation.
828@item undefined segment
829This ``segment'' is a catch-all for address references to objects
830not in the preceding segments. See the description of @file{a.out}
831for details.
832@end table
833An idealized example of the 3 relocatable segments follows. Memory
834addresses are on the horizontal axis.
835
836@example
837 +-----+----+--+
838partial program # 1: |ttttt|dddd|00|
839 +-----+----+--+
840
841 text data bss
842 seg. seg. seg.
843
844 +---+---+---+
845partial program # 2: |TTT|DDD|000|
846 +---+---+---+
847
848 +--+---+-----+--+----+---+-----+~~
849linked program: | |TTT|ttttt| |dddd|DDD|00000|
850 +--+---+-----+--+----+---+-----+~~
851
852 addresses: 0 @dots{}
853@end example
854
855@node MythSegs, , ,
856@subsection Mythical Segments
857These segments are invented for the internal use of @code{as}. They
858have no meaning at run-time. You don't need to know about these
859segments except that they might be mentioned in @code{as}' warning
860messages. These segments are invented to permit the value of every
861expression in your assembly language program to be a segmented
862address.
863
864@table @b
865@item absent segment
866An expression was expected and none was found.
867@item goof segment
868An internal assembler logic error has been found. This means there
869is a bug in the assembler.
870@item grand segment
871A @dfn{grand number} is a bignum or a flonum, but not an integer.
872If a number can't be written as a C @code{int} constant, it is a
873grand number. @code{as} has to remember that a flonum or a bignum
874does not fit into 32 bits, and cannot be a primary (@xref{Primary}.)
875in an expression: this is done by making a flonum or bignum be of
876type ``grand''. This is purely for internal @code{as} convenience;
877grand segment behaves similarly to absolute segment.
878@item pass1 segment
879The expression was impossible to evaluate in the first pass. The
880assembler will attempt a second pass (second reading of the source)
881to evaluate the expression. Your expression mentioned an undefined
882symbol in a way that defies the one-pass (segment + offset in
883segment) assembly process. No compiler need emit such an expression.
884@item difference segment
885As an assist to the C compiler, expressions of the forms
886@itemize @bullet
887@item
888(undefined symbol) @t{-} (expression)
889@item
890(something) @t{-} (undefined symbol)
891@item
892(undefined symbol) @t{-} (undefined symbol)
893@end itemize
894are permitted to belong to the ``difference'' segment. @code{as}
895re-evaluates such expressions after the source file has been read
896and the symbol table built. If by that time there are no undefined
897symbols in the expression then the expression assumes a new segment.
898The intention is to permit statements like @samp{.word label -
899base_of_table} to be assembled in one pass where both @code{label}
900and @code{base_of_table} are undefined. This is useful for
901compiling C and Algol switch statements, Pascal case statements,
902FORTRAN computed goto statements and the like.
903@end table
904
905@section Sub-Segments
906Assembled bytes fall into two segments: text and data. Because you
907may have groups of text or data that you want to end up near to each
908other in the object file, @code{as}, allows you to use
909@dfn{subsegments}. Within each segment, there can be numbered
910subsegments with values from 0 to 8192. Objects assembled into the
911same subsegment will be grouped with other objects in the same
912subsegment when they are all put into the object file. For example,
913a compiler might want to store constants in the text segment, but
914might not want to have them intersperced with the program being
915assembled. In this case, the compiler could issue a @code{text 0}
916before each section of code being output, and a @code{text 1} before
917each group of constants being output.
918
919Subsegments are optional. If you don't used subsegments, everything
920will be stored in subsegment number zero.
921
922Each subsegment is zero-padded up to a multiple of four bytes.
923(Subsegments may be padded a different amount on different flavors
924of @code{as}.) Subsegments appear in your object file in numeric
925order, lowest numbered to highest. (All this to be compatible with
926other people's assemblers.) The object file, @code{ld} @i{etc.}
927have no concept of subsegments. They just see all your text
928subsegments as a text segment, and all your data subsegments as a
929data segment.
930
931To specify which subsegment you want subsequent statements assembled
932into, use a @samp{.text @var{expression}} or a @samp{.data
933@var{expression}} statement. @var{Expression} should be an absolute
934expression. (@xref{Expressions}.) If you just say @samp{.text}
935then @samp{.text 0} is assumed. Likewise @samp{.data} means
936@samp{.data 0}. Assembly begins in @code{text 0}.
937For instance:
938@example
939.text 0 # The default subsegment is text 0 anyway.
940.ascii "This lives in the first text subsegment. *"
941.text 1
942.ascii "But this lives in the second text subsegment."
943.data 0
944.ascii "This lives in the data segment,"
945.ascii "in the first data subsegment."
946.text 0
947.ascii "This lives in the first text segment,"
948.ascii "immediately following the asterisk (*)."
949@end example
950
951Each segment has a @dfn{location counter} incremented by one for
952every byte assembled into that segment. Because subsegments are
953merely a convenience restricted to @code{as} there is no concept of
954a subsegment location counter. There is no way to directly
955manipulate a location counter. The location counter of the segment
956that statements are being assembled into is said to be the
957@dfn{active} location counter.
958
959@section Bss Segment
960The @code{bss} segment is used for local common variable storage.
961You may allocate address space in the @code{bss} segment, but you may
962not dictate data to load into it before your program executes. When
963your program starts running, all the contents of the @code{bss}
964segment are zeroed bytes.
965
966Addresses in the bss segment are allocated with a special statement;
967you may not assemble anything directly into the bss segment. Hence
968there are no bss subsegments.
969
970@node Symbols, Expressions, Segments, top
971@chapter Symbols
972Because the linker uses symbols to link, the debugger uses symbols
973to debug and the programmer uses symbols to name things, symbols are
974a central concept. Symbols do not appear in the object file in the
975order they are declared. This may break some debuggers.
976
977@node Labels, , , Symbols
978@section Labels
979A @dfn{label} is written as a symbol immediately followed by a colon
980(@samp{:}). The symbol then represents the current value of the
981active location counter, and is, for example, a suitable instruction
982operand. You are warned if you use the same symbol to represent two
983different locations: the first definition overrides any other
984definitions.
985
986@section Giving Symbols Other Values
987A symbol can be given an arbitrary value by writing a symbol followed
988by an equals sign (@samp{=}) followed by an expression
989(@pxref{Expressions}). This is equivalent to using the @code{.set}
990directive. (@xref{Set}.)
991
992@section Symbol Names
993Symbol names begin with a letter or with one of @samp{$._}. That
994character may be followed by any string of digits, letters,
995underscores and dollar signs. Case of letters is significant:
996@code{foo} is a different symbol name than @code{Foo}.
997
998Each symbol has exactly one name. Each name in an assembly program
999refers to exactly one symbol. You may use that symbol name any
1000number of times in an assembly program.
1001
1002@subsection Local Symbol Names
1003
1004Local symbols help compilers and programmers use names temporarily.
1005There are ten @dfn{local} symbol names, which are re-used throughout
1006the program. Their names are @samp{0} @samp{1} @dots{} @samp{9}.
1007To define a local symbol, write a label of the form
1008@var{digit}@t{:}. To refer to the most recent previous definition
1009of that symbol write @var{digit}@t{b}, using the same digit as when
1010you defined the label. To refer to the next definition of a local
1011label, write @var{digit}@t{f} where @var{digit} gives you a choice
1012of 10 forward references. The @samp{b} stands for ``backwards'' and
1013the @samp{f} stands for ``forwards''.
1014
1015Local symbols are not used by the current C compiler.
1016
1017There is no restriction on how you can use these labels, but
1018remember that at any point in the assembly you can refer to at most
101910 prior local labels and to at most 10 forward local labels.
1020
1021Local symbol names are only a notation device. They are immediately
1022transformed into more conventional symbol names before the assembler
1023thinks about them. The symbol names stored in the symbol table,
1024appearing in error messages and optionally emitted to the object
1025file have these parts:
1026@table @kbd
1027@item L
1028All local labels begin with @samp{L}. Normally both @code{as} and
1029@code{ld} forget symbols that start with @samp{L}. These labels are
1030used for symbols you are never intended to see. If you give the
1031@samp{-L} option then @code{as} will retain these symbols in the
1032object file. By instructing @code{ld} to also retain these symbols,
1033you may use them in debugging.
1034@item @i{a digit}
1035If the label is written @samp{0:} then the digit is @samp{0}.
1036If the label is written @samp{1:} then the digit is @samp{1}.
1037And so on up through @samp{9:}.
1038@item @i{control}-A
1039This unusual character is included so you don't accidentally invent
1040a symbol of the same name. The character has ASCII value
1041@samp{\001}.
1042@item @i{an ordinal number}
1043This is like a serial number to keep the labels distinct. The first
1044@samp{0:} gets the number @samp{1}; The 15th @samp{0:} gets the
1045number @samp{15}; @i{etc.}. Likewise for the other labels @samp{1:}
1046through @samp{9:}.
1047@end table
1048For instance, the
1049first @code{1:} is named @code{L1^A1}, the 44th @code{3:} is named @code{L3^A44}.
1050
1051@section The Special Dot Symbol
1052
1053The special symbol @code{.} refers to the current address that
1054@code{as} is assembling into. Thus, the expression @samp{melvin:
1055.long .} will cause @var{melvin} to contain its own address.
1056Assigning a value to @code{.} is treated the same as a @code{.org}
1057directive. Thus, the expression @samp{.=.+4} is the same as saying
1058@samp{.space 4}.
1059
1060@section Symbol Attributes
1061Every symbol has the attributes discussed below. The detailed
1062definitions are in <a.out.h>.
1063
1064If you use a symbol without defining it, @code{as} assumes zero for
1065all these attributes, and probably won't warn you. This makes the
1066symbol an externally defined symbol, which is generally what you
1067would want.
1068
1069@subsection Value
1070The value of a symbol is (usually) 32 bits, the size of one C
1071@code{int}. For a symbol which labels a location in the
1072@code{text}, @code{data}, @code{bss} or @code{Absolute} segments the
1073value is the number of addresses from the start of that segment to
1074the label. Naturally for @code{text} @code{data} and @code{bss}
1075segments the value of a symbol changes as @code{ld} changes segment
1076base addresses during linking. @code{absolute} symbols' values do
1077not change during linking: that is why they are called absolute.
1078
1079The value of an undefined symbol is treated in a special way. If it
1080is 0 then the symbol is not defined in this assembler source
1081program, and @code{ld} will try to determine its value from other
1082programs it is linked with. You make this kind of symbol simply by
1083mentioning a symbol name without defining it. A non-zero value
1084represents a @code{.comm} common declaration. The value is how much
1085common storage to reserve, in bytes (@i{i.e.} addresses). The
1086symbol refers to the first address of the allocated storage.
1087
1088@subsection Type
1089The type attribute of a symbol is 8 bits encoded in a devious way.
1090We kept this coding standard for compatibility with older operating
1091systems.
1092
1093@example
1094
1095 7 6 5 4 3 2 1 0 bit numbers
1096 +-----+-----+-----+-----+-----+-----+-----+-----+
1097 | | | |
1098 | N_STAB bits | N_TYPE bits |N_EXT|
1099 | | | bit |
1100 +-----+-----+-----+-----+-----+-----+-----+-----+
1101
1102 n_type byte
1103@end example
1104
1105@subsubsection N_EXT bit
1106This bit is set if @code{ld} might need to use the symbol's value
1107and type bits. If this bit is re-set then @code{ld} can ignore the
1108symbol while linking. It is set in two cases. If the symbol is
1109undefined, then @code{ld} is expected to find the symbol's value
1110elsewhere in another program module. Otherwise the symbol has the
1111value given, but this symbol name and value are revealed to any other
1112programs linked in the same executable program. This second use of
1113the @code{N_EXT} bit is most often done by a @code{.globl} statement.
1114
1115@subsubsection N_TYPE bits
1116These establish the symbol's ``type'', which is mainly a relocation
1117concept. Common values are detailed in the manual describing the
1118executable file format.
1119
1120@subsubsection N_STAB bits
1121Common values for these bits are described in the manual on the
1122executable file format.
1123
1124@subsection Desc(riptor)
1125This is an arbitrary 16-bit value. You may establish a symbol's
1126descriptor value by using a @code{.desc} statement (@xref{Desc}.).
1127A descriptor value means nothing to @code{as}.
1128
1129@subsection Other
1130This is an arbitrary 8-bit value. It means nothing to @code{as}.
1131
1132@node Expressions, PseudoOps, Symbols, top
1133@chapter Expressions
1134An @dfn{expression} specifies an address or numeric value.
1135Whitespace may precede and/or follow an expression.
1136
1137@section Empty Expressions
1138An empty expression has no operands: it is just whitespace or null.
1139Wherever an absolute expression is required, you may omit the
1140expression and @code{as} will assume a value of (absolute) 0. This
1141is compatible with other assemblers.
1142
1143@section Integer Expressions
1144An @dfn{integer expression} is one or more @i{primaries} delimited
1145by @i{operators}.
1146
1147@node Primary, Unops, , Expressions
1148@subsection Primaries
1149@dfn{Primaries} are symbols, numbers or subexpressions. Other
1150languages might call primaries ``arithmetic operands'' but we don't
1151want them confused with ``instruction operands'' of the machine
1152language so we give them a different name.
1153
1154Symbols are evaluated to yield @{@var{segment} @var{value}@} where
1155@var{segment} is one of @b{text}, @b{data}, @b{bss}, @b{absolute},
1156or @b{undefined}. @var{value} is a signed 2's complement 32 bit
1157integer.
1158
1159Numbers are usually integers.
1160
1161A number can be a flonum or bignum. In this case, you are warned
1162that only the low order 32 bits are used, and @code{as} pretends
1163these 32 bits are an integer. You may write integer-manipulating
1164instructions that act on exotic constants, compatible with other
1165assemblers.
1166
1167Subexpressions are a left parenthesis (@t{(}) followed by an integer
1168expression followed by a right parenthesis (@t{)}), or a unary
1169operator followed by an primary.
1170
1171@subsection Operators
1172@dfn{Operators} are arithmetic marks, like @t{+} or @t{%}. Unary
1173operators are followed by an primary. Binary operators appear
1174between primaries. Operators may be preceded and/or followed by
1175whitespace.
1176
1177@subsection Unary Operators
1178@node Unops, , Primary, Expressions
1179@code{as} has the following @dfn{unary operators}. They each take
1180one primary, which must be absolute.
1181@table @t
1182@item -
1183Hyphen. @dfn{Negation}. Two's complement negation.
1184@item ~
1185Tilde. @dfn{Complementation}. Bitwise not.
1186@end table
1187
1188@subsection Binary Operators
1189@dfn{Binary operators} are infix. Operators are prioritized, but
1190equal priority operators are performed left to right. Apart from
1191@samp{+} or @samp{-}, both primaries must be absolute, and the
1192result is absolute, else one primary can be either undefined or
1193pass1 and the result is pass1.
1194@enumerate
1195@item
1196Highest Priority
1197@table @code
1198@item *
1199@dfn{Multiplication}.
1200@item /
1201@dfn{Division}. Truncation is the same as the C operator @samp{/}
1202of the compiler that compiled @code{as}.
1203@item %
1204@dfn{Remainder}.
1205@item <
1206@itemx <<
1207@dfn{Shift Left}. Same as the C operator @samp{<<} of
1208the compiler that compiled @code{as}.
1209@item >
1210@itemx >>
1211@dfn{Shift Right}. Same as the C operator @samp{>>} of
1212the compiler that compiled @code{as}.
1213@end table
1214@item
1215Intermediate priority
1216@table @t
1217@item |
1218@dfn{Bitwise Inclusive Or}.
1219@item &
1220@dfn{Bitwise And}.
1221@item ^
1222@dfn{Bitwise Exclusive Or}.
1223@item !
1224@dfn{Bitwise Or Not}.
1225@end table
1226@item
1227Lowest Priority
1228@table @t
1229@item +
1230@dfn{Addition}. If either primary is absolute, the result
1231has the segment of the other primary.
1232If either primary is pass1 or undefined, result is pass1.
1233Otherwise @t{+} is illegal.
1234@item -
1235@dfn{Subtraction}. If the right primary is absolute, the
1236result has the segment of the left primary.
1237If either primary is pass1 the result is pass1.
1238If either primary is undefined the result is difference segment.
1239If both primaries are in the same segment, the result is absolute; provided
1240that segment is one of text, data or bss.
1241Otherwise @t{-} is illegal.
1242@end table
1243@end enumerate
1244
1245The sense of the rules is that you can't add or subtract quantities
1246from two different segments. If both primaries are in one of these
1247segments, they must be in the same segment: @b{text}, @b{data} or
1248@b{bss}, and the operator must be @samp{-}.
1249
1250@node PseudoOps, MachineDependent, Expressions, top
1251@chapter Assembler Directives
1252@menu
1253* Abort:: The Abort directive causes as to abort
1254* Align:: Pad the location counter to a power of 2
1255* Ascii:: Fill memory with bytes of ASCII characters
1256* Asciz:: Fill memory with bytes of ASCII characters followed
1257 by a null.
1258* Byte:: Fill memory with 8-bit integers
1259* Comm:: Reserve public space in the BSS segment
1260* Data:: Change to the data segment
1261* Desc:: Set the n_desc of a symbol
1262* Double:: Fill memory with double-precision floating-point numbers
1263* File:: Set the logical file name
1264* Fill:: Fill memory with repeated values
1265* Float:: Fill memory with single-precision floating-point numbers
1266* Global:: Make a symbol visible to the linker
1267* Int:: Fill memory with 32-bit integers
1268* Lcomm:: Reserve private space in the BSS segment
1269* Line:: Set the logical line number
1270* Long:: Fill memory with 32-bit integers
1271* Lsym:: Create a local symbol
1272* Octa:: Fill memory with 128-bit integers
1273* Org:: Change the location counter
1274* Quad:: Fill memory with 64-bit integers
1275* Set:: Set the value of a symbol
1276* Short:: Fill memory with 16-bit integers
1277* Space:: Fill memory with a repeated value
1278* Stab:: Store debugging information
1279* Text:: Change to the text segment
1280* Word:: Fill memory with 16-bit integers
1281@end menu
1282
1283All assembler directives begin with a symbol that begins with a
1284period (@samp{.}). The rest of the symbol is letters: their case
1285does not matter.
1286
1287@node Abort, Align, PseudoOps, PseudoOps
1288@section .abort
1289This directive stops the assembly immediately. It is for
1290compatibility with other assemblers. The original idea was that the
1291assembler program would be piped into the assembler. If the source
1292of program wanted to quit, then this directive tells @code{as} to
1293quit also. One day @code{.abort} will not be supported.
1294
1295@node Align, Ascii, Abort, PseudoOps
1296@section .align @var{absolute-expression} , @var{absolute-expression}
1297Pad the location counter (in the current subsegment) to a word,
1298longword or whatever boundary. The first expression is the number
1299of low-order zero bits the location counter will have after
1300advancement. For example @samp{.align 3} will advance the location
1301counter until it a multiple of 8. If the location counter is
1302already a multiple of 8, no change is needed.
1303
1304The second expression gives the value to be stored in the padding
1305bytes. It (and the comma) may be omitted. If it is omitted, the
1306padding bytes are zeroed.
1307
1308@node Ascii, Asciz, Align, PseudoOps
1309@section .ascii @var{strings}
1310This expects zero or more string literals (@xref{Strings}.)
1311separated by commas. It assembles each string (with no automatic
1312trailing zero byte) into consecutive addresses.
1313
1314@node Asciz, Byte, Ascii, PseudoOps
1315@section .asciz @var{strings}
1316This is just like .ascii, but each string is followed by a zero byte.
1317The `z' in `.asciz' stands for `zero'.
1318
1319@node Byte, Comm, Asciz, PseudoOps
1320@section .byte @var{expressions}
1321
1322This expects zero or more expressions, separated by commas.
1323Each expression is assembled into the next byte.
1324
1325@node Comm, Data, Byte, PseudoOps
1326@section .comm @var{symbol} , @var{length}
1327This declares a named common area in the bss segment. Normally
1328@code{ld} reserves memory addresses for it during linking, so no
1329partial program defines the location of the symbol. Tell @code{ld}
1330that it must be at least @var{length} bytes long. @code{ld} will
1331allocate space that is at least as long as the longest @code{.comm}
1332request in any of the partial programs linked. @var{length} is an
1333absolute expression.
1334
1335@node Data, Desc, Comm, PseudoOps
1336@section .data @var{subsegment}
1337This tells @code{as} to assemble the following statements onto the
1338end of the data subsegment numbered @var{subsegment} (which is an
1339absolute expression). If @var{subsegment} is omitted, it defaults
1340to zero.
1341
1342@node Desc, Double, Data, PseudoOps
1343@section .desc @var{symbol}, @var{absolute-expression}
1344This sets @code{n_desc} of the symbol to the low 16 bits of
1345@var{absolute-expression}.
1346
1347@node Double, File, Desc, PseudoOps
1348@section .double @var{flonums}
1349This expects zero or more flonums, separated by commas. It assembles
1350floating point numbers. The exact kind of floating point numbers
1351emitted depends on what computer @code{as} is assembling for. See
1352the machine-specific part of the manual for the machine the
1353assembler is running on for more information.
1354
1355@node File, Fill, Double, PseudoOps
1356@section .file @var{string}
1357This tells @code{as} that we are about to start a new logical
1358file. @var{String} is the new file name. An empty file name
1359is OK, but you must still give the quotes: @code{""}. This
1360statement may go away in future: it is only recognized to
1361be compatible with old @code{as} programs.
1362
1363@node Fill, Float, File, PseudoOps
1364@section .fill @var{repeat} , @var{size} , @var{value}
1365@var{result}, @var{size} and @var{value} are absolute expressions.
1366This emits @var{repeat} copies of @var{size} bytes. @var{Repeat}
1367may be zero or more. @var{Size} may be zero or more, but if it is
1368more than 8, then it is deemed to have the value 8, compatible with
1369other people's assemblers. The contents of each @var{repeat} bytes
1370is taken from an 8-byte number. The highest order 4 bytes are
1371zero. The lowest order 4 bytes are @var{value} rendered in the
1372byte-order of an integer on the computer @code{as} is assembling for.
1373Each @var{size} bytes in a repetition is taken from the lowest order
1374@var{size} bytes of this number. Again, this bizarre behavior is
1375compatible with other people's assemblers.
1376
1377@var{Size} and @var{value} are optional.
1378If the second comma and @var{value} are absent, @var{value} is
1379assumed zero. If the first comma and following tokens are absent,
1380@var{size} is assumed to be 1.
1381
1382@node Float, Global, Fill, PseudoOps
1383@section .float @var{flonums}
1384This directive assembles zero or more flonums, separated by commas.
1385The exact kind of floating point numbers emitted depends on what
1386computer @code{as} is assembling for. See the machine-specific part
1387of the manual for the machine the assembler is running on for more
1388information.
1389
1390@node Global, Int, Float, PseudoOps
1391@section .global @var{symbol}
1392This makes the symbol visible to @code{ld}. If you define
1393@var{symbol} in your partial program, its value is made available to
1394other partial programs that are linked with it. Otherwise,
1395@var{symbol} will take its attributes from a symbol of the same name
1396from another partial program it is linked with.
1397
1398This is done by setting the @code{N_EXT} bit
1399of that symbol's @code{n_type} to 1.
1400
1401@node Int, Lcomm, Global, PseudoOps
1402@section .int @var{expressions}
1403Expect zero or more @var{expressions}, of any segment, separated by
1404commas. For each expression, emit a 32-bit number that will, at run
1405time, be the value of that expression. The byte order of the
1406expression depends on what kind of computer will run the program.
1407
1408@node Lcomm, Line, Int, PseudoOps
1409@section .lcomm @var{symbol} , @var{length}
1410Reserve @var{length} (an absolute expression) bytes for a local
1411common and denoted by @var{symbol}, whose segment and value are
1412those of the new local common. The addresses are allocated in the
1413@code{bss} segment, so at run-time the bytes will start off zeroed.
1414@var{Symbol} is not declared global (@xref{Global}.), so is normally
1415not visible to @code{ld}.
1416
1417@node Line, Long, Lcomm, PseudoOps
1418@section .line @var{logical line number}
1419This tells @code{as} to change the logical line number.
1420@var{logical line number} is an absolute expression. The next line
1421will have that logical line number. So any other statements on the
1422current line (after a @code{;}) will be reported as on logical line
1423number @var{logical line number} - 1. One day this directive will
1424be unsupported: it is used only for compatibility with existing
1425assembler programs.
1426
1427@node Long, Lsym, Line, PseudoOps
1428@section .long @var{expressions}
1429This is the same as @samp{.int}, @pxref{Int}.
1430
1431@node Lsym, Octa, Long, PseudoOps
1432@section .lsym @var{symbol}, @var{expression}
1433This creates a new symbol named @var{symbol}, but do not put it in
1434the hash table, ensuring it cannot be referenced by name during the
1435rest of the assembly. This sets the attributes of the symbol to be
1436the same as the expression value. @code{n_other} = @code{n_desc} =
14370. @code{n_type} = (whatever segment the expression has); the
1438@code{N_EXT} bit of @code{n_type} is zero. @code{n_value} =
1439(expression's value).
1440
1441@node Octa, Org, Lsym, PseudoOps
1442@section .octa @var{bignums}
1443This expects zero or more bignums, separated by commas. For each
1444bignum, it emits an 16-byte (@b{octa}-word) integer.
1445
1446@node Org, Quad, Octa, PseudoOps
1447@section .org @var{new-lc} , @var{fill}
1448This will advance the location counter of the current segment to
1449@var{new-lc}. @var{new-lc} is either an absolute expression or an
1450expression with the same segment as the current subsegment. That
1451is, you can't use @code{.org} to cross segments. Because @code{as}
1452tries to assemble programs in one pass @var{new-lc} must be defined.
1453If you really detest this restriction we eagerly await a chance to
1454share your improved assembler. To be compatible with former
1455assemblers, if the segment of @var{new-lc} is absolute then we
1456pretend the segment of @var{new-lc} is the same as the current
1457subsegment.
1458
1459Beware that the origin is relative to the start of the segment, not
1460to the start of the subsegment. This is compatible with other
1461people's assemblers.
1462
1463If the location counter (of the current subsegment) is advanced, the
1464intervening bytes are filled with @var{fill} which should be an
1465absolute expression. If the comma and @var{fill} are omitted,
1466@var{fill} defaults to zero.
1467
1468@node Quad, Set, Org, PseudoOps
1469@section .quad @var{bignums}
1470This expects zero or more bignums, separated by commas. For each
1471bignum, it emits an 8-byte (@b{quad}-word) integer. If the bignum
1472won't fit in a quad-word, it prints a warning message; and just
1473takes the lowest order 8 bytes of the bignum.
1474
1475@node Set, Short, Quad, PseudoOps
1476@section .set @var{symbol}, @var{expression}
1477
1478This sets the value of @var{symbol} to expression. This will change
1479@code{n_value} and @code{n_type} to conform to the @var{expression}.
1480if @code{n_ext} is set, it remains set.
1481
1482It is OK to @code{.set} a symbol many times in the same assembly.
1483If the expression's segment is unknowable during pass 1, a second
1484pass over the source program will be forced. The second pass is
1485currently not implemented. @code{as} will abort with an error
1486message if one is required.
1487
1488If you @code{.set} a global symbol, the value stored in the object
1489file is the last value stored into it.
1490
1491@node Short, Space, Set, PseudoOps
1492@section .short @var{expressions}
1493Except on the Sparc this is the same as @samp{.word}. @xref{Word}.
1494On the sparc, this expects zero or more @var{expressions}, and emits
1495a 16 bit number for each.
1496
1497@node Space, Stab, Short, PseudoOps
1498@section .space @var{size} , @var{fill}
1499This emits @var{size} bytes, each of value @var{fill}. Both
1500@var{size} and @var{fill} are absolute expressions. If the comma
1501and @var{fill} are omitted, @var{fill} is assumed to be zero.
1502
1503@node Stab, Text, Space, PseudoOps
1504@section .stabd, .stabn, .stabs
1505There are three directives that begin @code{.stab@dots{}}.
1506All emit symbols, for use by symbolic debuggers.
1507The symbols are not entered in @code{as}' hash table: they
1508cannot be referenced elsewhere in the source file.
1509Up to five fields are required:
1510@table @var
1511@item string
1512This is the symbol's name. It may contain any character except @samp{\000},
1513so is more general than ordinary symbol names. Some debuggers used to
1514code arbitrarily complex structures into symbol names using this technique.
1515@item type
1516An absolute expression. The symbol's @code{n_type} is set to the low 8
1517bits of this expression.
1518Any bit pattern is permitted, but @code{ld} and debuggers will choke on
1519silly bit patterns.
1520@item other
1521An absolute expression.
1522The symbol's @code{n_other} is set to the low 8 bits of this expression.
1523@item desc
1524An absolute expression.
1525The symbol's @code{n_desc} is set to the low 16 bits of this expression.
1526@item value
1527An absolute expression which becomes the symbol's @code{n_value}.
1528@end table
1529
1530If a warning is detected while reading the @code{.stab@dots{}}
1531statement the symbol has probably already been created and you will
1532get a half-formed symbol in your object file. This is compatible
1533with earlier assemblers (!)
1534
1535.stabd @var{type} , @var{other} , @var{desc}
1536
1537The ``name'' of the symbol generated is not even an empty string.
1538It is a null pointer, for compatibility. Older assemblers used a
1539null pointer so they didn't waste space in object files with empty
1540strings.
1541
1542The symbol's @code{n_value} is set to the location counter,
1543relocatably. When your program is linked, the value of this symbol
1544will be where the location counter was when the @code{.stabd} was
1545assembled.
1546
1547.stabn @var{type} , @var{other} , @var{desc} , @var{value}
1548
1549The name of the symbol is set to the empty string @code{""}.
1550
1551.stabs @var{string} , @var{type} , @var{other} , @var{desc} , @var{value}
1552
1553@node Text, Word, Stab, PseudoOps
1554@section .text @var{subsegment}
1555Tells @code{as} to assemble the following statements onto the end of
1556the text subsegment numbered @var{subsegment}, which is an absolute
1557expression. If @var{subsegment} is omitted, subsegment number zero
1558is used.
1559
1560@node Word, , Text, PseudoOps
1561@section .word @var{expressions}
1562On the Sparc, this produces 32-bit numbers instead of 16-bit ones.
1563This expect zero or more @var{expressions}, of any segment,
1564separated by commas. For each expression, emit a 16-bit number that
1565will, at run time, be the value of that expression. The byte order
1566of the expression depends on what kind of computer will run the
1567program.
1568
1569@section Deprecated Directives
1570One day these directives won't work.
1571They are included for compatibility with older assemblers.
1572@table @t
1573@item .abort
1574@item .file
1575@item .line
1576@end table
1577
1578@node MachineDependent, Maintenance, PseudoOps, top
1579@chapter Machine Dependent Features
1580@section Vax
1581@subsection Options
1582
1583The Vax version of @code{as} accepts any of the following options,
1584gives a warning message that the option was ignored and proceeds.
1585These options are for compatibility with scripts designed for other
1586people's assemblers.
1587
1588@table @asis
1589@item @kbd{-D} (Debug)
1590@itemx @kbd{-S} (Symbol Table)
1591@itemx @kbd{-T} (Token Trace)
1592These are obsolete options used to debug old assemblers.
1593
1594@item @kbd{-d} (Displacement size for JUMPs)
1595This option expects a number following the @kbd{-d}. Like options
1596that expect filenames, the number may immediately follow the
1597@kbd{-d} (old standard) or constitute the whole of the command line
1598argument that follows @kbd{-d} (GNU standard).
1599
1600@item @kbd{-V} (Virtualize Interpass Temporary File)
1601Some other assemblers use a temporary file. This option
1602commanded them to keep the information in active memory rather
1603than in a disk file. @code{as} always does this, so this
1604option is redundant.
1605
1606@item @kbd{-J} (JUMPify Longer Branches)
1607Many 32-bit computers permit a variety of branch instructions
1608to do the same job. Some of these instructions are short (and
1609fast) but have a limited range; others are long (and slow) but
1610can branch anywhere in virtual memory. Often there are 3
1611flavors of branch: short, medium and long. Some other
1612assemblers would emit short and medium branches, unless told by
1613this option to emit short and long branches.
1614
1615@item @kbd{-t} (Temporary File Directory)
1616Some other assemblers may use a temporary file, and this option
1617takes a filename being the directory to site the temporary
1618file. @code{as} does not use a temporary disk file, so this
1619option makes no difference. @kbd{-t} needs exactly one
1620filename.
1621@end table
1622
1623The Vax version of the assembler accepts two options when
1624compiled for VMS. They are @kbd{-h}, and @kbd{-+}. The
1625@kbd{-h} option prevents @code{as} from modifying the
1626symbol-table entries for symbols that contain lowercase
1627characters (I think). The @kbd{-+} option causes @code{as} to
1628print warning messages if the FILENAME part of the object file,
1629or any symbol name is larger than 31 characters. The @kbd{-+}
1630option also insertes some code following the @samp{_main}
1631symbol so that the object file will be compatable with Vax-11
1632"C".
1633
1634@subsection Floating Point
1635Conversion of flonums to floating point is correct, and
1636compatible with previous assemblers. Rounding is
1637towards zero if the remainder is exactly half the least significant bit.
1638
1639@code{D}, @code{F}, @code{G} and @code{H} floating point formats
1640are understood.
1641
1642Immediate floating literals (@i{e.g.} @samp{S`$6.9})
1643are rendered correctly. Again, rounding is towards zero in the
1644boundary case.
1645
1646The @code{.float} directive produces @code{f} format numbers.
1647The @code{.double} directive produces @code{d} format numbers.
1648
1649@subsection Machine Directives
1650The Vax version of the assembler supports four directives for
1651generating Vax floating point constants. They are described in the
1652table below.
1653
1654@table @code
1655@item .dfloat
1656This expects zero or more flonums, separated by commas, and
1657assembles Vax @code{d} format 64-bit floating point constants.
1658
1659@item .ffloat
1660This expects zero or more flonums, separated by commas, and
1661assembles Vax @code{f} format 32-bit floating point constants.
1662
1663@item .gfloat
1664This expects zero or more flonums, separated by commas, and
1665assembles Vax @code{g} format 64-bit floating point constants.
1666
1667@item .hfloat
1668This expects zero or more flonums, separated by commas, and
1669assembles Vax @code{h} format 128-bit floating point constants.
1670
1671@end table
1672
1673@subsection Opcodes
1674All DEC mnemonics are supported. Beware that @code{case@dots{}}
1675instructions have exactly 3 operands. The dispatch table that
1676follows the @code{case@dots{}} instruction should be made with
1677@code{.word} statements. This is compatible with all unix
1678assemblers we know of.
1679
1680@subsection Branch Improvement
1681Certain pseudo opcodes are permitted. They are for branch
1682instructions. They expand to the shortest branch instruction that
1683will reach the target. Generally these mnemonics are made by
1684substituting @samp{j} for @samp{b} at the start of a DEC mnemonic.
1685This feature is included both for compatibility and to help
1686compilers. If you don't need this feature, don't use these
1687opcodes. Here are the mnemonics, and the code they can expand into.
1688
1689@table @code
1690@item jbsb
1691@samp{Jsb} is already an instruction mnemonic, so we chose @samp{jbsb}.
1692@table @asis
1693@item (byte displacement)
1694@kbd{bsbb @dots{}}
1695@item (word displacement)
1696@kbd{bsbw @dots{}}
1697@item (long displacement)
1698@kbd{jsb @dots{}}
1699@end table
1700@item jbr
1701@itemx jr
1702Unconditional branch.
1703@table @asis
1704@item (byte displacement)
1705@kbd{brb @dots{}}
1706@item (word displacement)
1707@kbd{brw @dots{}}
1708@item (long displacement)
1709@kbd{jmp @dots{}}
1710@end table
1711@item j@var{COND}
1712@var{COND} may be any one of the conditional branches
1713@code{neq nequ eql eqlu gtr geq lss gtru lequ vc vs gequ cc lssu cs}.
1714@var{COND} may also be one of the bit tests
1715@code{bs bc bss bcs bsc bcc bssi bcci lbs lbc}.
1716@var{NOTCOND} is the opposite condition to @var{COND}.
1717@table @asis
1718@item (byte displacement)
1719@kbd{b@var{COND} @dots{}}
1720@item (word displacement)
1721@kbd{b@var{UNCOND} foo ; brw @dots{} ; foo:}
1722@item (long displacement)
1723@kbd{b@var{UNCOND} foo ; jmp @dots{} ; foo:}
1724@end table
1725@item jacb@var{X}
1726@var{X} may be one of @code{b d f g h l w}.
1727@table @asis
1728@item (word displacement)
1729@kbd{@var{OPCODE} @dots{}}
1730@item (long displacement)
1731@kbd{@var{OPCODE} @dots{}, foo ; brb bar ; foo: jmp @dots{} ; bar:}
1732@end table
1733@item jaob@var{YYY}
1734@var{YYY} may be one of @code{lss leq}.
1735@item jsob@var{ZZZ}
1736@var{ZZZ} may be one of @code{geq gtr}.
1737@table @asis
1738@item (byte displacement)
1739@kbd{@var{OPCODE} @dots{}}
1740@item (word displacement)
1741@kbd{@var{OPCODE} @dots{}, foo ; brb bar ; foo: brw @var{destination} ; bar:}
1742@item (long displacement)
1743@kbd{@var{OPCODE} @dots{}, foo ; brb bar ; foo: jmp @var{destination} ; bar: }
1744@end table
1745@item aobleq
1746@itemx aoblss
1747@itemx sobgeq
1748@itemx sobgtr
1749@table @asis
1750@item (byte displacement)
1751@kbd{@var{OPCODE} @dots{}}
1752@item (word displacement)
1753@kbd{@var{OPCODE} @dots{}, foo ; brb bar ; foo: brw @var{destination} ; bar:}
1754@item (long displacement)
1755@kbd{@var{OPCODE} @dots{}, foo ; brb bar ; foo: jmp @var{destination} ; bar:}
1756@end table
1757@end table
1758
1759@subsection operands
1760The immediate character is @samp{$} for Unix compatibility, not
1761@samp{#} as DEC writes it.
1762
1763The indirect character is @samp{*} for Unix compatibility, not
1764@samp{@@} as DEC writes it.
1765
1766The displacement sizing character is @samp{`} (an accent grave) for
1767Unix compatibility, not @samp{^} as DEC writes it. The letter
1768preceding @samp{`} may have either case. @samp{G} is not
1769understood, but all other letters (@code{b i l s w}) are understood.
1770
1771Register names understood are @code{r0 r1 r2 @dots{} r15 ap fp sp
1772pc}. Any case of letters will do.
1773
1774For instance
1775@example
1776tstb *w`$4(r5)
1777@end example
1778
1779Any expression is permitted in an operand. Operands are comma
1780separated.
1781
1782@c There is some bug to do with recognizing expressions
1783@c in operands, but I forget what it is. It is
1784@c a syntax clash because () is used as an address mode
1785@c and to encapsulate sub-expressions.
1786@subsection Not Supported
1787Vax bit fields can not be assembled with @code{as}. Someone
1788can add the required code if they really need it.
1789
1790@section 680x0
1791@subsection Options
1792The 680x0 version of @code{as} has two machine dependent options.
1793One shortens undefined references from 32 to 16 bits, while the
1794other is used to tell @code{as} what kind of machine it is
1795assembling for.
1796
1797You can use the @kbd{-l} option to shorten the size of references to
1798undefined symbols. If the @kbd{-l} option is not given, references
1799to undefined symbols will be a full long (32 bits) wide. (Since
1800@code{as} cannot know where these symbols will end up being,
1801@code{as} can only allocate space for the linker to fill in later.
1802Since @code{as} doesn't know how far away these symbols will be, it
1803allocates as much space as it can.) If this option is given, the
1804references will only be one word wide (16 bits). This may be useful
1805if you want the object file to be as small as possible, and you know
1806that the relevant symbols will be less than 17 bits away.
1807
1808The 680x0 version of @code{as} is usually used to assemble programs
1809for the Motorola MC68020 microprocessor. Occasionally it is used to
1810assemble programs for the mostly-similar-but-slightly-different
1811MC68000 or MC68010 microprocessors. You can give @code{as} the
1812options @samp{-m68000}, @samp{-mc68000}, @samp{-m68010},
1813@samp{-mc68010}, @samp{-m68020}, and @samp{-mc68020} to tell it what
1814processor it should be assembling for. Unfortunately, these options
1815are almost entirely unused and untried. They make work, but nobody
1816has tested them much.
1817
1818@subsection Syntax
1819
1820The 680x0 version of @code{as} uses syntax similar to the Sun
1821assembler. Size modifieres are appended directly to the end of the
1822opcode without an intervening period. Thus, @samp{move.l} is
1823written @samp{movl}, etc.
1824
1825@c This is no longer true
1826@c Explicit size modifiers for branch instructions are ignored; @code{as}
1827@c automatically picks the smallest size that will reach the
1828destination.
1829
1830If @code{as} is compiled with SUN_ASM_SYNTAX defined, it will also
1831allow Sun-style local labels of the form @samp{1$} through @samp{$9}.
1832
1833In the following table @dfn{apc} stands for any of the address
1834registers (@samp{a0} through @samp{a7}), nothing, (@samp{}), the
1835Program Counter (@samp{pc}), or the zero-address relative to the
1836program counter (@samp{zpc}).
1837
1838The following addressing modes are understood:
1839@table @dfn
1840@item Immediate
1841@samp{#@var{digits}}
1842
1843@item Data Register
1844@samp{d0} through @samp{d7}
1845
1846@item Address Register
1847@samp{a0} through @samp{a7}
1848
1849@item Address Register Indirect
1850@samp{a0@@} through @samp{a7@@}
1851
1852@item Address Register Postincrement
1853@samp{a0@@+} through @samp{a7@@+}
1854
1855@item Address Register Predecrement
1856@samp{a0@@-} through @samp{a7@@-}
1857
1858@item Indirect Plus Offset
1859@samp{@var{apc}@@(@var{digits})}
1860
1861@item Index
1862@samp{@var{apc}@@(@var{digits},@var{register}:@var{size}:@var{scale})}
1863or @samp{@var{apc}@@(@var{register}:@var{size}:@var{scale})}
1864
1865@item Postindex
1866@samp{@var{apc}@@(@var{digits})@@(@var{digits},@var{register}:@var{size}:@var{scale})}
1867or @samp{@var{apc}@@(@var{digits})@@(@var{register}:@var{size}:@var{scale})}
1868
1869@item Preindex
1870@samp{@var{apc}@@(@var{digits},@var{register}:@var{size}:@var{scale})@@(@var{digits})}
1871or @samp{@var{apc}@@(@var{register}:@var{size}:@var{scale})@@(@var{digits})}
1872
1873@item Memory Indirect
1874@samp{@var{apc}@@(@var{digits})@@(@var{digits})}
1875
1876@item Absolute
1877@samp{@var{symbol}}, or @samp{@var{digits}}, or either of the above followed
1878by @samp{:b}, @samp{:w}, or @samp{:l}.
1879@end table
1880
1881@subsection Floating Point
1882The floating point code is not too well tested, and may have
1883subtle bugs in it.
1884
1885Packed decimal (P) format floating literals are not supported.
1886Feel free to add the code yourself.
1887
1888The floating point formats generated by directives are these.
1889@table @code
1890@item .float
1891@code{Single} precision floating point constants.
1892@item .double
1893@code{Double} precision floating point constants.
1894@end table
1895
1896There is no directive to produce regions of memory holding
1897extended precision numbers, however they can be used as
1898immediate operands to floating-point instructions. Adding a
1899directive to create extended precision numbers would not be
1900hard. Nobody has felt any burning need to do it.
1901
1902@subsection Machine Directives
1903In order to be compatible with the Sun assembler the 680x0 assembler
1904understands the following directives.
1905@table @code
1906@item .data1
1907This directive is identical to a @code{.data 1} directive.
1908@item .data2
1909This directive is identical to a @code{.data 2} directive.
1910@item .even
1911This directive is identical to a @code{.align 1} directive.
1912@c Is this true? does it work???
1913@item .skip
1914This directive is identical to a @code{.space} directive.
1915@end table
1916
1917@subsection Opcodes
1918Danger: Several bugs have been found in the opcode table (and
1919fixed). More bugs may exist. Be careful when using obscure
1920instructions.
1921
1922The assembler automatically chooses the proper size for branch
1923instructions. However, most attempts to force a short displacement
1924will be honored. Branches that are forced to use a short
1925displacement will not be adjusted if the target is out of range.
1926Let The User Beware.
1927
1928The immediate character is @samp{#} for Sun compatibility. The
1929line-comment character is @samp{|}. If a @samp{#} appears at the
1930beginning of a line, it is treated as a comment unless it looks like
1931@samp{# line file}, in which case it is treated normally.
1932
1933@section 32x32
1934@subsection Options
1935The 32x32 version of @code{as} accepts a @kbd{-m32032} option to
1936specify thiat it is compiling for a 32032 processor, or a
1937@kbd{-m32532} to specify that it is compiling for a 32532 option.
1938The default (if neither is specified) is chosen when the assembler
1939is compiled.
1940
1941@subsection Syntax
1942I don't know anything about the 32x32 syntax assembled by
1943@code{as}. Someone who undersands the processor (I've never seen
1944one) and the possible syntaxes should write this section.
1945
1946@subsection Floating Point
1947The 32x32 uses IEEE floating point numbers, but @code{as} will only
1948create single or double precision values. I don't know if the 32x32
1949understands extended precision numbers.
1950
1951@subsection Machine Directives
1952The 32x32 has no machine dependent directives.
1953
1954@section Sparc
1955@subsection Options
1956The sparc has no machine dependent options.
1957
1958@subsection syntax
1959I don't know anything about Sparc syntax. Someone who does
1960will have to write this section.
1961
1962@subsection Floating Point
1963The Sparc uses ieee floating-point numbers.
1964
1965@subsection Machine Directives
1966The Sparc version of @code{as} supports the following additional
1967machine directives:
1968
1969@table @code
1970@item .common
1971This must be followed by a symbol name, a positive number, and
1972@code{"bss"}. This behaves somewhat like @code{.comm}, but the
1973syntax is different.
1974
1975@item .global
1976This is functionally identical to @code{.globl}.
1977
1978@item .half
1979This is functionally identical to @code{.short}.
1980
1981@item .proc
1982This directive is ignored. Any text following it on the same
1983line is also ignored.
1984
1985@item .reserve
1986This must be followed by a symbol name, a positive number, and
1987@code{"bss"}. This behaves somewhat like @code{.lcomm}, but the
1988syntax is different.
1989
1990@item .seg
1991This must be followed by @code{"text"}, @code{"data"}, or
1992@code{"data1"}. It behaves like @code{.text}, @code{.data}, or
1993@code{.data 1}.
1994
1995@item .skip
1996This is functionally identical to the .space directive.
1997
1998@item .word
1999On the Sparc, the .word directive produces 32 bit values,
2000instead of the 16 bit values it produces on every other machine.
2001
2002@end table
2003
2004@section Intel 80386
2005@subsection Options
2006The 80386 has no machine dependent options.
2007
2008@subsection AT&T Syntax versus Intel Syntax
2009In order to maintain compatibility with the output of @code{GCC},
2010@code{as} supports AT&T System V/386 assembler syntax. This is quite
2011different from Intel syntax. We mention these differences because
2012almost all 80386 documents used only Intel syntax. Notable differences
2013between the two syntaxes are:
2014@itemize @bullet
2015@item
2016AT&T immediate operands are preceded by @samp{$}; Intel immediate
2017operands are undelimited (Intel @samp{push 4} is AT&T @samp{pushl $4}).
2018AT&T register operands are preceded by @samp{%}; Intel register operands
2019are undelimited. AT&T absolute (as opposed to PC relative) jump/call
2020operands are prefixed by @samp{*}; they are undelimited in Intel syntax.
2021
2022@item
2023AT&T and Intel syntax use the opposite order for source and destination
2024operands. Intel @samp{add eax, 4} is @samp{addl $4, %eax}. The
2025@samp{source, dest} convention is maintained for compatibility with
2026previous Unix assemblers.
2027
2028@item
2029In AT&T syntax the size of memory operands is determined from the last
2030character of the opcode name. Opcode suffixes of @samp{b}, @samp{w},
2031and @samp{l} specify byte (8-bit), word (16-bit), and long (32-bit)
2032memory references. Intel syntax accomplishes this by prefixes memory
2033operands (@emph{not} the opcodes themselves) with @samp{byte ptr},
2034@samp{word ptr}, and @samp{dword ptr}. Thus, Intel @samp{mov al, byte
2035ptr @var{foo}} is @samp{movb @var{foo}, %al} in AT&T syntax.
2036
2037@item
2038Immediate form long jumps and calls are
2039@samp{lcall/ljmp $@var{segment}, $@var{offset}} in AT&T syntax; the
2040Intel syntax is
2041@samp{call/jmp far @var{segment}:@var{offset}}. Also, the far return
2042instruction
2043is @samp{lret $@var{stack-adjust}} in AT&T syntax; Intel syntax is
2044@samp{ret far @var{stack-adjust}}.
2045
2046@item
2047The AT&T assembler does not provide support for multiple segment
2048programs. Unix style systems expect all programs to be single segments.
2049@end itemize
2050
2051@subsection Opcode Naming
2052Opcode names are suffixed with one character modifiers which specify the
2053size of operands. The letters @samp{b}, @samp{w}, and @samp{l} specify
2054byte, word, and long operands. If no suffix is specified by an
2055instruction and it contains no memory operands then @code{as} tries to
2056fill in the missing suffix based on the destination register operand
2057(the last one by convention). Thus, @samp{mov %ax, %bx} is equivalent
2058to @samp{movw %ax, %bx}; also, @samp{mov $1, %bx} is equivalent to
2059@samp{movw $1, %bx}. Note that this is incompatible with the AT&T Unix
2060assembler which assumes that a missing opcode suffix implies long
2061operand size. (This incompatibility does not affect compiler output
2062since compilers always explicitly specify the opcode suffix.)
2063
2064Almost all opcodes have the same names in AT&T and Intel format. There
2065are a few exceptions. The sign extend and zero extend instructions need
2066two sizes to specify them. They need a size to sign/zero extend
2067@emph{from} and a size to zero extend @emph{to}. This is accomplished
2068by using two opcode suffixes in AT&T syntax. Base names for sign extend
2069and zero extend are @samp{movs@dots{}} and @samp{movz@dots{}} in AT&T
2070syntax (@samp{movsx} and @samp{movzx} in Intel syntax). The opcode
2071suffixes are tacked on to this base name, the @emph{from} suffix before
2072the @emph{to} suffix. Thus, @samp{movsbl %al, %edx} is AT&T syntax for
2073``move sign extend @emph{from} %al @emph{to} %edx.'' Possible suffixes,
2074thus, are @samp{bl} (from byte to long), @samp{bw} (from byte to word),
2075and @samp{wl} (from word to long).
2076
2077The Intel syntax conversion instructions
2078@itemize @bullet
2079@item
2080@samp{cbw} --- sign-extend byte in @samp{%al} to word in @samp{%ax},
2081@item
2082@samp{cwde} --- sign-extend word in @samp{%ax} to long in @samp{%eax},
2083@item
2084@samp{cwd} --- sign-extend word in @samp{%ax} to long in @samp{%dx:%ax},
2085@item
2086@samp{cdq} --- sign-extend dword in @samp{%eax} to quad in @samp{%edx:%eax},
2087@end itemize
2088are called @samp{cbtw}, @samp{cwtl}, @samp{cwtd}, and @samp{cltd} in
2089AT&T naming. @code{as} accepts either naming for these instructions.
2090
2091Far call/jump instructions are @samp{lcall} and @samp{ljmp} in
2092AT&T syntax, but are @samp{call far} and @samp{jump far} in Intel
2093convention.
2094
2095@subsection Register Naming
2096Register operands are always prefixes with @samp{%}. The 80386 registers
2097consist of
2098@itemize @bullet
2099@item
2100the 8 32-bit registers @samp{%eax} (the accumulator), @samp{%ebx},
2101@samp{%ecx}, @samp{%edx}, @samp{%edi}, @samp{%esi}, @samp{%ebp} (the
2102frame pointer), and @samp{%esp} (the stack pointer).
2103
2104@item
2105the 8 16-bit low-ends of these: @samp{%ax}, @samp{%bx}, @samp{%cx},
2106@samp{%dx}, @samp{%di}, @samp{%si}, @samp{%bp}, and @samp{%sp}.
2107
2108@item
2109the 8 8-bit registers: @samp{%ah}, @samp{%al}, @samp{%bh},
2110@samp{%bl}, @samp{%ch}, @samp{%cl}, @samp{%dh}, and @samp{%dl} (These
2111are the high-bytes and low-bytes of @samp{%ax}, @samp{%bx},
2112@samp{%cx}, and @samp{%dx})
2113
2114@item
2115the 6 segment registers @samp{%cs} (code segment), @samp{%ds}
2116(data segment), @samp{%ss} (stack segment), @samp{%es}, @samp{%fs},
2117and @samp{%gs}.
2118
2119@item
2120the 3 processor control registers @samp{%cr0}, @samp{%cr2}, and
2121@samp{%cr3}.
2122
2123@item
2124the 6 debug registers @samp{%db0}, @samp{%db1}, @samp{%db2},
2125@samp{%db3}, @samp{%db6}, and @samp{%db7}.
2126
2127@item
2128the 2 test registers @samp{%tr6} and @samp{%tr7}.
2129
2130@item
2131the 8 floating point register stack @samp{%st} or equivalently
2132@samp{%st(0)}, @samp{%st(1)}, @samp{%st(2)}, @samp{%st(3)},
2133@samp{%st(4)}, @samp{%st(5)}, @samp{%st(6)}, and @samp{%st(7)}.
2134@end itemize
2135
2136@subsection Opcode Prefixes
2137Opcode prefixes are used to modify the following opcode. They are used
2138to repeat string instructions, to provide segment overrides, to perform
2139bus lock operations, and to give operand and address size (16-bit
2140operands are specified in an instruction by prefixing what would
2141normally be 32-bit operands with a ``operand size'' opcode prefix).
2142Opcode prefixes are usually given as single-line instructions with no
2143operands, and must directly precede the instruction they act upon. For
2144example, the @samp{scas} (scan string) instruction is repeated with:
2145@example
2146 repne
2147 scas
2148@end example
2149
2150Here is a list of opcode prefixes:
2151@itemize @bullet
2152@item
2153Segment override prefixes @samp{cs}, @samp{ds}, @samp{ss}, @samp{es},
2154@samp{fs}, @samp{gs}. These are automatically added by specifying
2155using the @var{segment}:@var{memory-operand} form for memory references.
2156
2157@item
2158Operand/Address size prefixes @samp{data16} and @samp{addr16}
2159change 32-bit operands/addresses into 16-bit operands/addresses. Note
2160that 16-bit addressing modes (i.e. 8086 and 80286 addressing modes)
2161are not supported (yet).
2162
2163@item
2164The bus lock prefix @samp{lock} inhibits interrupts during
2165execution of the instruction it precedes. (This is only valid with
2166certain instructions; see a 80386 manual for details).
2167
2168@item
2169The wait for coprocessor prefix @samp{wait} waits for the
2170coprocessor to complete the current instruction. This should never be
2171needed for the 80386/80387 combination.
2172
2173@item
2174The @samp{rep}, @samp{repe}, and @samp{repne} prefixes are added
2175to string instructions to make them repeat @samp{%ecx} times.
2176@end itemize
2177
2178@subsection Memory References
2179An Intel syntax indirect memory reference of the form
2180@example
2181@var{segment}:[@var{base} + @var{index}*@var{scale} + @var{disp}]
2182@end example
2183is translated into the AT&T syntax
2184@example
2185@var{segment}:@var{disp}(@var{base}, @var{index}, @var{scale})
2186@end example
2187where @var{base} and @var{index} are the optional 32-bit base and
2188index registers, @var{disp} is the optional displacement, and
2189@var{scale}, taking the values 1, 2, 4, and 8, multiplies @var{index}
2190to calculate the address of the operand. If no @var{scale} is
2191specified, @var{scale} is taken to be 1. @var{segment} specifies the
2192optional segment register for the memory operand, and may override the
2193default segment register (see a 80386 manual for segment register
2194defaults). Note that segment overrides in AT&T syntax @emph{must} have
2195be preceded by a @samp{%}. If you specify a segment override which
2196coincides with the default segment register, @code{as} will @emph{not}
2197output any segment register override prefixes to assemble the given
2198instruction. Thus, segment overrides can be specified to emphasize which
2199segment register is used for a given memory operand.
2200
2201Here are some examples of Intel and AT&T style memory references:
2202@table @asis
2203
2204@item AT&T: @samp{-4(%ebp)}, Intel: @samp{[ebp - 4]}
2205@var{base} is @samp{%ebp}; @var{disp} is @samp{-4}. @var{segment} is
2206missing, and the default segment is used (@samp{%ss} for addressing with
2207@samp{%ebp} as the base register). @var{index}, @var{scale} are both missing.
2208
2209@item AT&T: @samp{foo(,%eax,4)}, Intel: @samp{[foo + eax*4]}
2210@var{index} is @samp{%eax} (scaled by a @var{scale} 4); @var{disp} is
2211@samp{foo}. All other fields are missing. The segment register here
2212defaults to @samp{%ds}.
2213
2214@item AT&T: @samp{foo(,1)}; Intel @samp{[foo]}
2215This uses the value pointed to by @samp{foo} as a memory operand.
2216Note that @var{base} and @var{index} are both missing, but there is only
2217@emph{one} @samp{,}. This is a syntactic exception.
2218
2219@item AT&T: @samp{%gs:foo}; Intel @samp{gs:foo}
2220This selects the contents of the variable @samp{foo} with segment
2221register @var{segment} being @samp{%gs}.
2222
2223@end table
2224
2225Absolute (as opposed to PC relative) call and jump operands must be
2226prefixed with @samp{*}. If no @samp{*} is specified, @code{as} will
2227always choose PC relative addressing for jump/call labels.
2228
2229Any instruction that has a memory operand @emph{must} specify its size (byte,
2230word, or long) with an opcode suffix (@samp{b}, @samp{w}, or @samp{l},
2231respectively).
2232
2233@subsection Handling of Jump Instructions
2234Jump instructions are always optimized to use the smallest possible
2235displacements. This is accomplished by using byte (8-bit) displacement
2236jumps whenever the target is sufficiently close. If a byte displacement
2237is insufficient a long (32-bit) displacement is used. We do not support
2238word (16-bit) displacement jumps (i.e. prefixing the jump instruction
2239with the @samp{addr16} opcode prefix), since the 80386 insists upon masking
2240@samp{%eip} to 16 bits after the word displacement is added.
2241
2242Note that the @samp{jcxz}, @samp{jecxz}, @samp{loop}, @samp{loopz},
2243@samp{loope}, @samp{loopnz} and @samp{loopne} instructions only come in
2244byte displacements, so that it is possible that use of these
2245instructions (@code{GCC} does not use them) will cause the assembler to
2246print an error message (and generate incorrect code). The AT&T 80386
2247assembler tries to get around this problem by expanding @samp{jcxz foo} to
2248@example
2249 jcxz cx_zero
2250 jmp cx_nonzero
2251cx_zero: jmp foo
2252cx_nonzero:
2253@end example
2254
2255@subsection Floating Point
2256All 80387 floating point types except packed BCD are supported.
2257(BCD support may be added without much difficulty). These data
2258types are 16-, 32-, and 64- bit integers, and single (32-bit),
2259double (64-bit), and extended (80-bit) precision floating point.
2260Each supported type has an opcode suffix and a constructor
2261associated with it. Opcode suffixes specify operand's data
2262types. Constructors build these data types into memory.
2263
2264@itemize @bullet
2265@item
2266Floating point constructors are @samp{.float} or @samp{.single},
2267@samp{.double}, and @samp{.tfloat} for 32-, 64-, and 80-bit formats.
2268These correspond to opcode suffixes @samp{s}, @samp{l}, and @samp{t}.
2269@samp{t} stands for temporary real, and that the 80387 only supports
2270this format via the @samp{fldt} (load temporary real to stack top) and
2271@samp{fstpt} (store temporary real and pop stack) instructions.
2272
2273@item
2274Integer constructors are @samp{.word}, @samp{.long} or @samp{.int}, and
2275@samp{.quad} for the 16-, 32-, and 64-bit integer formats. The corresponding
2276opcode suffixes are @samp{s} (single), @samp{l} (long), and @samp{q}
2277(quad). As with the temporary real format the 64-bit @samp{q} format is
2278only present in the @samp{fildq} (load quad integer to stack top) and
2279@samp{fistpq} (store quad integer and pop stack) instructions.
2280@end itemize
2281
2282Register to register operations do not require opcode suffixes,
2283so that @samp{fst %st, %st(1)} is equivalent to @samp{fstl %st, %st(1)}.
2284
2285Since the 80387 automatically synchronizes with the 80386 @samp{fwait}
2286instructions are almost never needed (this is not the case for the
228780286/80287 and 8086/8087 combinations). Therefore, @code{as} supresses
2288the @samp{fwait} instruction whenever it is implicitly selected by one
2289of the @samp{fn@dots{}} instructions. For example, @samp{fsave} and
2290@samp{fnsave} are treated identically. In general, all the @samp{fn@dots{}}
2291instructions are made equivalent to @samp{f@dots{}} instructions. If
2292@samp{fwait} is desired it must be explicitly coded.
2293
2294@subsection Notes
2295There is some trickery concerning the @samp{mul} and @samp{imul}
2296instructions that deserves mention. The 16-, 32-, and 64-bit expanding
2297multiplies (base opcode @samp{0xf6}; extension 4 for @samp{mul} and 5
2298for @samp{imul}) can be output only in the one operand form. Thus,
2299@samp{imul %ebx, %eax} does @emph{not} select the expanding multiply;
2300the expanding multiply would clobber the @samp{%edx} register, and this
2301would confuse @code{GCC} output. Use @samp{imul %ebx} to get the
230264-bit product in @samp{%edx:%eax}.
2303
2304We have added a two operand form of @samp{imul} when the first operand
2305is an immediate mode expression and the second operand is a register.
2306This is just a shorthand, so that, multiplying @samp{%eax} by 69, for
2307example, can be done with @samp{imul $69, %eax} rather than @samp{imul
2308$69, %eax, %eax}.
2309
2310@node Maintenance, Retargeting, MachineDependent, top
2311@chapter Maintaining the Assembler
2312[[this chapter is still being built]]
2313
2314@section Design
2315We had these goals, in descending priority:
2316@table @b
2317@item Accuracy.
2318For every program composed by a compiler, @code{as} should emit
2319``correct'' code. This leaves some latitude in choosing addressing
2320modes, order of @code{relocation_info} structures in the object
2321file, @i{etc}.
2322
2323@item Speed, for usual case.
2324By far the most common use of @code{as} will be assembling compiler
2325emissions.
2326
2327@item Upward compatibility for existing assembler code.
2328Well @dots{} we don't support Vax bit fields but everything else
2329seems to be upward compatible.
2330
2331@item Readability.
2332The code should be maintainable with few surprises. (JF: ha!)
2333
2334@end table
2335
2336We assumed that disk I/O was slow and expensive while memory was
2337fast and access to memory was cheap. We expect the in-memory data
2338structures to be less than 10 times the size of the emitted object
2339file. (Contrast this with the C compiler where in-memory structures
2340might be 100 times object file size!)
2341This suggests:
2342@itemize @bullet
2343@item
2344Try to read the source file from disk only one time. For other
2345reasons, we keep large chunks of the source file in memory during
2346assembly so this is not a problem. Also the assembly algorithm
2347should only scan the source text once if the compiler composed the
2348text according to a few simple rules.
2349@item
2350Emit the object code bytes only once. Don't store values and then
2351backpatch later.
2352@item
2353Build the object file in memory and do direct writes to disk of
2354large buffers.
2355@end itemize
2356
2357RMS suggested a one-pass algorithm which seems to work well. By not
2358parsing text during a second pass considerable time is saved on
2359large programs (@i{e.g.} the sort of C program @code{yacc} would
2360emit).
2361
2362It happened that the data structures needed to emit relocation
2363information to the object file were neatly subsumed into the data
2364structures that do backpatching of addresses after pass 1.
2365
2366Many of the functions began life as re-usable modules, loosely
2367connected. RMS changed this to gain speed. For example, input
2368parsing routines which used to work on pre-sanitized strings now
2369must parse raw data. Hence they have to import knowledge of the
2370assemblers' comment conventions @i{etc}.
2371
2372@section Deprecated Feature(?)s
2373We have stopped supporting some features:
2374@itemize @bullet
2375@item
2376@code{.org} statements must have @b{defined} expressions.
2377@item
2378Vax Bit fields (@kbd{:} operator) are entirely unsupported.
2379@end itemize
2380
2381It might be a good idea to not support these features in a future release:
2382@itemize @bullet
2383@item
2384@kbd{#} should begin a comment, even in column 1.
2385@item
2386Why support the logical line & file concept any more?
2387@item
2388Subsegments are a good candidate for flushing.
2389Depends on which compilers need them I guess.
2390@end itemize
2391
2392@section Bugs, Ideas, Further Work
2393Clearly the major improvement is DON'T USE A TEXT-READING
2394ASSEMBLER for the back end of a compiler. It is much faster to
2395interpret binary gobbledygook from a compiler's tables than to
2396ask the compiler to write out human-readable code just so the
2397assembler can parse it back to binary.
2398
2399Assuming you use @code{as} for human written programs: here are
2400some ideas:
2401@itemize @bullet
2402@item
2403Document (here) @code{APP}.
2404@item
2405Take advantage of knowing no spaces except after opcode
2406to speed up @code{as}. (Modify @code{app.c} to flush useless spaces:
2407only keep space/tabs at begin of line or between 2
2408symbols.)
2409@item
2410Put pointers in this documentation to @file{a.out} documentation.
2411@item
2412Split the assembler into parts so it can gobble direct binary
2413from @i{e.g.} @code{cc}. It is silly for@code{cc} to compose text
2414just so @code{as} can parse it back to binary.
2415@item
2416Rewrite hash functions: I want a more modular, faster library.
2417@item
2418Clean up LOTS of code.
2419@item
2420Include all the non-@file{.c} files in the maintenance chapter.
2421@item
2422Document flonums.
2423@item
2424Implement flonum short literals.
2425@item
2426Change all talk of expression operands to expression quantities,
2427or perhaps to expression primaries.
2428@item
2429Implement pass 2.
2430@item
2431Whenever a @code{.text} or @code{.data} statement is seen, we close
2432of the current frag with an imaginary @code{.fill 0}. This is
2433because we only have one obstack for frags, and we can't grow new
2434frags for a new subsegment, then go back to the old subsegment and
2435append bytes to the old frag. All this nonsense goes away if we
2436give each subsegment its own obstack. It makes code simpler in
2437about 10 places, but nobody has bothered to do it because C compiler
2438output rarely changes subsegments (compared to ending frags with
2439relaxable addresses, which is common).
2440@end itemize
2441
2442@section Sources
2443@c The following files in the @file{as} directory
2444@c are symbolic links to other files, of
2445@c the same name, in a different directory.
2446@c @itemize @bullet
2447@c @item
2448@c @file{atof_generic.c}
2449@c @item
2450@c @file{atof_vax.c}
2451@c @item
2452@c @file{flonum_const.c}
2453@c @item
2454@c @file{flonum_copy.c}
2455@c @item
2456@c @file{flonum_get.c}
2457@c @item
2458@c @file{flonum_multip.c}
2459@c @item
2460@c @file{flonum_normal.c}
2461@c @item
2462@c @file{flonum_print.c}
2463@c @end itemize
2464
2465Here is a list of the source files in the @file{as} directory.
2466
2467@table @file
2468@item app.c
2469This contains the pre-processing phase, which deletes comments,
2470handles whitespace, etc. This was recently re-written, since app
2471used to be a separate program, but RMS wanted it to be inline.
2472
2473@item append.c
2474This is a subroutine to append a string to another string returning a
2475pointer just after the last @code{char} appended. (JF: All these
2476little routines should probably all be put in one file.)
2477
2478@item as.c
2479Here you will find the main program of the assembler @code{as}.
2480
2481@item expr.c
2482This is a branch office of @file{read.c}. This understands
2483expressions, primaries. Inside @code{as}, primaries are called
2484(expression) @i{operands}. This is confusing, because we also talk
2485(elsewhere) about instruction @i{operands}. Also, expression
2486operands are called @i{quantities} explicitly to avoid confusion
2487with instruction operands. What a mess.
2488
2489@item frags.c
2490This implements the @b{frag} concept. Without frags, finding the
2491right size for branch instructions would be a lot harder.
2492
2493@item hash.c
2494This contains the symbol table, opcode table @i{etc.} hashing
2495functions.
2496
2497@item hex_value.c
2498This is a table of values of digits, for use in atoi() type
2499functions. Could probably be flushed by using calls to strtol(), or
2500something similar.
2501
2502@item input-file.c
2503This contains Operating system dependent source file reading
2504routines. Since error messages often say where we are in reading
2505the source file, they live here too. Since @code{as} is intended to
2506run under GNU and Unix only, this might be worth flushing. Anyway,
2507almost all C compilers support stdio.
2508
2509@item input-scrub.c
2510This deals with calling the pre-processor (if needed) and feeding the
2511chunks back to the rest of the assembler the right way.
2512
2513@item messages.c
2514This contains operating system independent parts of fatal and
2515warning message reporting. See @file{append.c} above.
2516
2517@item output-file.c
2518This contains operating system dependent functions that write an
2519object file for @code{as}. See @file{input-file.c} above.
2520
2521@item read.c
2522This implements all the directives of @code{as}. This also deals
2523with passing input lines to the machine dependent part of the
2524assembler.
2525
2526@item strstr.c
2527This is a C library function that isn't in most C libraries yet.
2528See @file{append.c} above.
2529
2530@item subsegs.c
2531This implements subsegments.
2532
2533@item symbols.c
2534This implements symbols.
2535
2536@item write.c
2537This contains the code to perform relaxation, and to write out
2538the object file. It is mostly operating system independent, but
2539different OSes have different object file formats in any case.
2540
2541@item xmalloc.c
2542This implements @code{malloc()} or bust. See @file{append.c} above.
2543
2544@item xrealloc.c
2545This implements @code{realloc()} or bust. See @file{append.c} above.
2546
2547@item atof-generic.c
2548The following files were taken from a machine-independent subroutine
2549library for manipulating floating point numbers and very large
2550integers.
2551
2552@file{atof-generic.c} turns a string into a flonum internal format
2553floating-point number.
2554
2555@item flonum-const.c
2556This contains some potentially useful floating point numbers in
2557flonum format.
2558
2559@item flonum-copy.c
2560This copies a flonum.
2561
2562@item flonum-multip.c
2563This multiplies two flonums together.
2564
2565@item bignum-copy.c
2566This copies a bignum.
2567
2568@end table
2569
2570Here is a table of all the machine-specific files (this includes
2571both source and header files). Typically, there is a
2572@var{machine}.c file, a @var{machine}-opcode.h file, and an
2573atof-@var{machine}.c file. The @var{machine}-opcode.h file should
2574be identical to the one used by GDB (which uses it for disassembly.)
2575
2576@table @file
2577
2578@item atof-ieee.c
2579This contains code to turn a flonum into a ieee literal constant.
2580This is used by tye 680x0, 32x32, sparc, and i386 versions of @code{as}.
2581
2582@item i386-opcode.h
2583This is the opcode-table for the i386 version of the assembler.
2584
2585@item i386.c
2586This contains all the code for the i386 version of the assembler.
2587
2588@item i386.h
2589This defines constants and macros used by the i386 version of the assembler.
2590
2591@item m-generic.h
2592generic 68020 header file. To be linked to m68k.h on a
2593non-sun3, non-hpux system.
2594
2595@item m-sun2.h
259668010 header file for Sun2 workstations. Not well tested. To be linked
2597to m68k.h on a sun2. (See also @samp{-DSUN_ASM_SYNTAX} in the
2598@file{Makefile}.)
2599
2600@item m-sun3.h
260168020 header file for Sun3 workstations. To be linked to m68k.h before
2602compiling on a Sun3 system. (See also @samp{-DSUN_ASM_SYNTAX} in the
2603@file{Makefile}.)
2604
2605@item m-hpux.h
260668020 header file for a HPUX (system 5?) box. Which box, which
2607version of HPUX, etc? I don't know.
2608
2609@item m68k.h
2610A hard- or symbolic- link to one of @file{m-generic.h},
2611@file{m-hpux.h} or @file{m-sun3.h} depending on which kind of
2612680x0 you are assembling for. (See also @samp{-DSUN_ASM_SYNTAX} in the
2613@file{Makefile}.)
2614
2615@item m68k-opcode.h
2616Opcode table for 68020. This is now a link to the opcode table
2617in the @code{GDB} source directory.
2618
2619@item m68k.c
2620All the mc680x0 code, in one huge, slow-to-compile file.
2621
2622@item ns32k.c
2623This contains the code for the ns32032/ns32532 version of the
2624assembler.
2625
2626@item ns32k-opcode.h
2627This contains the opcode table for the ns32032/ns32532 version
2628of the assembler.
2629
2630@item vax-inst.h
2631Vax specific file for describing Vax operands and other Vax-ish things.
2632
2633@item vax-opcode.h
2634Vax opcode table.
2635
2636@item vax.c
2637Vax specific parts of @code{as}. Also includes the former files
2638@file{vax-ins-parse.c}, @file{vax-reg-parse.c} and @file{vip-op.c}.
2639
2640@item atof-vax.c
2641Turns a flonum into a Vax constant.
2642
2643@item vms.c
2644This file contains the special code needed to put out a VMS
2645style object file for the Vax.
2646
2647@end table
2648
2649Here is a list of the header files in the source directory.
2650(Warning: This section may not be very accurate. I didn't
2651write the header files; I just report them.) Also note that I
2652think many of these header files could be cleaned up or
2653eliminated.
2654
2655@table @file
2656
2657@item a.out.h
2658This describes the structures used to create the binary header data
2659inside the object file. Perhaps we should use the one in
2660@file{/usr/include}?
2661
2662@item as.h
2663This defines all the globally useful things, and pulls in <stdio.h>
2664and <assert.h>.
2665
2666@item bignum.h
2667This defines macros useful for dealing with bignums.
2668
2669@item expr.h
2670Structure and macros for dealing with expression()
2671
2672@item flonum.h
2673This defines the structure for dealing with floating point
2674numbers. It #includes @file{bignum.h}.
2675
2676@item frags.h
2677This contains macro for appending a byte to the current frag.
2678
2679@item hash.h
2680Structures and function definitions for the hashing functions.
2681
2682@item input-file.h
2683Function headers for the input-file.c functions.
2684
2685@item md.h
2686structures and function headers for things defined in the
2687machine dependent part of the assembler.
2688
2689@item obstack.h
2690This is the GNU systemwide include file for manipulating obstacks.
2691Since nobody is running under real GNU yet, we include this file.
2692
2693@item read.h
2694Macros and function headers for reading in source files.
2695
2696@item struct-symbol.h
2697Structure definition and macros for dealing with the gas
2698internal form of a symbol.
2699
2700@item subsegs.h
2701structure definition for dealing with the numbered subsegments
2702of the text and data segments.
2703
2704@item symbols.h
2705Macros and function headers for dealing with symbols.
2706
2707@item write.h
2708Structure for doing segment fixups.
2709@end table
2710
2711@comment ~subsection Test Directory
2712@comment (Note: The test directory seems to have disappeared somewhere
2713@comment along the line. If you want it, you'll probably have to find a
2714@comment REALLY OLD dump tape~dots{})
2715@comment
2716@comment The ~file{test/} directory is used for regression testing.
2717@comment After you modify ~code{as}, you can get a quick go/nogo
2718@comment confidence test by running the new ~code{as} over the source
2719@comment files in this directory. You use a shell script ~file{test/do}.
2720@comment
2721@comment The tests in this suite are evolving. They are not comprehensive.
2722@comment They have, however, caught hundreds of bugs early in the debugging
2723@comment cycle of ~code{as}. Most test statements in this suite were naturally
2724@comment selected: they were used to demonstrate actual ~code{as} bugs rather
2725@comment than being written ~i{a prioi}.
2726@comment
2727@comment Another testing suggestion: over 30 bugs have been found simply by
2728@comment running examples from this manual through ~code{as}.
2729@comment Some examples in this manual are selected
2730@comment to distinguish boundary conditions; they are good for testing ~code{as}.
2731@comment
2732@comment ~subsubsection Regression Testing
2733@comment Each regression test involves assembling a file and comparing the
2734@comment actual output of ~code{as} to ``known good'' output files. Both
2735@comment the object file and the error/warning message file (stderr) are
2736@comment inspected. Optionally ~code{as}' exit status may be checked.
2737@comment Discrepencies are reported. Each discrepency means either that
2738@comment you broke some part of ~code{as} or that the ``known good'' files
2739@comment are now out of date and should be changed to reflect the new
2740@comment definition of ``good''.
2741@comment
2742@comment Each regression test lives in its own directory, in a tree
2743@comment rooted in the directory ~file{test/}. Each such directory
2744@comment has a name ending in ~file{.ret}, where `ret' stands for
2745@comment REgression Test. The ~file{.ret} ending allows ~code{find
2746@comment (1)} to find all regression tests in the tree, without
2747@comment needing to list them explicitly.
2748@comment
2749@comment Any ~file{.ret} directory must contain a file called
2750@comment ~file{input} which is the source file to assemble. During
2751@comment testing an object file ~file{output} is created, as well as
2752@comment a file ~file{stdouterr} which contains the output to both
2753@comment stderr and stderr. If there is a file ~file{output.good} in
2754@comment the directory, and if ~file{output} contains exactly the
2755@comment same data as ~file{output.good}, the file ~file{output} is
2756@comment deleted. Likewise ~file{stdouterr} is removed if it exactly
2757@comment matches a file ~file{stdouterr.good}. If file
2758@comment ~file{status.good} is present, containing a decimal number
2759@comment before a newline, the exit status of ~code{as} is compared
2760@comment to this number. If the status numbers are not equal, a file
2761@comment ~file{status} is written to the directory, containing the
2762@comment actual status as a decimal number followed by newline.
2763@comment
2764@comment Should any of the ~file{*.good} files fail to match their corresponding
2765@comment actual files, this is noted by a 1-line message on the screen during
2766@comment the regression test, and you can use ~code{find (1)} to find any
2767@comment files named ~file{status}, ~file {output} or ~file{stdouterr}.
2768@comment
2769@node Retargeting, , Maintenance, top
2770@chapter Teaching the Assembler about a New Machine
2771
2772This chapter describes the steps required in order to make the
2773assembler work with another machine's assembly language. This
2774chapter is not complete, and only describes the steps in the
2775broadest terms. You should look at the source for the
2776currently supported machine in order to discover some of the
2777details that aren't mentioned here.
2778
2779You should create a new file called @file{@var{machine}.c}, and
2780add the appropriate lines to the file @file{Makefile} so that
2781you can compile your new version of the assembler. This should
2782be straighforward; simply add lines similar to the ones there
2783for the four current versions of the assembler.
2784
2785If you want to be compatable with GDB, (and the current
2786machine-dependent versions of the assembler), you should create
2787a file called @file{@var{machine}-opcode.h} which should
2788contain all the information about the names of the machine
2789instructions, their opcodes, and what addressing modes they
2790support. If you do this right, the assembler and GDB can share
2791this file, and you'll only have to write it once. Note that
2792while you're writing @code{as}, you may want to use an
2793independent program (if you have access to one), to make sure
2794that @code{as} is emitting the correct bytes. Since @code{as}
2795and @code{GDB} share the opcode table, an incorrect opcode
2796table entry may make invalid bytes look OK when you disassemble
2797them with @code{GDB}.
2798
2799@section Functions You will Have to Write
2800
2801Your file @file{@var{machine}.c} should contain definitions for
2802the following functions and variables. It will need to include
2803some header files in order to use some of the structures
2804defined in the machine-independent part of the assembler. The
2805needed header files are mentioned in the descriptions of the
2806functions that will need them.
2807
2808@table @code
2809
2810@item long omagic;
2811This long integer holds the value to place at the beginning of
2812the @file{a.out} file. It is usually @samp{OMAGIC}, except on
2813machines that store additional information in the magic-number.
2814
2815@item char comment_chars[];
2816This character array holds the values of the characters that
2817start a comment anywhere in a line. Comments are stripped off
2818automatically by the machine independent part of the
2819assembler. Note that the @samp{/*} will always start a
2820comment, and that only @samp{*/} will end a comment started by
2821@samp{*/}.
2822
2823@item char line_comment_chars[];
2824This character array holds the values of the chars that start a
2825comment only if they are the first (non-whitespace) character
2826on a line. If the character @samp{#} does not appear in this
2827list, you may get unexpected results. (Various
2828machine-independent parts of the assembler treat the comments
2829@samp{#APP} and @samp{#NO_APP} specially, and assume that lines
2830that start with @samp{#} are comments.)
2831
2832@item char EXP_CHARS[];
2833This character array holds the letters that can separate the
2834mantissa and the exponent of a floating point number. Typical
2835values are @samp{e} and @samp{E}.
2836
2837@item char FLT_CHARS[];
2838This character array holds the letters that--when they appear
2839immediately after a leading zero--indicate that a number is a
2840floating-point number. (Sort of how 0x indicates that a
2841hexadecimal number follows.)
2842
2843@item pseudo_typeS md_pseudo_table[];
2844(@var{pseudo_typeS} is defined in @file{md.h})
2845This array contains a list of the machine_dependent directives
2846the assembler must support. It contains the name of each
2847pseudo op (Without the leading @samp{.}), a pointer to a
2848function to be called when that directive is encountered, and
2849an integer argument to be passed to that function.
2850
2851@item void md_begin(void)
2852This function is called as part of the assembler's
2853initialization. It should do any initialization required by
2854any of your other routines.
2855
2856@item int md_parse_option(char **optionPTR, int *argcPTR, char ***argvPTR)
2857This routine is called once for each option on the command line
2858that the machine-independent part of @code{as} does not
2859understand. This function should return non-zero if the option
2860pointed to by @var{optionPTR} is a valid option. If it is not
2861a valid option, this routine should return zero. The variables
2862@var{argcPTR} and @var{argvPTR} are provided in case the option
2863requires a filename or something similar as an argument. If
2864the option is multi-character, @var{optionPTR} should be
2865advanced past the end of the option, otherwise every letter in
2866the option will be treated as a separate single-character
2867option.
2868
2869@item void md_assemble(char *string)
2870This routine is called for every machine-dependent
2871non-directive line in the source file. It does all the real
2872work involved in reading the opcode, parsing the operands,
2873etc. @var{string} is a pointer to a null-terminated string,
2874that comprises the input line, with all excess whitespace and
2875comments removed.
2876
2877@item void md_number_to_chars(char *outputPTR,long value,int nbytes)
2878This routine is called to turn a C long int, short int, or char
2879into the series of bytes that represents that number on the
2880target machine. @var{outputPTR} points to an array where the
2881result should be stored; @var{value} is the value to store; and
2882@var{nbytes} is the number of bytes in 'value' that should be
2883stored.
2884
2885@item void md_number_to_imm(char *outputPTR,long value,int nbytes)
2886This routine is called to turn a C long int, short int, or char
2887into the series of bytes that represent an immediate value on
2888the target machine. It is identical to the function @code{md_number_to_chars},
2889except on NS32K machines.@refill
2890
2891@item void md_number_to_disp(char *outputPTR,long value,int nbytes)
2892This routine is called to turn a C long int, short int, or char
2893into the series of bytes that represent an displacement value on
2894the target machine. It is identical to the function @code{md_number_to_chars},
2895except on NS32K machines.@refill
2896
2897@item void md_number_to_field(char *outputPTR,long value,int nbytes)
2898This routine is identical to @code{md_number_to_chars},
2899except on NS32K machines.
2900
2901@item void md_ri_to_chars(struct relocation_info *riPTR,ri)
2902(@code{struct relocation_info} is defined in @file{a.out.h})
2903This routine emits the relocation info in @var{ri}
2904in the appropriate bit-pattern for the target machine.
2905The result should be stored in the location pointed
2906to by @var{riPTR}. This routine may be a no-op unless you are
2907attempting to do cross-assembly.
2908
2909@item char *md_atof(char type,char *outputPTR,int *sizePTR)
2910This routine turns a series of digits into the appropriate
2911internal representation for a floating-point number.
2912@var{type} is a character from @var{FLT_CHARS[]} that describes
2913what kind of floating point number is wanted; @var{outputPTR}
2914is a pointer to an array that the result should be stored in;
2915and @var{sizePTR} is a pointer to an integer where the size (in
2916bytes) of the result should be stored. This routine should
2917return an error message, or an empty string (not (char *)0) for
2918success.
2919
2920@item int md_short_jump_size;
2921This variable holds the (maximum) size in bytes of a short (16
2922bit or so) jump created by @code{md_create_short_jump()}. This
2923variable is used as part of the broken-word feature, and isn't
2924needed if the assembler is compiled with
2925@samp{-DWORKING_DOT_WORD}.
2926
2927@item int md_long_jump_size;
2928This variable holds the (maximum) size in bytes of a long (32
2929bit or so) jump created by @code{md_create_long_jump()}. This
2930variable is used as part of the broken-word feature, and isn't
2931needed if the assembler is compiled with
2932@samp{-DWORKING_DOT_WORD}.
2933
2934@item void md_create_short_jump(char *resultPTR,long from_addr,
2935@code{long to_addr,fragS *frag,symbolS *to_symbol)}
2936This function emits a jump from @var{from_addr} to @var{to_addr} in
2937the array of bytes pointed to by @var{resultPTR}. If this creates a
2938type of jump that must be relocated, this function should call
2939@code{fix_new()} with @var{frag} and @var{to_symbol}. The jump
2940emitted by this function may be smaller than @var{md_short_jump_size},
2941but it must never create a larger one.
2942(If it creates a smaller jump, the extra bytes of memory will not be
2943used.) This function is used as part of the broken-word feature,
2944and isn't needed if the assembler is compiled with
2945@samp{-DWORKING_DOT_WORD}.@refill
2946
2947@item void md_create_long_jump(char *ptr,long from_addr,
2948@code{long to_addr,fragS *frag,symbolS *to_symbol)}
2949This function is similar to the previous function,
2950@code{md_create_short_jump()}, except that it creates a long
2951jump instead of a short one. This function is used as part of
2952the broken-word feature, and isn't needed if the assembler is
2953compiled with @samp{-DWORKING_DOT_WORD}.
2954
2955@item int md_estimate_size_before_relax(fragS *fragPTR,int segment_type)
2956This function does the initial setting up for relaxation. This
2957includes forcing references to still-undefined symbols to the
2958appropriate addressing modes.
2959
2960@item relax_typeS md_relax_table[];
2961(relax_typeS is defined in md.h)
2962This array describes the various machine dependent states a
2963frag may be in before relaxation. You will need one group of
2964entries for each type of addressing mode you intend to relax.
2965
2966@item void md_convert_frag(fragS *fragPTR)
2967(@var{fragS} is defined in @file{as.h})
2968This routine does the required cleanup after relaxation.
2969Relaxation has changed the type of the frag to a type that can
2970reach its destination. This function should adjust the opcode
2971of the frag to use the appropriate addressing mode.
2972@var{fragPTR} points to the frag to clean up.
2973
2974@item void md_end(void)
2975This function is called just before the assembler exits. It
2976need not free up memory unless the operating system doesn't do
2977it automatically on exit. (In which case you'll also have to
2978track down all the other places where the assembler allocates
2979space but never frees it.)
2980
2981@end table
2982
2983@section External Variables You will Need to Use
2984
2985You will need to refer to or change the following external variables
2986from within the machine-dependent part of the assembler.
2987
2988@table @code
2989@item extern char flagseen[];
2990This array holds non-zero values in locations corresponding to
2991the options that were on the command line. Thus, if the
2992assembler was called with @samp{-W}, @var{flagseen['W']} would
2993be non-zero.
2994
2995@item extern fragS *frag_now;
2996This pointer points to the current frag--the frag that bytes
2997are currently being added to. If nothing else, you will need
2998to pass it as an argument to various machine-independent
2999functions. It is maintained automatically by the
3000frag-manipulating functions; you should never have to change it
3001yourself.
3002
3003@item extern LITTLENUM_TYPE generic_bignum[];
3004(@var{LITTLENUM_TYPE} is defined in @file{bignum.h}.
3005This is where @dfn{bignums}--numbers larger than 32 bits--are
3006returned when they are encountered in an expression. You will
3007need to use this if you need to implement directives (or
3008anything else) that must deal with these large numbers.
3009@code{Bignums} are of @code{segT} @code{SEG_BIG} (defined in
3010@file{as.h}, and have a positive @code{X_add_number}. The
3011@code{X_add_number} of a @code{bignum} is the number of
3012@code{LITTLENUMS} in @var{generic_bignum} that the number takes
3013up.
3014
3015@item extern FLONUM_TYPE generic_floating_point_number;
3016(@var{FLONUM_TYPE} is defined in @file{flonum.h}.
3017The is where @dfn{flonums}--floating-point numbers within
3018expressions--are returned. @code{Flonums} are of @code{segT}
3019@code{SEG_BIG}, and have a negative @code{X_add_number}.
3020@code{Flonums} are returned in a generic format. You will have
3021to write a routine to turn this generic format into the
3022appropriate floating-point format for your machine.
3023
3024@item extern int need_pass_2;
3025If this variable is non-zero, the assembler has encountered an
3026expression that cannot be assembled in a single pass. Since
3027the second pass isn't implemented, this flag means that the
3028assembler is punting, and is only looking for additional syntax
3029errors. (Or something like that.)
3030
3031@item extern segT now_seg;
3032This variable holds the value of the segment the assembler is
3033currently assembling into.
3034
3035@end table
3036
3037@section External functions will you need
3038
3039You will find the following external functions useful (or
3040indispensable) when you're writing the machine-dependent part
3041of the assembler.
3042
3043@table @code
3044
3045@item char *frag_more(int bytes)
3046This function allocates @var{bytes} more bytes in the current
3047frag (or starts a new frag, if it can't expand the current frag
3048any more.) for you to store some object-file bytes in. It
3049returns a pointer to the bytes, ready for you to store data in.
3050
3051@item void fix_new(fragS *frag, int where, short size, symbolS *add_symbol, symbolS *sub_symbol, long offset, int pcrel)
3052This function stores a relocation fixup to be acted on later.
3053@var{frag} points to the frag the relocation belongs in;
3054@var{where} is the location within the frag where the relocation begins;
3055@var{size} is the size of the relocation, and is usually 1 (a single byte),
3056 2 (sixteen bits), or 4 (a longword).
3057The value @var{add_symbol} @minus{} @var{sub_symbol} + @var{offset}, is added to the byte(s)
3058at @var{frag->literal[where]}. If @var{pcrel} is non-zero, the address of the
3059location is subtracted from the result. A relocation entry is also added
3060to the @file{a.out} file. @var{add_symbol}, @var{sub_symbol}, and/or
3061@var{offset} may be NULL.@refill
3062
3063@item char *frag_var(relax_stateT type, int max_chars, int var,
3064@code{relax_substateT subtype, symbolS *symbol, char *opcode)}
3065This function creates a machine-dependent frag of type @var{type}
3066(usually @code{rs_machine_dependent}).
3067@var{max_chars} is the maximum size in bytes that the frag may grow by;
3068@var{var} is the current size of the variable end of the frag;
3069@var{subtype} is the sub-type of the frag. The sub-type is used to index into
3070@var{md_relax_table[]} during @code{relaxation}.
3071@var{symbol} is the symbol whose value should be used to when relax-ing this frag.
3072@var{opcode} points into a byte whose value may have to be modified if the
3073addressing mode used by this frag changes. It typically points into the
3074@var{fr_literal[]} of the previous frag, and is used to point to a location
3075that @code{md_convert_frag()}, may have to change.@refill
3076
3077@item void frag_wane(fragS *fragPTR)
3078This function is useful from within @code{md_convert_frag}. It
3079changes a frag to type rs_fill, and sets the variable-sized
3080piece of the frag to zero. The frag will never change in size
3081again.
3082
3083@item segT expression(expressionS *retval)
3084(@var{segT} is defined in @file{as.h}; @var{expressionS} is defined in @file{expr.h})
3085This function parses the string pointed to by the external char
3086pointer @var{input_line_pointer}, and returns the segment-type
3087of the expression. It also stores the results in the
3088@var{expressionS} pointed to by @var{retval}.
3089@var{input_line_pointer} is advanced to point past the end of
3090the expression. (@var{input_line_pointer} is used by other
3091parts of the assembler. If you modify it, be sure to restore
3092it to its original value.)
3093
3094@item as_warn(char *message,@dots{})
3095If warning messages are disabled, this function does nothing.
3096Otherwise, it prints out the current file name, and the current
3097line number, then uses @code{fprintf} to print the
3098@var{message} and any arguments it was passed.
3099
3100@item as_bad(char *message,@dots{})
3101This function should be called when @code{as} encounters
3102conditions that are bad enough that @code{as} should not
3103produce an object file, but should continue reading input and
3104printing warning and bad error messages.
3105
3106@item as_fatal(char *message,@dots{})
3107This function prints out the current file name and line number,
3108prints the word @samp{FATAL:}, then uses @code{fprintf} to
3109print the @var{message} and any arguments it was passed. Then
3110the assembler exits. This function should only be used for
3111serious, unrecoverable errors.
3112
3113@item void float_const(int float_type)
3114This function reads floating-point constants from the current
3115input line, and calls @code{md_atof} to assemble them. It is
3116useful as the function to call for the directives
3117@samp{.single}, @samp{.double}, @samp{.float}, etc.
3118@var{float_type} must be a character from @var{FLT_CHARS}.
3119
3120@item void demand_empty_rest_of_line(void);
3121This function can be used by machine-dependent directives to
3122make sure the rest of the input line is empty. It prints a
3123warning message if there are additional characters on the line.
3124
3125@item long int get_absolute_expression(void)
3126This function can be used by machine-dependent directives to
3127read an absolute number from the current input line. It
3128returns the result. If it isn't given an absolute expression,
3129it prints a warning message and returns zero.
3130
3131@end table
3132
3133
3134@section The concept of Frags
3135
3136This assembler works to optimize the size of certain addressing
3137modes. (e.g. branch instructions) This means the size of many
3138pieces of object code cannot be determined until after assembly
3139is finished. (This means that the addresses of symbols cannot be
3140determined until assembly is finished.) In order to do this,
3141@code{as} stores the output bytes as @dfn{frags}.
3142
3143Here is the definition of a frag (from @file{as.h})
3144@example
3145struct frag
3146@{
3147 long int fr_fix;
3148 long int fr_var;
3149 relax_stateT fr_type;
3150 relax_substateT fr_substate;
3151 unsigned long fr_address;
3152 long int fr_offset;
3153 struct symbol *fr_symbol;
3154 char *fr_opcode;
3155 struct frag *fr_next;
3156 char fr_literal[];
3157@}
3158@end example
3159
3160@table @var
3161@item fr_fix
3162is the size of the fixed-size piece of the frag.
3163
3164@item fr_var
3165is the maximum (?) size of the variable-sized piece of the frag.
3166
3167@item fr_type
3168is the type of the frag.
3169Current types are:
3170rs_fill
3171rs_align
3172rs_org
3173rs_machine_dependent
3174
3175@item fr_substate
3176This stores the type of machine-dependent frag this is. (what
3177kind of addressing mode is being used, and what size is being
3178tried/will fit/etc.
3179
3180@item fr_address
3181@var{fr_address} is only valid after relaxation is finished.
3182Before relaxation, the only way to store an address is (pointer
3183to frag containing the address) plus (offset into the frag).
3184
3185@item fr_offset
3186This contains a number, whose meaning depends on the type of
3187the frag.
3188for machine_dependent frags, this contains the offset from
3189fr_symbol that the frag wants to go to. Thus, for branch
3190instructions it is usually zero. (unless the instruction was
3191@samp{jba foo+12} or something like that.)
3192
3193@item fr_symbol
3194for machine_dependent frags, this points to the symbol the frag
3195needs to reach.
3196
3197@item fr_opcode
3198This points to the location in the frag (or in a previous frag)
3199of the opcode for the instruction that caused this to be a frag.
3200@var{fr_opcode} is needed if the actual opcode must be changed
3201in order to use a different form of the addressing mode.
3202(For example, if a conditional branch only comes in size tiny,
3203a large-size branch could be implemented by reversing the sense
3204of the test, and turning it into a tiny branch over a large jump.
3205This would require changing the opcode.)
3206
3207@var{fr_literal} is a variable-size array that contains the
3208actual object bytes. A frag consists of a fixed size piece of
3209object data, (which may be zero bytes long), followed by a
3210piece of object data whose size may not have been determined
3211yet. Other information includes the type of the frag (which
3212controls how it is relaxed),
3213
3214@item fr_next
3215This is the next frag in the singly-linked list. This is
3216usually only needed by the machine-independent part of
3217@code{as}.
3218
3219@end table
3220
3221@c Is this really a good idea?
3222@iftex
3223@center [end of manual]
3224@end iftex
3225@summarycontents
3226@contents
3227@bye
This page took 0.341115 seconds and 4 git commands to generate.