source: trunk/binutils/gas/doc/as.info-2@ 3003

Last change on this file since 3003 was 610, checked in by bird, 22 years ago

This commit was generated by cvs2svn to compensate for changes in r609,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 48.7 KB
Line 
1This is as.info, produced by makeinfo version 4.3 from as.texinfo.
2
3START-INFO-DIR-ENTRY
4* As: (as). The GNU assembler.
5* Gas: (as). The GNU assembler.
6END-INFO-DIR-ENTRY
7
8 This file documents the GNU Assembler "as".
9
10 Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002
11Free Software Foundation, Inc.
12
13 Permission is granted to copy, distribute and/or modify this document
14under the terms of the GNU Free Documentation License, Version 1.1 or
15any later version published by the Free Software Foundation; with no
16Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
17Texts. A copy of the license is included in the section entitled "GNU
18Free Documentation License".
19
20
21File: as.info, Node: Comments, Next: Symbol Intro, Prev: Whitespace, Up: Syntax
22
23Comments
24========
25
26 There are two ways of rendering comments to `as'. In both cases the
27comment is equivalent to one space.
28
29 Anything from `/*' through the next `*/' is a comment. This means
30you may not nest these comments.
31
32 /*
33 The only way to include a newline ('\n') in a comment
34 is to use this sort of comment.
35 */
36
37 /* This sort of comment does not nest. */
38
39 Anything from the "line comment" character to the next newline is
40considered a comment and is ignored. The line comment character is `;'
41for the AMD 29K family; `;' on the ARC; `@' on the ARM; `;' for the
42H8/300 family; `!' for the H8/500 family; `;' for the HPPA; `#' on the
43i386 and x86-64; `#' on the i960; `;' for the PDP-11; `;' for picoJava;
44`;' for Motorola PowerPC; `!' for the Renesas / SuperH SH; `!' on the
45SPARC; `#' on the ip2k; `#' on the m32r; `|' on the 680x0; `#' on the
4668HC11 and 68HC12; `;' on the M880x0; `#' on the Vax; `!' for the Z8000;
47`#' on the V850; `#' for Xtensa systems; see *Note Machine
48Dependencies::.
49
50 On some machines there are two different line comment characters.
51One character only begins a comment if it is the first non-whitespace
52character on a line, while the other always begins a comment.
53
54 The V850 assembler also supports a double dash as starting a comment
55that extends to the end of the line.
56
57 `--';
58
59 To be compatible with past assemblers, lines that begin with `#'
60have a special interpretation. Following the `#' should be an absolute
61expression (*note Expressions::): the logical line number of the _next_
62line. Then a string (*note Strings: Strings.) is allowed: if present
63it is a new logical file name. The rest of the line, if any, should be
64whitespace.
65
66 If the first non-whitespace characters on the line are not numeric,
67the line is ignored. (Just like a comment.)
68
69 # This is an ordinary comment.
70 # 42-6 "new_file_name" # New logical file name
71 # This is logical line # 36.
72 This feature is deprecated, and may disappear from future versions
73of `as'.
74
75
76File: as.info, Node: Symbol Intro, Next: Statements, Prev: Comments, Up: Syntax
77
78Symbols
79=======
80
81 A "symbol" is one or more characters chosen from the set of all
82letters (both upper and lower case), digits and the three characters
83`_.$'. On most machines, you can also use `$' in symbol names;
84exceptions are noted in *Note Machine Dependencies::. No symbol may
85begin with a digit. Case is significant. There is no length limit:
86all characters are significant. Symbols are delimited by characters
87not in that set, or by the beginning of a file (since the source
88program must end with a newline, the end of a file is not a possible
89symbol delimiter). *Note Symbols::.
90
91
92File: as.info, Node: Statements, Next: Constants, Prev: Symbol Intro, Up: Syntax
93
94Statements
95==========
96
97 A "statement" ends at a newline character (`\n') or line separator
98character. (The line separator is usually `;', unless this conflicts
99with the comment character; *note Machine Dependencies::.) The newline
100or separator character is considered part of the preceding statement.
101Newlines and separators within character constants are an exception:
102they do not end statements.
103
104 It is an error to end any statement with end-of-file: the last
105character of any input file should be a newline.
106
107 An empty statement is allowed, and may include whitespace. It is
108ignored.
109
110 A statement begins with zero or more labels, optionally followed by a
111key symbol which determines what kind of statement it is. The key
112symbol determines the syntax of the rest of the statement. If the
113symbol begins with a dot `.' then the statement is an assembler
114directive: typically valid for any computer. If the symbol begins with
115a letter the statement is an assembly language "instruction": it
116assembles into a machine language instruction. Different versions of
117`as' for different computers recognize different instructions. In
118fact, the same symbol may represent a different instruction in a
119different computer's assembly language.
120
121 A label is a symbol immediately followed by a colon (`:').
122Whitespace before a label or after a colon is permitted, but you may not
123have whitespace between a label's symbol and its colon. *Note Labels::.
124
125 For HPPA targets, labels need not be immediately followed by a
126colon, but the definition of a label must begin in column zero. This
127also implies that only one label may be defined on each line.
128
129 label: .directive followed by something
130 another_label: # This is an empty statement.
131 instruction operand_1, operand_2, ...
132
133
134File: as.info, Node: Constants, Prev: Statements, Up: Syntax
135
136Constants
137=========
138
139 A constant is a number, written so that its value is known by
140inspection, without knowing any context. Like this:
141 .byte 74, 0112, 092, 0x4A, 0X4a, 'J, '\J # All the same value.
142 .ascii "Ring the bell\7" # A string constant.
143 .octa 0x123456789abcdef0123456789ABCDEF0 # A bignum.
144 .float 0f-314159265358979323846264338327\
145 95028841971.693993751E-40 # - pi, a flonum.
146
147* Menu:
148
149* Characters:: Character Constants
150* Numbers:: Number Constants
151
152
153File: as.info, Node: Characters, Next: Numbers, Up: Constants
154
155Character Constants
156-------------------
157
158 There are two kinds of character constants. A "character" stands
159for one character in one byte and its value may be used in numeric
160expressions. String constants (properly called string _literals_) are
161potentially many bytes and their values may not be used in arithmetic
162expressions.
163
164* Menu:
165
166* Strings:: Strings
167* Chars:: Characters
168
169
170File: as.info, Node: Strings, Next: Chars, Up: Characters
171
172Strings
173.......
174
175 A "string" is written between double-quotes. It may contain
176double-quotes or null characters. The way to get special characters
177into a string is to "escape" these characters: precede them with a
178backslash `\' character. For example `\\' represents one backslash:
179the first `\' is an escape which tells `as' to interpret the second
180character literally as a backslash (which prevents `as' from
181recognizing the second `\' as an escape character). The complete list
182of escapes follows.
183
184`\b'
185 Mnemonic for backspace; for ASCII this is octal code 010.
186
187`\f'
188 Mnemonic for FormFeed; for ASCII this is octal code 014.
189
190`\n'
191 Mnemonic for newline; for ASCII this is octal code 012.
192
193`\r'
194 Mnemonic for carriage-Return; for ASCII this is octal code 015.
195
196`\t'
197 Mnemonic for horizontal Tab; for ASCII this is octal code 011.
198
199`\ DIGIT DIGIT DIGIT'
200 An octal character code. The numeric code is 3 octal digits. For
201 compatibility with other Unix systems, 8 and 9 are accepted as
202 digits: for example, `\008' has the value 010, and `\009' the
203 value 011.
204
205`\`x' HEX-DIGITS...'
206 A hex character code. All trailing hex digits are combined.
207 Either upper or lower case `x' works.
208
209`\\'
210 Represents one `\' character.
211
212`\"'
213 Represents one `"' character. Needed in strings to represent this
214 character, because an unescaped `"' would end the string.
215
216`\ ANYTHING-ELSE'
217 Any other character when escaped by `\' gives a warning, but
218 assembles as if the `\' was not present. The idea is that if you
219 used an escape sequence you clearly didn't want the literal
220 interpretation of the following character. However `as' has no
221 other interpretation, so `as' knows it is giving you the wrong
222 code and warns you of the fact.
223
224 Which characters are escapable, and what those escapes represent,
225varies widely among assemblers. The current set is what we think the
226BSD 4.2 assembler recognizes, and is a subset of what most C compilers
227recognize. If you are in doubt, do not use an escape sequence.
228
229
230File: as.info, Node: Chars, Prev: Strings, Up: Characters
231
232Characters
233..........
234
235 A single character may be written as a single quote immediately
236followed by that character. The same escapes apply to characters as to
237strings. So if you want to write the character backslash, you must
238write `'\\' where the first `\' escapes the second `\'. As you can
239see, the quote is an acute accent, not a grave accent. A newline
240immediately following an acute accent is taken as a literal character
241and does not count as the end of a statement. The value of a character
242constant in a numeric expression is the machine's byte-wide code for
243that character. `as' assumes your character code is ASCII: `'A' means
24465, `'B' means 66, and so on.
245
246
247File: as.info, Node: Numbers, Prev: Characters, Up: Constants
248
249Number Constants
250----------------
251
252 `as' distinguishes three kinds of numbers according to how they are
253stored in the target machine. _Integers_ are numbers that would fit
254into an `int' in the C language. _Bignums_ are integers, but they are
255stored in more than 32 bits. _Flonums_ are floating point numbers,
256described below.
257
258* Menu:
259
260* Integers:: Integers
261* Bignums:: Bignums
262* Flonums:: Flonums
263
264
265File: as.info, Node: Integers, Next: Bignums, Up: Numbers
266
267Integers
268........
269
270 A binary integer is `0b' or `0B' followed by zero or more of the
271binary digits `01'.
272
273 An octal integer is `0' followed by zero or more of the octal digits
274(`01234567').
275
276 A decimal integer starts with a non-zero digit followed by zero or
277more digits (`0123456789').
278
279 A hexadecimal integer is `0x' or `0X' followed by one or more
280hexadecimal digits chosen from `0123456789abcdefABCDEF'.
281
282 Integers have the usual values. To denote a negative integer, use
283the prefix operator `-' discussed under expressions (*note Prefix
284Operators: Prefix Ops.).
285
286
287File: as.info, Node: Bignums, Next: Flonums, Prev: Integers, Up: Numbers
288
289Bignums
290.......
291
292 A "bignum" has the same syntax and semantics as an integer except
293that the number (or its negative) takes more than 32 bits to represent
294in binary. The distinction is made because in some places integers are
295permitted while bignums are not.
296
297
298File: as.info, Node: Flonums, Prev: Bignums, Up: Numbers
299
300Flonums
301.......
302
303 A "flonum" represents a floating point number. The translation is
304indirect: a decimal floating point number from the text is converted by
305`as' to a generic binary floating point number of more than sufficient
306precision. This generic floating point number is converted to a
307particular computer's floating point format (or formats) by a portion
308of `as' specialized to that computer.
309
310 A flonum is written by writing (in order)
311 * The digit `0'. (`0' is optional on the HPPA.)
312
313 * A letter, to tell `as' the rest of the number is a flonum. `e' is
314 recommended. Case is not important.
315
316 On the H8/300, H8/500, Renesas / SuperH SH, and AMD 29K
317 architectures, the letter must be one of the letters `DFPRSX' (in
318 upper or lower case).
319
320 On the ARC, the letter must be one of the letters `DFRS' (in upper
321 or lower case).
322
323 On the Intel 960 architecture, the letter must be one of the
324 letters `DFT' (in upper or lower case).
325
326 On the HPPA architecture, the letter must be `E' (upper case only).
327
328 * An optional sign: either `+' or `-'.
329
330 * An optional "integer part": zero or more decimal digits.
331
332 * An optional "fractional part": `.' followed by zero or more
333 decimal digits.
334
335 * An optional exponent, consisting of:
336
337 * An `E' or `e'.
338
339 * Optional sign: either `+' or `-'.
340
341 * One or more decimal digits.
342
343
344 At least one of the integer part or the fractional part must be
345present. The floating point number has the usual base-10 value.
346
347 `as' does all processing using integers. Flonums are computed
348independently of any floating point hardware in the computer running
349`as'.
350
351
352File: as.info, Node: Sections, Next: Symbols, Prev: Syntax, Up: Top
353
354Sections and Relocation
355***********************
356
357* Menu:
358
359* Secs Background:: Background
360* Ld Sections:: Linker Sections
361* As Sections:: Assembler Internal Sections
362* Sub-Sections:: Sub-Sections
363* bss:: bss Section
364
365
366File: as.info, Node: Secs Background, Next: Ld Sections, Up: Sections
367
368Background
369==========
370
371 Roughly, a section is a range of addresses, with no gaps; all data
372"in" those addresses is treated the same for some particular purpose.
373For example there may be a "read only" section.
374
375 The linker `ld' reads many object files (partial programs) and
376combines their contents to form a runnable program. When `as' emits an
377object file, the partial program is assumed to start at address 0.
378`ld' assigns the final addresses for the partial program, so that
379different partial programs do not overlap. This is actually an
380oversimplification, but it suffices to explain how `as' uses sections.
381
382 `ld' moves blocks of bytes of your program to their run-time
383addresses. These blocks slide to their run-time addresses as rigid
384units; their length does not change and neither does the order of bytes
385within them. Such a rigid unit is called a _section_. Assigning
386run-time addresses to sections is called "relocation". It includes the
387task of adjusting mentions of object-file addresses so they refer to
388the proper run-time addresses. For the H8/300 and H8/500, and for the
389Renesas / SuperH SH, `as' pads sections if needed to ensure they end on
390a word (sixteen bit) boundary.
391
392 An object file written by `as' has at least three sections, any of
393which may be empty. These are named "text", "data" and "bss" sections.
394
395 When it generates COFF or ELF output, `as' can also generate
396whatever other named sections you specify using the `.section'
397directive (*note `.section': Section.). If you do not use any
398directives that place output in the `.text' or `.data' sections, these
399sections still exist, but are empty.
400
401 When `as' generates SOM or ELF output for the HPPA, `as' can also
402generate whatever other named sections you specify using the `.space'
403and `.subspace' directives. See `HP9000 Series 800 Assembly Language
404Reference Manual' (HP 92432-90001) for details on the `.space' and
405`.subspace' assembler directives.
406
407 Additionally, `as' uses different names for the standard text, data,
408and bss sections when generating SOM output. Program text is placed
409into the `$CODE$' section, data into `$DATA$', and BSS into `$BSS$'.
410
411 Within the object file, the text section starts at address `0', the
412data section follows, and the bss section follows the data section.
413
414 When generating either SOM or ELF output files on the HPPA, the text
415section starts at address `0', the data section at address `0x4000000',
416and the bss section follows the data section.
417
418 To let `ld' know which data changes when the sections are relocated,
419and how to change that data, `as' also writes to the object file
420details of the relocation needed. To perform relocation `ld' must
421know, each time an address in the object file is mentioned:
422 * Where in the object file is the beginning of this reference to an
423 address?
424
425 * How long (in bytes) is this reference?
426
427 * Which section does the address refer to? What is the numeric
428 value of
429 (ADDRESS) - (START-ADDRESS OF SECTION)?
430
431 * Is the reference to an address "Program-Counter relative"?
432
433 In fact, every address `as' ever uses is expressed as
434 (SECTION) + (OFFSET INTO SECTION)
435
436Further, most expressions `as' computes have this section-relative
437nature. (For some object formats, such as SOM for the HPPA, some
438expressions are symbol-relative instead.)
439
440 In this manual we use the notation {SECNAME N} to mean "offset N
441into section SECNAME."
442
443 Apart from text, data and bss sections you need to know about the
444"absolute" section. When `ld' mixes partial programs, addresses in the
445absolute section remain unchanged. For example, address `{absolute 0}'
446is "relocated" to run-time address 0 by `ld'. Although the linker
447never arranges two partial programs' data sections with overlapping
448addresses after linking, _by definition_ their absolute sections must
449overlap. Address `{absolute 239}' in one part of a program is always
450the same address when the program is running as address `{absolute
451239}' in any other part of the program.
452
453 The idea of sections is extended to the "undefined" section. Any
454address whose section is unknown at assembly time is by definition
455rendered {undefined U}--where U is filled in later. Since numbers are
456always defined, the only way to generate an undefined address is to
457mention an undefined symbol. A reference to a named common block would
458be such a symbol: its value is unknown at assembly time so it has
459section _undefined_.
460
461 By analogy the word _section_ is used to describe groups of sections
462in the linked program. `ld' puts all partial programs' text sections
463in contiguous addresses in the linked program. It is customary to
464refer to the _text section_ of a program, meaning all the addresses of
465all partial programs' text sections. Likewise for data and bss
466sections.
467
468 Some sections are manipulated by `ld'; others are invented for use
469of `as' and have no meaning except during assembly.
470
471
472File: as.info, Node: Ld Sections, Next: As Sections, Prev: Secs Background, Up: Sections
473
474Linker Sections
475===============
476
477 `ld' deals with just four kinds of sections, summarized below.
478
479*named sections*
480*text section*
481*data section*
482 These sections hold your program. `as' and `ld' treat them as
483 separate but equal sections. Anything you can say of one section
484 is true of another. When the program is running, however, it is
485 customary for the text section to be unalterable. The text
486 section is often shared among processes: it contains instructions,
487 constants and the like. The data section of a running program is
488 usually alterable: for example, C variables would be stored in the
489 data section.
490
491*bss section*
492 This section contains zeroed bytes when your program begins
493 running. It is used to hold uninitialized variables or common
494 storage. The length of each partial program's bss section is
495 important, but because it starts out containing zeroed bytes there
496 is no need to store explicit zero bytes in the object file. The
497 bss section was invented to eliminate those explicit zeros from
498 object files.
499
500*absolute section*
501 Address 0 of this section is always "relocated" to runtime address
502 0. This is useful if you want to refer to an address that `ld'
503 must not change when relocating. In this sense we speak of
504 absolute addresses being "unrelocatable": they do not change
505 during relocation.
506
507*undefined section*
508 This "section" is a catch-all for address references to objects
509 not in the preceding sections.
510
511 An idealized example of three relocatable sections follows. The
512example uses the traditional section names `.text' and `.data'. Memory
513addresses are on the horizontal axis.
514
515 +-----+----+--+
516 partial program # 1: |ttttt|dddd|00|
517 +-----+----+--+
518
519 text data bss
520 seg. seg. seg.
521
522 +---+---+---+
523 partial program # 2: |TTT|DDD|000|
524 +---+---+---+
525
526 +--+---+-----+--+----+---+-----+~~
527 linked program: | |TTT|ttttt| |dddd|DDD|00000|
528 +--+---+-----+--+----+---+-----+~~
529
530 addresses: 0 ...
531
532
533File: as.info, Node: As Sections, Next: Sub-Sections, Prev: Ld Sections, Up: Sections
534
535Assembler Internal Sections
536===========================
537
538 These sections are meant only for the internal use of `as'. They
539have no meaning at run-time. You do not really need to know about these
540sections for most purposes; but they can be mentioned in `as' warning
541messages, so it might be helpful to have an idea of their meanings to
542`as'. These sections are used to permit the value of every expression
543in your assembly language program to be a section-relative address.
544
545ASSEMBLER-INTERNAL-LOGIC-ERROR!
546 An internal assembler logic error has been found. This means
547 there is a bug in the assembler.
548
549expr section
550 The assembler stores complex expression internally as combinations
551 of symbols. When it needs to represent an expression as a symbol,
552 it puts it in the expr section.
553
554
555File: as.info, Node: Sub-Sections, Next: bss, Prev: As Sections, Up: Sections
556
557Sub-Sections
558============
559
560 Assembled bytes conventionally fall into two sections: text and data.
561You may have separate groups of data in named sections that you want to
562end up near to each other in the object file, even though they are not
563contiguous in the assembler source. `as' allows you to use
564"subsections" for this purpose. Within each section, there can be
565numbered subsections with values from 0 to 8192. Objects assembled
566into the same subsection go into the object file together with other
567objects in the same subsection. For example, a compiler might want to
568store constants in the text section, but might not want to have them
569interspersed with the program being assembled. In this case, the
570compiler could issue a `.text 0' before each section of code being
571output, and a `.text 1' before each group of constants being output.
572
573 Subsections are optional. If you do not use subsections, everything
574goes in subsection number zero.
575
576 Each subsection is zero-padded up to a multiple of four bytes.
577(Subsections may be padded a different amount on different flavors of
578`as'.)
579
580 Subsections appear in your object file in numeric order, lowest
581numbered to highest. (All this to be compatible with other people's
582assemblers.) The object file contains no representation of
583subsections; `ld' and other programs that manipulate object files see
584no trace of them. They just see all your text subsections as a text
585section, and all your data subsections as a data section.
586
587 To specify which subsection you want subsequent statements assembled
588into, use a numeric argument to specify it, in a `.text EXPRESSION' or
589a `.data EXPRESSION' statement. When generating COFF or ELF output, you
590can also use an extra subsection argument with arbitrary named
591sections: `.section NAME, EXPRESSION'. EXPRESSION should be an
592absolute expression. (*Note Expressions::.) If you just say `.text'
593then `.text 0' is assumed. Likewise `.data' means `.data 0'. Assembly
594begins in `text 0'. For instance:
595 .text 0 # The default subsection is text 0 anyway.
596 .ascii "This lives in the first text subsection. *"
597 .text 1
598 .ascii "But this lives in the second text subsection."
599 .data 0
600 .ascii "This lives in the data section,"
601 .ascii "in the first data subsection."
602 .text 0
603 .ascii "This lives in the first text section,"
604 .ascii "immediately following the asterisk (*)."
605
606 Each section has a "location counter" incremented by one for every
607byte assembled into that section. Because subsections are merely a
608convenience restricted to `as' there is no concept of a subsection
609location counter. There is no way to directly manipulate a location
610counter--but the `.align' directive changes it, and any label
611definition captures its current value. The location counter of the
612section where statements are being assembled is said to be the "active"
613location counter.
614
615
616File: as.info, Node: bss, Prev: Sub-Sections, Up: Sections
617
618bss Section
619===========
620
621 The bss section is used for local common variable storage. You may
622allocate address space in the bss section, but you may not dictate data
623to load into it before your program executes. When your program starts
624running, all the contents of the bss section are zeroed bytes.
625
626 The `.lcomm' pseudo-op defines a symbol in the bss section; see
627*Note `.lcomm': Lcomm.
628
629 The `.comm' pseudo-op may be used to declare a common symbol, which
630is another form of uninitialized symbol; see *Note `.comm': Comm.
631
632 When assembling for a target which supports multiple sections, such
633as ELF or COFF, you may switch into the `.bss' section and define
634symbols as usual; see *Note `.section': Section. You may only assemble
635zero values into the section. Typically the section will only contain
636symbol definitions and `.skip' directives (*note `.skip': Skip.).
637
638
639File: as.info, Node: Symbols, Next: Expressions, Prev: Sections, Up: Top
640
641Symbols
642*******
643
644 Symbols are a central concept: the programmer uses symbols to name
645things, the linker uses symbols to link, and the debugger uses symbols
646to debug.
647
648 _Warning:_ `as' does not place symbols in the object file in the
649 same order they were declared. This may break some debuggers.
650
651* Menu:
652
653* Labels:: Labels
654* Setting Symbols:: Giving Symbols Other Values
655* Symbol Names:: Symbol Names
656* Dot:: The Special Dot Symbol
657* Symbol Attributes:: Symbol Attributes
658
659
660File: as.info, Node: Labels, Next: Setting Symbols, Up: Symbols
661
662Labels
663======
664
665 A "label" is written as a symbol immediately followed by a colon
666`:'. The symbol then represents the current value of the active
667location counter, and is, for example, a suitable instruction operand.
668You are warned if you use the same symbol to represent two different
669locations: the first definition overrides any other definitions.
670
671 On the HPPA, the usual form for a label need not be immediately
672followed by a colon, but instead must start in column zero. Only one
673label may be defined on a single line. To work around this, the HPPA
674version of `as' also provides a special directive `.label' for defining
675labels more flexibly.
676
677
678File: as.info, Node: Setting Symbols, Next: Symbol Names, Prev: Labels, Up: Symbols
679
680Giving Symbols Other Values
681===========================
682
683 A symbol can be given an arbitrary value by writing a symbol,
684followed by an equals sign `=', followed by an expression (*note
685Expressions::). This is equivalent to using the `.set' directive.
686*Note `.set': Set.
687
688
689File: as.info, Node: Symbol Names, Next: Dot, Prev: Setting Symbols, Up: Symbols
690
691Symbol Names
692============
693
694 Symbol names begin with a letter or with one of `._'. On most
695machines, you can also use `$' in symbol names; exceptions are noted in
696*Note Machine Dependencies::. That character may be followed by any
697string of digits, letters, dollar signs (unless otherwise noted in
698*Note Machine Dependencies::), and underscores. For the AMD 29K
699family, `?' is also allowed in the body of a symbol name, though not at
700its beginning.
701
702 Case of letters is significant: `foo' is a different symbol name
703than `Foo'.
704
705 Each symbol has exactly one name. Each name in an assembly language
706program refers to exactly one symbol. You may use that symbol name any
707number of times in a program.
708
709Local Symbol Names
710------------------
711
712 Local symbols help compilers and programmers use names temporarily.
713They create symbols which are guaranteed to be unique over the entire
714scope of the input source code and which can be referred to by a simple
715notation. To define a local symbol, write a label of the form `N:'
716(where N represents any positive integer). To refer to the most recent
717previous definition of that symbol write `Nb', using the same number as
718when you defined the label. To refer to the next definition of a local
719label, write `Nf'-- The `b' stands for"backwards" and the `f' stands
720for "forwards".
721
722 There is no restriction on how you can use these labels, and you can
723reuse them too. So that it is possible to repeatedly define the same
724local label (using the same number `N'), although you can only refer to
725the most recently defined local label of that number (for a backwards
726reference) or the next definition of a specific local label for a
727forward reference. It is also worth noting that the first 10 local
728labels (`0:'...`9:') are implemented in a slightly more efficient
729manner than the others.
730
731 Here is an example:
732
733 1: branch 1f
734 2: branch 1b
735 1: branch 2f
736 2: branch 1b
737
738 Which is the equivalent of:
739
740 label_1: branch label_3
741 label_2: branch label_1
742 label_3: branch label_4
743 label_4: branch label_3
744
745 Local symbol names are only a notational device. They are
746immediately transformed into more conventional symbol names before the
747assembler uses them. The symbol names stored in the symbol table,
748appearing in error messages and optionally emitted to the object file.
749The names are constructed using these parts:
750
751`L'
752 All local labels begin with `L'. Normally both `as' and `ld'
753 forget symbols that start with `L'. These labels are used for
754 symbols you are never intended to see. If you use the `-L' option
755 then `as' retains these symbols in the object file. If you also
756 instruct `ld' to retain these symbols, you may use them in
757 debugging.
758
759`NUMBER'
760 This is the number that was used in the local label definition.
761 So if the label is written `55:' then the number is `55'.
762
763`C-B'
764 This unusual character is included so you do not accidentally
765 invent a symbol of the same name. The character has ASCII value
766 of `\002' (control-B).
767
768`_ordinal number_'
769 This is a serial number to keep the labels distinct. The first
770 definition of `0:' gets the number `1'. The 15th definition of
771 `0:' gets the number `15', and so on. Likewise the first
772 definition of `1:' gets the number `1' and its 15th defintion gets
773 `15' as well.
774
775 So for example, the first `1:' is named `L1C-B1', the 44th `3:' is
776named `L3C-B44'.
777
778Dollar Local Labels
779-------------------
780
781 `as' also supports an even more local form of local labels called
782dollar labels. These labels go out of scope (ie they become undefined)
783as soon as a non-local label is defined. Thus they remain valid for
784only a small region of the input source code. Normal local labels, by
785contrast, remain in scope for the entire file, or until they are
786redefined by another occurrence of the same local label.
787
788 Dollar labels are defined in exactly the same way as ordinary local
789labels, except that instead of being terminated by a colon, they are
790terminated by a dollar sign. eg `55$'.
791
792 They can also be distinguished from ordinary local labels by their
793transformed name which uses ASCII character `\001' (control-A) as the
794magic character to distinguish them from ordinary labels. Thus the 5th
795defintion of `6$' is named `L6C-A5'.
796
797
798File: as.info, Node: Dot, Next: Symbol Attributes, Prev: Symbol Names, Up: Symbols
799
800The Special Dot Symbol
801======================
802
803 The special symbol `.' refers to the current address that `as' is
804assembling into. Thus, the expression `melvin: .long .' defines
805`melvin' to contain its own address. Assigning a value to `.' is
806treated the same as a `.org' directive. Thus, the expression `.=.+4'
807is the same as saying `.space 4'.
808
809
810File: as.info, Node: Symbol Attributes, Prev: Dot, Up: Symbols
811
812Symbol Attributes
813=================
814
815 Every symbol has, as well as its name, the attributes "Value" and
816"Type". Depending on output format, symbols can also have auxiliary
817attributes.
818
819 If you use a symbol without defining it, `as' assumes zero for all
820these attributes, and probably won't warn you. This makes the symbol
821an externally defined symbol, which is generally what you would want.
822
823* Menu:
824
825* Symbol Value:: Value
826* Symbol Type:: Type
827
828
829* a.out Symbols:: Symbol Attributes: `a.out'
830
831* COFF Symbols:: Symbol Attributes for COFF
832
833* SOM Symbols:: Symbol Attributes for SOM
834
835
836File: as.info, Node: Symbol Value, Next: Symbol Type, Up: Symbol Attributes
837
838Value
839-----
840
841 The value of a symbol is (usually) 32 bits. For a symbol which
842labels a location in the text, data, bss or absolute sections the value
843is the number of addresses from the start of that section to the label.
844Naturally for text, data and bss sections the value of a symbol changes
845as `ld' changes section base addresses during linking. Absolute
846symbols' values do not change during linking: that is why they are
847called absolute.
848
849 The value of an undefined symbol is treated in a special way. If it
850is 0 then the symbol is not defined in this assembler source file, and
851`ld' tries to determine its value from other files linked into the same
852program. You make this kind of symbol simply by mentioning a symbol
853name without defining it. A non-zero value represents a `.comm' common
854declaration. The value is how much common storage to reserve, in bytes
855(addresses). The symbol refers to the first address of the allocated
856storage.
857
858
859File: as.info, Node: Symbol Type, Next: a.out Symbols, Prev: Symbol Value, Up: Symbol Attributes
860
861Type
862----
863
864 The type attribute of a symbol contains relocation (section)
865information, any flag settings indicating that a symbol is external, and
866(optionally), other information for linkers and debuggers. The exact
867format depends on the object-code output format in use.
868
869
870File: as.info, Node: a.out Symbols, Next: COFF Symbols, Prev: Symbol Type, Up: Symbol Attributes
871
872Symbol Attributes: `a.out'
873--------------------------
874
875* Menu:
876
877* Symbol Desc:: Descriptor
878* Symbol Other:: Other
879
880
881File: as.info, Node: Symbol Desc, Next: Symbol Other, Up: a.out Symbols
882
883Descriptor
884..........
885
886 This is an arbitrary 16-bit value. You may establish a symbol's
887descriptor value by using a `.desc' statement (*note `.desc': Desc.).
888A descriptor value means nothing to `as'.
889
890
891File: as.info, Node: Symbol Other, Prev: Symbol Desc, Up: a.out Symbols
892
893Other
894.....
895
896 This is an arbitrary 8-bit value. It means nothing to `as'.
897
898
899File: as.info, Node: COFF Symbols, Next: SOM Symbols, Prev: a.out Symbols, Up: Symbol Attributes
900
901Symbol Attributes for COFF
902--------------------------
903
904 The COFF format supports a multitude of auxiliary symbol attributes;
905like the primary symbol attributes, they are set between `.def' and
906`.endef' directives.
907
908Primary Attributes
909..................
910
911 The symbol name is set with `.def'; the value and type,
912respectively, with `.val' and `.type'.
913
914Auxiliary Attributes
915....................
916
917 The `as' directives `.dim', `.line', `.scl', `.size', and `.tag' can
918generate auxiliary symbol table information for COFF.
919
920
921File: as.info, Node: SOM Symbols, Prev: COFF Symbols, Up: Symbol Attributes
922
923Symbol Attributes for SOM
924-------------------------
925
926 The SOM format for the HPPA supports a multitude of symbol
927attributes set with the `.EXPORT' and `.IMPORT' directives.
928
929 The attributes are described in `HP9000 Series 800 Assembly Language
930Reference Manual' (HP 92432-90001) under the `IMPORT' and `EXPORT'
931assembler directive documentation.
932
933
934File: as.info, Node: Expressions, Next: Pseudo Ops, Prev: Symbols, Up: Top
935
936Expressions
937***********
938
939 An "expression" specifies an address or numeric value. Whitespace
940may precede and/or follow an expression.
941
942 The result of an expression must be an absolute number, or else an
943offset into a particular section. If an expression is not absolute,
944and there is not enough information when `as' sees the expression to
945know its section, a second pass over the source program might be
946necessary to interpret the expression--but the second pass is currently
947not implemented. `as' aborts with an error message in this situation.
948
949* Menu:
950
951* Empty Exprs:: Empty Expressions
952* Integer Exprs:: Integer Expressions
953
954
955File: as.info, Node: Empty Exprs, Next: Integer Exprs, Up: Expressions
956
957Empty Expressions
958=================
959
960 An empty expression has no value: it is just whitespace or null.
961Wherever an absolute expression is required, you may omit the
962expression, and `as' assumes a value of (absolute) 0. This is
963compatible with other assemblers.
964
965
966File: as.info, Node: Integer Exprs, Prev: Empty Exprs, Up: Expressions
967
968Integer Expressions
969===================
970
971 An "integer expression" is one or more _arguments_ delimited by
972_operators_.
973
974* Menu:
975
976* Arguments:: Arguments
977* Operators:: Operators
978* Prefix Ops:: Prefix Operators
979* Infix Ops:: Infix Operators
980
981
982File: as.info, Node: Arguments, Next: Operators, Up: Integer Exprs
983
984Arguments
985---------
986
987 "Arguments" are symbols, numbers or subexpressions. In other
988contexts arguments are sometimes called "arithmetic operands". In this
989manual, to avoid confusing them with the "instruction operands" of the
990machine language, we use the term "argument" to refer to parts of
991expressions only, reserving the word "operand" to refer only to machine
992instruction operands.
993
994 Symbols are evaluated to yield {SECTION NNN} where SECTION is one of
995text, data, bss, absolute, or undefined. NNN is a signed, 2's
996complement 32 bit integer.
997
998 Numbers are usually integers.
999
1000 A number can be a flonum or bignum. In this case, you are warned
1001that only the low order 32 bits are used, and `as' pretends these 32
1002bits are an integer. You may write integer-manipulating instructions
1003that act on exotic constants, compatible with other assemblers.
1004
1005 Subexpressions are a left parenthesis `(' followed by an integer
1006expression, followed by a right parenthesis `)'; or a prefix operator
1007followed by an argument.
1008
1009
1010File: as.info, Node: Operators, Next: Prefix Ops, Prev: Arguments, Up: Integer Exprs
1011
1012Operators
1013---------
1014
1015 "Operators" are arithmetic functions, like `+' or `%'. Prefix
1016operators are followed by an argument. Infix operators appear between
1017their arguments. Operators may be preceded and/or followed by
1018whitespace.
1019
1020
1021File: as.info, Node: Prefix Ops, Next: Infix Ops, Prev: Operators, Up: Integer Exprs
1022
1023Prefix Operator
1024---------------
1025
1026 `as' has the following "prefix operators". They each take one
1027argument, which must be absolute.
1028
1029`-'
1030 "Negation". Two's complement negation.
1031
1032`~'
1033 "Complementation". Bitwise not.
1034
1035
1036File: as.info, Node: Infix Ops, Prev: Prefix Ops, Up: Integer Exprs
1037
1038Infix Operators
1039---------------
1040
1041 "Infix operators" take two arguments, one on either side. Operators
1042have precedence, but operations with equal precedence are performed left
1043to right. Apart from `+' or `-', both arguments must be absolute, and
1044the result is absolute.
1045
1046 1. Highest Precedence
1047
1048 `*'
1049 "Multiplication".
1050
1051 `/'
1052 "Division". Truncation is the same as the C operator `/'
1053
1054 `%'
1055 "Remainder".
1056
1057 `<'
1058 `<<'
1059 "Shift Left". Same as the C operator `<<'.
1060
1061 `>'
1062 `>>'
1063 "Shift Right". Same as the C operator `>>'.
1064
1065 2. Intermediate precedence
1066
1067 `|'
1068 "Bitwise Inclusive Or".
1069
1070 `&'
1071 "Bitwise And".
1072
1073 `^'
1074 "Bitwise Exclusive Or".
1075
1076 `!'
1077 "Bitwise Or Not".
1078
1079 3. Low Precedence
1080
1081 `+'
1082 "Addition". If either argument is absolute, the result has
1083 the section of the other argument. You may not add together
1084 arguments from different sections.
1085
1086 `-'
1087 "Subtraction". If the right argument is absolute, the result
1088 has the section of the left argument. If both arguments are
1089 in the same section, the result is absolute. You may not
1090 subtract arguments from different sections.
1091
1092 `=='
1093 "Is Equal To"
1094
1095 `<>'
1096 "Is Not Equal To"
1097
1098 `<'
1099 "Is Less Than"
1100
1101 `>'
1102 "Is Greater Than"
1103
1104 `>='
1105 "Is Greater Than Or Equal To"
1106
1107 `<='
1108 "Is Less Than Or Equal To"
1109
1110 The comparison operators can be used as infix operators. A
1111 true results has a value of -1 whereas a false result has a
1112 value of 0. Note, these operators perform signed
1113 comparisons.
1114
1115 4. Lowest Precedence
1116
1117 `&&'
1118 "Logical And".
1119
1120 `||'
1121 "Logical Or".
1122
1123 These two logical operations can be used to combine the
1124 results of sub expressions. Note, unlike the comparison
1125 operators a true result returns a value of 1 but a false
1126 results does still return 0. Also note that the logical or
1127 operator has a slightly lower precedence than logical and.
1128
1129
1130 In short, it's only meaningful to add or subtract the _offsets_ in an
1131address; you can only have a defined section in one of the two
1132arguments.
1133
1134
1135File: as.info, Node: Pseudo Ops, Next: Machine Dependencies, Prev: Expressions, Up: Top
1136
1137Assembler Directives
1138********************
1139
1140 All assembler directives have names that begin with a period (`.').
1141The rest of the name is letters, usually in lower case.
1142
1143 This chapter discusses directives that are available regardless of
1144the target machine configuration for the GNU assembler. Some machine
1145configurations provide additional directives. *Note Machine
1146Dependencies::.
1147
1148* Menu:
1149
1150* Abort:: `.abort'
1151
1152* ABORT:: `.ABORT'
1153
1154* Align:: `.align ABS-EXPR , ABS-EXPR'
1155* Ascii:: `.ascii "STRING"'...
1156* Asciz:: `.asciz "STRING"'...
1157* Balign:: `.balign ABS-EXPR , ABS-EXPR'
1158* Byte:: `.byte EXPRESSIONS'
1159* Comm:: `.comm SYMBOL , LENGTH '
1160* Data:: `.data SUBSECTION'
1161
1162* Def:: `.def NAME'
1163
1164* Desc:: `.desc SYMBOL, ABS-EXPRESSION'
1165
1166* Dim:: `.dim'
1167
1168* Double:: `.double FLONUMS'
1169* Eject:: `.eject'
1170* Else:: `.else'
1171* Elseif:: `.elseif'
1172* End:: `.end'
1173
1174* Endef:: `.endef'
1175
1176* Endfunc:: `.endfunc'
1177* Endif:: `.endif'
1178* Equ:: `.equ SYMBOL, EXPRESSION'
1179* Equiv:: `.equiv SYMBOL, EXPRESSION'
1180* Err:: `.err'
1181* Exitm:: `.exitm'
1182* Extern:: `.extern'
1183* Fail:: `.fail'
1184
1185* File:: `.file STRING'
1186
1187* Fill:: `.fill REPEAT , SIZE , VALUE'
1188* Float:: `.float FLONUMS'
1189* Func:: `.func'
1190* Global:: `.global SYMBOL', `.globl SYMBOL'
1191
1192* Hidden:: `.hidden NAMES'
1193
1194* hword:: `.hword EXPRESSIONS'
1195* Ident:: `.ident'
1196* If:: `.if ABSOLUTE EXPRESSION'
1197* Incbin:: `.incbin "FILE"[,SKIP[,COUNT]]'
1198* Include:: `.include "FILE"'
1199* Int:: `.int EXPRESSIONS'
1200
1201* Internal:: `.internal NAMES'
1202
1203* Irp:: `.irp SYMBOL,VALUES'...
1204* Irpc:: `.irpc SYMBOL,VALUES'...
1205* Lcomm:: `.lcomm SYMBOL , LENGTH'
1206* Lflags:: `.lflags'
1207
1208* Line:: `.line LINE-NUMBER'
1209
1210* Ln:: `.ln LINE-NUMBER'
1211* Linkonce:: `.linkonce [TYPE]'
1212* List:: `.list'
1213* Long:: `.long EXPRESSIONS'
1214
1215* Macro:: `.macro NAME ARGS'...
1216* MRI:: `.mri VAL'
1217* Nolist:: `.nolist'
1218* Octa:: `.octa BIGNUMS'
1219* Org:: `.org NEW-LC , FILL'
1220* P2align:: `.p2align ABS-EXPR , ABS-EXPR'
1221
1222* PopSection:: `.popsection'
1223* Previous:: `.previous'
1224
1225* Print:: `.print STRING'
1226
1227* Protected:: `.protected NAMES'
1228
1229* Psize:: `.psize LINES, COLUMNS'
1230* Purgem:: `.purgem NAME'
1231
1232* PushSection:: `.pushsection NAME'
1233
1234* Quad:: `.quad BIGNUMS'
1235* Rept:: `.rept COUNT'
1236* Sbttl:: `.sbttl "SUBHEADING"'
1237
1238* Scl:: `.scl CLASS'
1239
1240* Section:: `.section NAME'
1241
1242* Set:: `.set SYMBOL, EXPRESSION'
1243* Short:: `.short EXPRESSIONS'
1244* Single:: `.single FLONUMS'
1245
1246* Size:: `.size [NAME , EXPRESSION]'
1247
1248* Skip:: `.skip SIZE , FILL'
1249* Sleb128:: `.sleb128 EXPRESSIONS'
1250* Space:: `.space SIZE , FILL'
1251
1252* Stab:: `.stabd, .stabn, .stabs'
1253
1254* String:: `.string "STR"'
1255* Struct:: `.struct EXPRESSION'
1256
1257* SubSection:: `.subsection'
1258* Symver:: `.symver NAME,NAME2@NODENAME'
1259
1260
1261* Tag:: `.tag STRUCTNAME'
1262
1263* Text:: `.text SUBSECTION'
1264* Title:: `.title "HEADING"'
1265
1266* Type:: `.type <INT | NAME , TYPE DESCRIPTION>'
1267
1268* Uleb128:: `.uleb128 EXPRESSIONS'
1269
1270* Val:: `.val ADDR'
1271
1272
1273* Version:: `.version "STRING"'
1274* VTableEntry:: `.vtable_entry TABLE, OFFSET'
1275* VTableInherit:: `.vtable_inherit CHILD, PARENT'
1276* Weak:: `.weak NAMES'
1277
1278* Word:: `.word EXPRESSIONS'
1279* Deprecated:: Deprecated Directives
1280
1281
1282File: as.info, Node: Abort, Next: ABORT, Up: Pseudo Ops
1283
1284`.abort'
1285========
1286
1287 This directive stops the assembly immediately. It is for
1288compatibility with other assemblers. The original idea was that the
1289assembly language source would be piped into the assembler. If the
1290sender of the source quit, it could use this directive tells `as' to
1291quit also. One day `.abort' will not be supported.
1292
1293
1294File: as.info, Node: ABORT, Next: Align, Prev: Abort, Up: Pseudo Ops
1295
1296`.ABORT'
1297========
1298
1299 When producing COFF output, `as' accepts this directive as a synonym
1300for `.abort'.
1301
1302 When producing `b.out' output, `as' accepts this directive, but
1303ignores it.
1304
1305
1306File: as.info, Node: Align, Next: Ascii, Prev: ABORT, Up: Pseudo Ops
1307
1308`.align ABS-EXPR, ABS-EXPR, ABS-EXPR'
1309=====================================
1310
1311 Pad the location counter (in the current subsection) to a particular
1312storage boundary. The first expression (which must be absolute) is the
1313alignment required, as described below.
1314
1315 The second expression (also absolute) gives the fill value to be
1316stored in the padding bytes. It (and the comma) may be omitted. If it
1317is omitted, the padding bytes are normally zero. However, on some
1318systems, if the section is marked as containing code and the fill value
1319is omitted, the space is filled with no-op instructions.
1320
1321 The third expression is also absolute, and is also optional. If it
1322is present, it is the maximum number of bytes that should be skipped by
1323this alignment directive. If doing the alignment would require
1324skipping more bytes than the specified maximum, then the alignment is
1325not done at all. You can omit the fill value (the second argument)
1326entirely by simply using two commas after the required alignment; this
1327can be useful if you want the alignment to be filled with no-op
1328instructions when appropriate.
1329
1330 The way the required alignment is specified varies from system to
1331system. For the a29k, hppa, m68k, m88k, w65, sparc, Xtensa, and
1332Renesas / SuperH SH, and i386 using ELF format, the first expression is
1333the alignment request in bytes. For example `.align 8' advances the
1334location counter until it is a multiple of 8. If the location counter
1335is already a multiple of 8, no change is needed.
1336
1337 For other systems, including the i386 using a.out format, and the
1338arm and strongarm, it is the number of low-order zero bits the location
1339counter must have after advancement. For example `.align 3' advances
1340the location counter until it a multiple of 8. If the location counter
1341is already a multiple of 8, no change is needed.
1342
1343 This inconsistency is due to the different behaviors of the various
1344native assemblers for these systems which GAS must emulate. GAS also
1345provides `.balign' and `.p2align' directives, described later, which
1346have a consistent behavior across all architectures (but are specific
1347to GAS).
1348
1349
1350File: as.info, Node: Ascii, Next: Asciz, Prev: Align, Up: Pseudo Ops
1351
1352`.ascii "STRING"'...
1353====================
1354
1355 `.ascii' expects zero or more string literals (*note Strings::)
1356separated by commas. It assembles each string (with no automatic
1357trailing zero byte) into consecutive addresses.
1358
1359
1360File: as.info, Node: Asciz, Next: Balign, Prev: Ascii, Up: Pseudo Ops
1361
1362`.asciz "STRING"'...
1363====================
1364
1365 `.asciz' is just like `.ascii', but each string is followed by a
1366zero byte. The "z" in `.asciz' stands for "zero".
1367
Note: See TracBrowser for help on using the repository browser.