2024年6月10日发(作者:掌夜绿)
GNU汇编器as的用户手册。
Here is a brief summary of how to invoke as. For details, see section
Command-Line Options.
以下是调用as的命令概要,详细内容请见命令行选项一节。
as [ -a[cdhlns][=file] ] [ -D ] [ --defsym sym=val ]
[ -f ] [ --gstabs ] [ --help ] [ -I dir ] [ -J ] [ -K ] [ -L ]
[ --keep-locals ] [ -o objfile ] [ -R ] [ --statistics ] [ -v ]
[ -version ] [ --version ] [ -W ] [ -w ] [ -x ] [ -Z ]
[ -mbig-endian | -mlittle-endian ]
[ -m[arm]1 | -m[arm]2 | -m[arm]250 | -m[arm]3 | -m[arm]6 | -m[arm]7[t][[d]m[i]] ]
[ -m[arm]v2 | -m[arm]v2a | -m[arm]v3 | -m[arm]v3m | -m[arm]v4 | -m[arm]v4t ]
[ -mthumb | -mall ]
[ -mfpa10 | -mfpa11 | -mfpe-old | -mno-fpu ]
[ -EB | -EL ]
[ -mapcs-32 | -mapcs-26 ]
[ -O ]
[ -Av6 | -Av7 | -Av8 | -Asparclet | -Asparclite
-Av8plus | -Av8plusa | -Av9 | -Av9a ]
[ -xarch=v8plus | -xarch=v8plusa ] [ -bump ] [ -32 | -64 ]
[ -ACA | -ACA_A | -ACB | -ACC | -AKA | -AKB | -AKC | -AMC ]
[ -b ] [ -no-relax ]
[ -l ] [ -m68000 | -m68010 | -m68020 | ... ]
[ -nocpp ] [ -EL ] [ -EB ] [ -G num ] [ -mcpu=CPU ]
[ -mips1 ] [ -mips2 ] [ -mips3 ] [ -m4650 ] [ -no-m4650 ]
[ --trap ] [ --break ]
[ --emulation=name ]
[ -- | files ... ]
-a[cdhlmns]
Turn on listings, in any of a variety of ways:
打开清单输出选项,可以任意使用以下各种方法:
-ac
omit false conditionals
忽略假条件
-ad
omit debugging directives
忽略调试指示
-ah
include high-level source
包含高层源代码
-al
include assembly
包含汇编代码
-am
include macro expansions
包含宏扩展
-an
omit forms processing
忽略forms处理
-as
include symbols
包含符号表
=file
set the name of the listing file
设置清单文件名
You may combine these options; for example, use `-aln' for assembly listing
without forms processing. The `=file' option, if used, must be the last one.
By itself, `-a' defaults to `-ahls'.
你可以联合使用这些选项;例如,要获得未经过forms处理的汇编代码清单可使用 '-aln',
如果要使用 ‘=file’选项,它必须在最后一个位置,选项‘-a’缺省含义是'-ahls'。
-D
Ignored. This option is accepted for script compatibility with calls to other
assemblers.
忽略。为和使用其它汇编器的脚本兼容而保留。
--defsym sym=value
Define the symbol sym to be value before assembling the input file. value must
be an integer constant. As in C, a leading `0x' indicates a hexadecimal value,
and a leading `0' indicates an octal value.
处理输入文件前,定义符号sym的值为value。value必须是整形常量。同在'C'中一样,前导
字符'0x'标志十六进制值,前导字符'0'标志八进制值。
-f
"fast"---skip whitespace and comment preprocessing (assume source is compiler
output).
“加速处理”---跳过空白和注释处理(假定输入源文件是一可信赖的编译器产生的)
--gstabs
Generate stabs debugging information for each assembler line. This may help
debugging assembler code, if the debugger can handle it.
生成逐行的stabs格式调试信息,如果调试器可以处理这种格式的信息将有助于汇编代码调
试。
--help
Print a summary of the command line options and exit.
打印命令行选项概要后退出。
-I dir
Add directory dir to the search list for .include directives.
为.include汇编指示增加搜索目录。
-J
Don't warn about signed overflow.
不警告符号溢出。
-K
Issue warnings when difference tables altered for long displacements.
长跳切换表时发出警告。
-L
--keep-locals
Keep (in the symbol table) local symbols. On traditional systems these
start with `L', but different systems have different local label prefixes.
保留(符号表中的)局部符号。在传统的系统中这些符号有'L'前缀,但是在不同
的系统中有不同的局部符号前缀。
-o objfile
Name the object-file output from as objfile.
as输出的目标文件名。
-R
Fold the data section into the text section.
交迭数据段和代码段。
--statistics
Print the maximum space (in bytes) and total time (in seconds) used by
assembly.
打印汇编过程使用的最大空间(字节)和总计时间(秒)。
--strip-local-absolute
Remove local absolute symbols from the outgoing symbol table.
从输出符号表中移除局部绝对符号。
-v
-version
Print the as version.
打印as的版本。
--version
Print the as version and exit.
打印as的版本后退出。
-W
Suppress warning messages.
压制警告信息。
-w
Ignored.
忽略。
-x
Ignored.
忽略。
-Z
Generate an object file even after errors.
即使发生错误也要生成目标文件。
-- | files ...
Standard input, or source files to assemble.
标准输入或汇编源文件。
The following options are available when as is configured for an ARC processor.
以下选项,当配置as为ARC处理器时有效。
-mbig-endian
Generate "big endian" format output.
生成“大端”格式输出。
-mlittle-endian
Generate "little endian" format output.
生成“小端”格式输出。
The following options are available when as is configured for the ARM processor
family.
以下选项,当配置as为ARM处理器族时有效。
-m[arm]1 | -m[arm]2 | -m[arm]250 | -m[arm]3 | -m[arm]6 | -m[arm]7[t][[d]m] |
-m[arm]v2 | -m[arm]v2a | -m[arm]v3 | -m[arm]v3m | -m[arm]v4 | -m[arm]v4t
Specify which variant of the ARM architecture is the target.
指定不同的目标架构。
-mthumb | -mall
Enable or disable Thumb only instruction decoding.
禁止或使能仅用Thumb指令译码。
-mfpa10 | -mfpa11 | -mfpe-old | -mno-fpu
Select which Floating Point architcture is the target.
选择不同的浮点目标架构。
-mapcs-32 | -mapcs-26
Select which procedure calling convention is in use.
选择使用的调用习惯。
-EB | -EL
Select either big-endian (-EB) or little-endian (-EL) output.
选择大端(-EB)或小端(-EL)输出格式。
The following options are available when as is configured for a D10V processor.
以下选项,当配置as为D10V处理器时有效。
-O
Optimize output by parallelizing instructions.
优化并行指令输出。
The following options are available when as is configured for the Intel 80960
processor.
以下选项,当配置as为英特尔80960处理器时有效。
-ACA | -ACA_A | -ACB | -ACC | -AKA | -AKB | -AKC | -AMC
Specify which variant of the 960 architecture is the target.
指定不同的960目标架构。
-b
Add code to collect statistics about branches taken.
加入分支统计代码。
-no-relax
Do not alter compare-and-branch instructions for long displacements; error if
necessary.
不为长跳改变比较和分支指令;如果必须改变就发出错误指示。
The following options are available when as is configured for the Motorola 68000
series.
以下选项,当配置as为摩托罗拉68000系列处理器时有效。
-l
Shorten references to undefined symbols, to one word instead of two.
缩写未定义符号引用,用单字代替双字。
-m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060
| -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -mcpu32 | -m5200
Specify what processor in the 68000 family is the target. The default is
normally the 68020, but this can be changed at configuration time.
指定68000族的目标架构,缺省是普通的68020,可在配置时更改。
-m68881 | -m68882 | -mno-68881 | -mno-68882
The target machine does (or does not) have a floating-point coprocessor. The
default is to assume a coprocessor for 68020, 68030, and cpu32. Although the
basic 68000 is not compatible with the 68881, a combination of the two can be
specified, since it's possible to do emulation of the coprocessor instructions
with the main processor.
目标机有或没有浮点协处理器。缺省假定有68020,68030和cpu32的协处理器。虽然基本
的
68000和68881不兼容,但是通过主处理器的协处理器指令模拟,两者还是可以联合使用。
-m68851 | -mno-68851
The target machine does (or does not) have a memory-management unit
coprocessor. The default is to assume an MMU for 68020 and up.
目标机有或没有内存管理单元协处理器。缺省假定有68020或以上的内存管理单元。
The following options are available when as is configured for the SPARC
architecture:
以下选项,当配置as为SPARC架构处理器时有效。
-Av6 | -Av7 | -Av8 | -Asparclet | -Asparclite
-Av8plus | -Av8plusa | -Av9 | -Av9a
Explicitly select a variant of the SPARC architecture. `-Av8plus' and
`-Av8plusa' select a 32 bit environment. `-Av9' and `-Av9a' select a 64 bit
environment. `-Av8plusa' and `-Av9a' enable the SPARC V9 instruction set with
UltraSPARC extensions.
明确选择不同的SPARC架构。'-Av8plus'和'-Av8plusa' 选择32位环境。'-Av9' 和 '-Av9a'
选择64位环境。'-Av8plusa' 和 '-Av9a' 使用带UltraSPARC扩展的SPARC V9指令集。
-xarch=v8plus | -xarch=v8plusa
For compatibility with the Solaris v9 assembler. These options are equivalent
to -Av8plus and -Av8plusa, respectively.
兼容Solaris V9汇编器。这些选项分别等于-Av8plus和-Av8plusa。
-bump
Warn when the assembler switches to another architecture.
汇编器转换到其他架构时发出警告。
The following options are available when as is configured for a MIPS processor.
以下选项,当配置as为MIPS处理器时有效。
-G num
This option sets the largest size of an object that can be referenced
implicitly with the gp register. It is only accepted for targets that use
ECOFF format, such as a DECstation running Ultrix. The default value is 8.
设置可以被gp寄存器隐含引用对象的最大尺寸。这只是为目标代码格式为ECOFF的情况
而设置,例如运行Ultrix的DECstation。缺省值是8。
-EB
Generate "big endian" format output.
生成“大端”格式输出。
-EL
Generate "little endian" format output.
生成“小端”格式输出。
-mips1
-mips2
-mips3
Generate code for a particular MIPS Instruction Set Architecture level.
`-mips1' corresponds to the R2000 and R3000 processors, `-mips2' to the R6000
processor, and `-mips3' to the R4000 processor.
生成特定MIPS指令集架构层的代码。'-mips1'对应R2000和R3000处理器,'-mips2'对应R6000
处理器,'-mips3'对应R4000处理器。
-m4650
-no-m4650
Generate code for the MIPS R4650 chip. This tells the assembler to accept the
`mad' and `madu' instruction, and to not schedule `nop' instructions around
accesses to the `HI' and `LO' registers. `-no-m4650' turns off this option.
生成MIPS R4650芯片代码。告诉汇编器接受'mad'和'madu'指令,访问'HI'和'LO'寄存器时
不调整'nop'指令。'-no-m4650'关闭这个选项。
-mcpu=CPU
Generate code for a particular MIPS cpu. This has little effect on the
assembler, but it is passed by gcc.
生成特定MIPS cpu的代码,如果输入文件是经过gcc相应处理而得,对汇编器的影响不大。
--emulation=name
This option causes as to emulate as configured for some other target, in all
respects, including output format (choosing between ELF and ECOFF only),
handling of pseudo-opcodes which may generate debugging information or store
symbol table information, and default endianness. The available configuration
names are: `mipsecoff', `mipself', `mipslecoff', `mipsbecoff', `mipslelf',
`mipsbelf'. The first two do not alter the default endianness from that of the
primary target for which the assembler was configured; the others change the
default to little- or big-endian as indicated by the `b' or `l' in the name.
Using `-EB' or `-EL' will override the endianness selection in any case. This
option is currently supported only when the primary target as is configured
for is a MIPS ELF or ECOFF target. Furthermore, the primary target or others
specified with `--enable-targets=...' at configuration time must include
support for the other format, if both are to be available. For example, the
Irix 5 configuration includes support for both. Eventually, this option will
support more configurations, with more fine-grained control over the
assembler's behavior, and will be supported for more processors.
模拟其他目标架构,包括输出文件格式(ELF或ECOFF二者其一),伪指令处理,生成的调
试
信息,存储的符号表信息,以及缺省的大小端格式。有效的配置名是:`mipsecoff', `mipself',
`mipslecoff', `mipsbecoff', `mipslelf',`mipsbelf'。前两个不改变相应目标的缺省大小端格式。
其它的分别依据其配置名中包含的字符'b'或'l'改变目标代码的大小端格式。这个选项当前
只支持主目标代码格式是MIPS ELF或ECOFF的情况。另外,如果二者都是有效格式,主
目标格式或配
置时通过'--enable-targets=...' 指定的格式必须包含支持另一格式。例如Irix 5配置包含对二
者
的支持。最终这个选项将会支持更多的配置,对汇编器行为进行更细微的控制,而且会支持
更多的处理器。
-nocpp
as ignores this option. It is accepted for compatibility with the native
tools.
as忽略这个选项。这是为兼容本地工具而设。
--trap
--no-trap
--break
--no-break
Control how to deal with multiplication overflow and division by zero.
`--trap' or `--no-break' (which are synonyms) take a trap exception (and only
work for Instruction Set Architecture level 2 and higher); `--break' or
`--no-trap' (also synonyms, and the default) take a break exception.
控制如何处理乘法溢出和除零。'--trap'或'--no-break'(二者意义相同)导致陷阱(trap)异常
(只工作在指令集架构层2或更高);'--break'或'--no-trap'(二者意义相同,并且是缺省选项)
导致终止(break)异常。
Structure of this Manual
手册结构
This manual is intended to describe what you need to know to use GNU as. We
cover the syntax expected in source files, including notation for symbols,
constants, and expressions; the directives that as understands; and of course
how to invoke as.
本手册的目的是介绍GNU as的使用知识。包括源文件中的语法,符号标记,表达式,as能
够理解
和处理的指示标记;当然还有如何调用as。
This manual also describes some of the machine-dependent features of various
flavors of the assembler.
手册也介绍本汇编器在机器相关情况下的各种使用特点。
On the other hand, this manual is not intended as an introduction to programming
in assembly language--let alone programming in general! In a similar vein, we
make no attempt to introduce the machine architecture; we do not describe the
instruction set, standard mnemonics, registers or addressing modes that are
standard to a particular architecture. You may want to consult the
manufacturer's machine architecture manual for this information.
但另一方面,手册并不介绍汇编语言编程,同样也不会介绍特定机器架构的指令集,标准内
存,寄存器,
以及寻址方式。这方面信息您可以参考特定机器架构的生产商手册。
The GNU Assembler
GNU汇编器
GNU as is really a family of assemblers. If you use (or have used) the GNU
assembler on one architecture, you should find a fairly similar environment when
you use it on another architecture. Each version has much in common with the
others, including object file formats, most assembler directives (often called
pseudo-ops) and assembler syntax.
GNU as 实际上是一个汇编器族。如果你在一种架构上使用(或已经使用过)GNU汇编器,当
您
使用其它架构时,你会发现一个你熟悉的环境。每一个版本和其他版本有很大的共同之处,
包括目标文件格式,大部分的汇编指示(常被称作伪指令pseudo-ops)和汇编语法。
as is primarily intended to assemble the output of the GNU C compiler gcc for
use by the linker ld. Nevertheless, we've tried to make as assemble correctly
everything that other assemblers for the same machine would assemble. Any
exceptions are documented explicitly (see section Machine Dependent Features).
This doesn't mean as always uses the same syntax as another assembler for the
same architecture; for example, we know of several incompatible versions of
680x0 assembly language syntax.
as的主要目的是处理GNU的C编译器gcc的输出文件以便生成目标文件,从而被连接器ld
使用。
但是,我们尽量使as能够正确的汇编为其他汇编器生成的文件。例外情况有专门文档介绍(
见机器相关部分);但是这并不是意味着对于相同架构as和其它汇编器使用相同的语法;例
如:
我们知道有几个相互不兼容的680x0汇编语言语法。
Unlike older assemblers, as is designed to assemble a source program in one pass
of the source file. This has a subtle impact on the .org directive (see section
.org new-lc , fill).
和其他老汇编器不同,as被设计成对汇编源文件进行一次性处理。这对汇编指示.org将产生
微妙的影响(见.org new-lc ,fill部分)。
Object File Formats
目标文件格式
The GNU assembler can be configured to produce several alternative object file
formats. For the most part, this does not affect how you write assembly language
programs; but directives for debugging symbols are typically different in
different file formats. See section Symbol Attributes. On the machine specific,
as can be configured to produce either or COFF format object files. On the
machine specific, as can be configured to produce either or COFF format
object files. On the machine specific, as can be configured to produce either
SOM or ELF format object files.
GNU汇编器可以被配置成处理不同的目标文件格式。大部分情况下,并不影响你的汇编语
言编程;
但是,典型的符号调试汇编指示在不同的文件格式中不同。见符号属性部分。在某些机器
as可被
配制成生成或COFF目标文件,在某些机器as可被配制成生成或COFF目标文
件,
在某些机器as可被配制成生成SOM或ELF格式目标文件。
Command Line
命令行
After the program name as, the command line may contain options and file names.
Options may appear in any order, and may be before, after, or between file
names. The order of file names is significant.
程序名as之后的命令行包含选项和文件名,选项可以以任何顺序出现,可以在文件名之前
之后
或是其间出现,但是文件名出现的先后顺序是有含义的。
`--' (two hyphens) by itself names the standard input file explicitly, as one of
the files for as to assemble.
'--'(双链字符)的含义是标准输入文件,这时汇编器从标准输入获得输入文件。
Except for `--' any command line argument that begins with a hyphen (`-') is an
option. Each option changes the behavior of as. No option changes the way
another option works. An option is a `-' followed by one or more letters; the
case of the letter is important. All options are optional.
Some options expect exactly one file name to follow them. The file name may
either immediately follow the option's letter (compatible with older assemblers)
or it may be the next command argument (GNU standard). These two command lines
are equivalent:
as -o my-object-file.o mumble.s
as -omy-object-file.o mumble.s
除了'--'以外,任何以链字符'-'开始的参数都是选项参数。每一个选项都会更改as的处理方
式。
任何选项都不会更改其他选项的工作方式。每个选项都是以链字符'-'开始,后跟一个或多个
字符;字符大小写的含义是有区分的。所有的选项都是可选的。有些选项后面必须有正确的
文件
名跟随。文件名必须立即跟随在选项字符后面或者是这一选项参数后面紧跟着的那个参数位
子。
以下两个命令行是等价的:
as -o my-object-file.o mumble.s
as -omy-object-file.o mumble.s
Input Files
输入文件
We use the phrase source program, abbreviated source, to describe the program
input to one run of as. The program may be in one or more files; how the source
is partitioned into files doesn't change the meaning of the source.
The source program is a concatenation of the text in all the files, in the order
specified.
被as处理的汇编语言源程序可以放在一个或多个文件中,这并不改变源程序的内在含义,
源程序
可以被看作是所有这些文件按一定的顺序将文件中的文本串接而成。
Each time you run as it assembles exactly one source program. The source program
is made up of one or more files. (The standard input is also a file.)
You give as a command line that has zero or more input file names. The input
files are read (from left file name to right). A command line argument (in any
position) that has no special meaning is taken to be an input file name.
If you give as no file names it attempts to read one input file from the as
standard input, which is normally your terminal. You may have to type ctl-D to
tell as there is no more program to assemble.
Use `--' if you need to explicitly name the standard input file in your command
line.
If the source is empty, as produces a small, empty object file.
as每次处理一个源程序,源程序有一个或多个文件构成(标准输入也是一个文件),你可以在
命令
行给出或不给源文件名,如果给出多个源文件名,as就依次读入他们(从左到右)。命令行参
数(
任何位子)如果没有特别的定义就被当作一个输入文件名。如果你没有给出文件名,as就尝
试从标准
输入获得输入文件,通常就是从你的终端。你得通过键入ctl-d告诉as输入文件结束。你可
以在命令
行中使用'--'来明确告诉as你使用标准输入作为你的输入文件。如果源文件为空,as将产生
一个小的
空目标文件。
Filenames and Line-numbers
文件名和行号
There are two ways of locating a line in the input file (or files) and either
may be used in reporting error messages. One way refers to a line number in a
physical file; the other refers to a line number in a "logical" file. See
section Error and Warning Messages.
有两种方法来定位文件的行号,这些行号可以用来报告错误信息。一种是物理文件行号,
一种是逻辑文件行号。请参考错误和警告信息部分。
Physical files are those files named in the command line given to as.
Logical files are simply names declared explicitly by assembler directives; they
bear no relation to physical files. Logical file names help error messages
reflect the original source file, when as source is itself synthesized from
other files. See section .app-file string.
物理文件名指那些你在命令行中给出的文件名。逻辑文件名是指你在源文件中通过特定的汇
编指示
明确指定的简记名称。当as的源文件来自其他文件的合成时,逻辑文件名可以帮助定位产
生错误的
原始文件。
Output (Object) File
输出(目标)文件
Every time you run as it produces an output file, which is your assembly
language program translated into numbers. This file is the object file. Its
default name is , or when as is configured for the Intel 80960. You
can give it another name by using the -o option. Conventionally, object file
names end with `.o'. The default name is used for historical reasons: older
assemblers were capable of assembling self-contained programs directly into a
runnable program. (For some formats, this isn't currently possible, but it can
be done for the format.)
The object file is meant for input to the linker ld. It contains assembled
program code, information to help ld integrate the assembled program into a
runnable file, and (optionally) symbolic information for the debugger.
每次运行as都会产生输出文件,输出文件就是汇编器将你的汇编语言源程序翻译的结果。
这个由as产生的文件就是目标文件,却省文件名是,如果处理器配置为英特尔80960
缺省
就是。你可以通过设置-o选项更改输出文件名。习惯上目标文件名都以'.o'结尾。缺省
文件
名的使用是由于历史原因:老的汇编器可以从完善的汇编语言源程序直接生成可执行程序。
(
对有些格式来说这是不可能的,但是有些格式就可以,比如格式)产生目标文件的目的
是提供给
连接程序ld使用,以便生成可执行程序。目标文件一般只包含汇编过的程序代码,帮助ld
组织合并
目标文件以便生成可执行文件的信息,以及帮助调试器进行调试的信息。
Error and Warning Messages
错误和警告信息
as may write warnings and error messages to the standard error file (usually
your terminal). This should not happen when a compiler runs as automatically.
Warnings report an assumption made so that as could keep assembling a flawed
program; errors report a grave problem that stops the assembly.
Warning messages have the format
file_name:NNN:Warning Message Text
(where NNN is a line number). If a logical file name has been given (see section
.app-file string) it is used for the filename, otherwise the name of the current
input file is used. If a logical line number was given (see section .line
line-number) (see section .ln line-number) then it is used to calculate the
number printed, otherwise the actual line in the current source file is printed.
The message text is intended to be self explanatory (in the grand Unix
tradition).
Error messages have the format
file_name:NNN:FATAL:Error Message Text
The file name and line number are derived as for warning messages. The actual
message text may be rather less explanatory because many of them aren't supposed
to happen.
as通常会写警告和错误信息到标准错误文件(通常就是你的终端),但是如果as是被编译器
自动调用
的情况除外。警告信息通常表明你的程序有缺点但不会终止汇编过程,错误信息一般表明你
的程序
有致命错误将停止汇编过程。
警告信息有如下格式:
文件名:NNN:警告信息文本
(NNN是行号)。如果给出逻辑文件名(见.app-file string)就使用逻辑文件名,没有就使用当前
的输
入文件名。如果给出逻辑行号(见.line line-number)(见.ln line-number)就使用逻辑行号,没有
就
使用文件中的真实行号。警告信息文本一般会表明产生警告的原因(Unix的伟大传统)。
错误信息有如下格式:
文件名:NNN:FATAL:错误信息文本
文件名和行号的产生方式和警告信息相同。错误信息文本一般不能很好的解释产生错误的原
因,因为
通常情况下都假定他们不会发生。
2 命令行选项
这一章讲述所有版本的gnu汇编器中可用的命令行选项,如果想了解特定机器体系结构的相
关选项,请看61页(第八章的机器相关性)
如果你是通过GNU 编译器(版本2)调用as,你可以使用‘-Wa’选项,把参数传给汇编
器,这些参数(包括选项-Wa)必须使用逗号分隔。例如:
gcc -c -g -O -Wa,-alh,-L file.c
这个例子传递了两个参数给汇编器:‘-alh’(以高级语言和汇编语言的形式生成清单到标准
输出)‘-L’(在符号表中保留局部符号)。通常你没必要使用‘-Wa‘选项,因为编译器把
很多命令行选项自动传递给汇编器。(你可以通过’-v‘选项使用GNU编译器,来确切了解
有什么选项被传递给编译过程,包括传递给汇编器的选项)
2.1 Enable Listings: -a[cdhlns]
2.1 开启清单选项:-a[cdhlns]
这些选项开启了汇编器的清单输出。如果只有‘-a’选项,代表需要生成高级语言,汇编语
言和符号清单。你可以用其他字母去选择特定的清单选项:‘-ah’需要生成一个高级语言清
单,'-al '需要生成一个输出程序的汇编语言清单,‘-as’需要生成符号表的清单。生成高级语
言清单需要使用一个‘-g‘之类的编译调试选项,汇编语言清单(’-al’)也需要上述调试
选项。
删去清单中汇编条件为false的语句,下列语句行不进行汇编:一个条件为false的.if语句块
(或是.ifdef语句块,或是其他的条件汇编语句块),条件为true的.if后面的那个.else语句块,
所有没有被汇编行都会从清单中删去。
使用选项‘-ad’删除清单中的调试命令。
一旦你使用了上述某个选项,你就可以使用.list ,.nolist,.psize,.title,和.sbttl 命令进一步控制清
单输出格式。选项‘-an’关闭所有清单表格的处理过程。如果你不需要输出清单,就不必
使用一个‘-a’系列的选项,那么清单控制命令就没有效果。
选项‘-a’后的字母可以合成一个选项(例如‘-aln’)。
注意,如果汇编源码来自标准输入(例如源码是由GCC创建,并且使用了‘-pipe’命令行
开关),则清单中不含有注释和预处理命令。这是因为只有在源代码必须被汇编器预处理后,
清单代码缓冲区才从标准输入中读取源代码行。这样减少了内存的使用,并且使生成的代码
更有效率。
2.2 -D
这个选项没什么作用,但as接受这个选项,使那些写给其他汇编器的脚本文件也能被as使
用。
2.3 Work Faster: -f
2.3 加快汇编:-f
只有在被汇编程序的源码是由可信任的编译器产生的情况下,才能使用‘-f’选项。 使用
选项‘-f’时,如果汇编器在汇编输入文件前要对它们进行空格和注释的预处理,则会终止
汇编器的汇编。
警告:如果文件事实上需要预处理时(如果它们包含有注释),而你使用了‘-f’,as将不能
正常工作。
2.4 .include search path: -I path
2.4 .include命令搜索路径的选项: -I path
使用这个选项给目录清单加一个路径path,这个目录清单是.Include命令在搜索指定文件使用
的,(见 7.37 [ .include],第44页)。 你可以视需要多次使用‘-I’来加入不同的路径。第一
个搜索的总是当前工作目录;然后,as安照命令行中的顺序(从左到右)搜索‘-I’选项指定
的目录。
2.5 Difference Tables: -K
altered
在as中使用‘.word sym1-sym2’形式的命令有时会改变生成的代码(参考Section 7.92
[ .word],page 59)。如果在遇到上述情况时您希望as会发出一个警告,您可以使用选项‘-K’。
2.6 Include Local Labels: -L
2.6包含局部标签:-L
以‘L’(必须大写)字母开头的标签叫做局部标签(参考Section 5.3 [Symbol Names],page 29)。
通常调试时你看不见它们,因为它们是供生成汇编源程序的程序(如编译器)使用的,而不
是为了引起你的注意。一般来讲as和ld丢弃这些标签,所以你不能用它们来调试。
这个选项让as在目标文件中保留那些‘L…’符号。一般如果你这样做了,你也应该让连接
器ld保留那些以符号名‘L’ 开头的符号。
默认情况下,以‘L’开始的标签是一个局部标签,不过每一个目标允许重新定义一个局部
标签的前缀。在HPPA上,局部标签以‘L$’开始。
2.7 Configuringh listing output: --listing
通过命令行开关‘-a‘可以开启汇编程序的清单功能(see
Section 2.1 [a], page 11)。这个功能使输入源文件和输出目标文件的16进制映象组合起来,
并且以清单文件的形式显示它们。清单的格式可以通过汇编源代码中的伪操作来控制(参考
Section 7.48 [List], page 47 ;Section 7.83 [Title], page 57 ;Section 7.64 [Sbttl], page 51 ;
Section 7.59 [Psize], page 50 ; Section 7.14 [Eject], page 40)也可以通过以下开关:
--listing-lhs-width=‘number’
设置16进制字节映象第一行的最大宽度,宽度单位为字(16位)。这个映象显示在清单输
出的左边。
--listing-lhs-width2=‘number’
由给定的源代码行生成的16进制字节映象,设置这个映象的除第1行外的所有行的最大宽
度,宽度单位为字。如果没有指定宽度值,那它默认等于‘--listing-lhs-width’的设定值。
如果两个开关都没指定,那么默认值是1。
--listing-rhs-width=‘number’
设置源代码行的最大宽度,宽度单位字符数,源代码显示在16进制映象旁边。默认宽度值
是100。源代码行显示在输出清单的右边。
--listing-cont-lines=‘number’
对于给定的一行源代码输入,设置16进制映象连续行数的最大值。默认值是4。
2.8 Assemble in MRI Compatibility Mode: -M
以MRI兼容模式汇编
选项 –M 或 –-mri 选择 MRI 兼容模式。它改变了 as 的语法和伪操作处理,使它兼容
于Microtec Research 的 ASM68K 或者 ASM960 (视配置目标而定)汇编器。这里没有给
出 MRI 语法具体形式,您可以查看 MRI 的手册。需要特别注意的是宏和宏参数的处理有
一些不同。这个选项的目的是允许使用 as 汇编现存的MRI汇编器代码。
与MRI的兼容工作没有做完。MRI 汇编器的具体操作依赖于目标文件格式,使用其他目标
文件格式不支持这些操作。要想支持这些需要分别增强目标文件格式。它们是:
•公共段中的全局符号
M68K的MRI汇编器允许使用公共段,公共段将被连接器合并。其它目标文件格式并不支
持使用公共段。 as 通过把公共段看成一个单独的普通符号来处理它。它允许在公共段中定
义局部符号,但是它不支持公共段中全局符号,因为没法描述它们。
•复杂重定向
MRI汇编器允许错误段址的重定向,允许联合了多个段的起始地址的重定向。其它目标文
件格式都不支持这些。
• END伪操作指定的启始地址
MRI中的END伪操作允许指定一个开始地址。其它目标文件格式不允许这么做。你也可以
对连接程序使用选项 ‘-e’来指定起始地址,也可以在连接脚本中指定。
IDNT, .ident and NAME伪操作
MRI 中的IDNT, .ident 和 NAME 伪操作给输出文件分配一个模块名。其它目标文件格式
不支持。
ORG 伪操作
m68k的MRI中ORG伪操作在一个给定的地址开辟一个具有独立地址的段。这和通常的 as
的 .ORG 伪操作不同,它在当前的段中改变定位。别的目标文件格式不支持独立段。因为
一个段的地址可能在连接脚本中分配。
还有一些MRI汇编器的功能as不支持,大体上,它们都难于实现,而且似乎无关紧要。其
中的一些特性可能在今后的版本中将会支持。
•EBCDIC strings
不支持EBCDIC 字符串。
•packed binary coded decimal
不支持包装BCD 码。这表示不支持 DC.P 和 DCB.P 伪操作。
•FEQU pseudo-op
不支持m68k 的 FEQU 伪操作。
•NOOBJ pseudo-op
不支持m68k 的 NOOBJ 伪操作。
•OPT branch control options
忽略 m68k 的OPT分支控制选项—B, BRS, BRB, BRL, 还有BRW。as 自动的放松所有的
分支(不管是向前还是向后)到一个合适的大小,所以这些选项不起作用。
•OPT list control options
以下m68k的OPT清单控制选项被忽略:C, CEX, CL, CRE, E, G, I, M, MEX, MC, MD, X.
•other OPT options
以下的m68k的OPT选项被忽略:NEST, O, OLD, OP, P, PCO, PCR, PCS, R.
•OPT D option is default
不象 MRI 汇编程序,m68k OPT的选项D是默认的。可以用选项 NOD 关闭它。
• XREF pseudo-op.
忽略m68k的XREF。
• .debug pseudo-op
不支持i960 的.debug伪操作。
•.extended pseudo-op
不支持 i960 的 .extended 伪操作。
•.list pseudo-op.
不支持 i960 的 .list 伪操作的各种选项。
•.optimize pseudo-op
不支持 i960 的 .optimize 伪操作。
•.output pseudo-op
不支持 i960 的 .output 伪操作。
•.setreal pseudo-op
不支持 i960 的 .setreal 伪操作。
2.9 Dependency tracking: --MD
2.9 相关性跟踪:--MD
as can generate a dependency file for the file it creates. This file consists of a single rule
suitable for make describing the dependencies of the main source file.
The rule is written to the file named in its argument.
This feature is used in the automatic updating of makefiles.
as 能为它创造的文件产生一个从属文件。这个文件包括一个合适的单一规则,用来描述主
要的源文件的依赖性。
规则写进文件,文件名规则的参数中指定。
自动更新 makefiles 使用了这个功能。
2.10 Name the Object File: -o
2.10 命名目标文件:-o
当你运行 as 时,总是产生一个目标文件。在默认的情况下,它的名字是 ’(或者是
‘’仅对 Intel 960 )。你用这个选项(选项后跟一个文件名)给目标文件指定一个不
同的文件名。
不管目标文件叫什么,as覆盖现存的同名文件。
2.11 Join Data and Text Sections: -R
2.11 连接数据段和正文段:-R
选项 -R 让 as 输出目标文件,在目标文件中数据段中的数据保存在正文段。这一步只在最
后做:你得到的二进制数据一样,可是数据段部分的重定向不同。你的目标文件的数据段部
分只有零字节长度,因为所有的字节都被追加到代码段后面(第4章 [Sections and
Relocation], 23页.)
当你指定了选项 –R ,它可能会产生更短的地址移动(因为我们不必在数据段和代码段之
间转移)。为了兼容老版本的 as 我们应尽量避免使用这个选项。以后,可以使用–R 这样
做。
as 配置成输出 COFF 的文件格式,只有你使用名字为 ‘.text’ 和 ‘.data’ 的段时,这
个选项才有用。
任何HPPA处理器的目标格式都不支持选项 –R 。如果使用了,as 会产生一个警告。
2.12 Display Assembly Statistics: --statistics
2.12 列出汇编的统计资料: --statistics
使用 ‘--statistics’ 来显示 as 使用资源的两个统计数据:汇编时分配的最大空间(字节)
和汇编过程的花费的时间(占用cpu的秒数)。
2.13 Compatible output: --traditional-format
2.13 兼容输出: --traditional-format
对一些目标格式来讲,as 的输出和一些现存的汇编器有点不同。这个开关要求 as 使用传
统的格式。
例如,它关闭了异常结构优化,而在默认情况下,as对gcc的输出都进行异常结构优化。
2.14 显示版本: -v
通过在命令行中加上选项 ‘-v’ (也可写成 ‘-version’),你能找出当前运行as的版本号。
2.15 Control Warnings: -W, --warn, --no-warn,
--fatal-warnings
2.15 控制警告选项: -W, --warn, --no-warn,--fatal-warnings
当 as 汇编编译器的输出时,从不发出警告或错误信息。但人们写的程序经常引发as产生
警告,警告指出已触发了一个特定的条件。这些警告都被定向到标准的错误文件。
如果你使用了选项 –W 和 --no-warn ,就不会产生警告。这只影响到警告的信息:它不会
影响到as如何汇编你的文件。而错误,将会终止汇编过程,仍会被报告。
如果使用选项 --fatal-warnings ,as将认为那些产生警告的文件含有错误。
你可以通过指定选项 –-warn 来关掉这些选项,使那些警告正常输出。
2.16 Generate Object File in Spite of Errors: -Z
2.16 在讨厌的错误中生成目标文件: -Z
当出现了一个错误信息,as 通常不产生输出。如果as对你的程序给出错误信息后,你对目
标文件感兴趣的话,可以使用选项 ‘-Z’。即使发生任何错误,as会继续进行汇编,最后发
出一条警告信息‘n errors, m warnings , generating bad object file.’,然后生成一个(坏的)目
标文件
3 语法
本章描述在各种机器平台上源程序文件可以使用的语法。as的语法与其他众多的汇编器都
很相似;它深受BSD4.2汇编器的影响,只是as不可以汇编Vax的位域(Vax bit-fields?)。
/*没有机会学习接触过Vax机器,这里指的是什么?*/
3.1 预处理
as的内部预处理:
*调整并删除多余的空白字符。在每行的关键字前保留一个空格或制表字符,并把每行中其
他的空白字符转换为一个空格字符。
*删除所有的注释,在注释处使用一个空格字符或者适当数量的换行字符进行替换。
*将字符常量转换为适当的数值。
as的内部预处理不进行宏处理,引入文件的操作处理,或者可以由C编译器预处理做好的
其它任何事项。您可以使用 .include命令 (参见 7.37 [.include], 44页)做引入文件的工作。
可以使用GNU C编译器(原文为gnu C compiler driver)获得一种“CPP”风格的预处理:方
法是给编译器一个“.S”尾缀的输入文件进行编译。见Using GNU CC中的“Options Controlling
the Kind of Output”一章
如果输入文本不经过预处理,则不可以在其中使用多余的空白,注释,和字符常量。
如果一个输入文件的首行是#NO_APP或者您使用了‘-f’选项,则不删除输入文件中的空
白和注释。在一个输入文件内,在可能包含空白和注释的文本前,您可以增加一个#APP
行,以请求删除这些部分的空白和注释,并在此文本后增加一个#NO_APP行。这个特征主
要用来支持编译器输出的汇编语句,这些语句往往包含大量的注释和空白。
3.2 空白
空白是指一个或多个空格符或制表符,它们可以是任意的次序。空白一般用来分隔符号,并
使程序更整洁以便人们阅读。除了在字符常量中的空白(参见 3.6.1 [Character Constants], 19
页),任意个数的空白和一个空格符是等价的。
3.3 注释
有两种方法表示注释。用这两种方法表示的注释都等价于一个空格符。
一切以/*开始的语句到下一个*/都是一个注释。这意味着您不能嵌套使用注释。
/*
这是唯一可以在一个注释中包含换行符(’n’)的方法。
*/
/* 使用这种方法注释不能进行嵌套 */
从行注释符开始到换行符的一切语句都被当作注释而忽略。AMD 29K系列的行注释符为
‘;’;ARC上为‘;’ARM上为‘@’; H8/300系列为‘;’;H8/500系列为‘!’; HPPA
上为‘;’;i386和x86-64家族为‘#’;i960上为‘#’;PDP-11上为‘;’;picoJava上为‘;’;
Hitachi SH上为‘!’;SPARC上为‘!’;m32r上为‘#’;680x0上为‘|’;68HC11 和 68HC12
上为‘#’;M880x0上为‘;’;Vax上为‘#’;Z8000上为‘!’; V850上为‘#’;参见第8
章[Machine Dependencies],61页。
某些机器上有两种不同的行注释符。一个只用作行中第一个字符是非空白字符的注释的开
始。而另一个可以用作注释的开始。
V850的汇编器还允许使用双破折号作为注释的开始,注释到行末为止。
为了兼容旧的汇编器,以‘#’开始的行具有特殊的意义。‘#’后面可以是一个纯粹表达式(参
见第6章[Expressions], 33页): 下一行的逻辑行号。后面还允许一个字符串(参见3.6.1.1
[Strings], 19页):如果存在,这个字符串是一个新的逻辑文件名。行的剩余部分,即便存在,
也应该是空白。
If the first non-whitespace characters on the line are not numeric, the line is ignored.(Just like a
comment.)
如果行中第一个非空白字符不是数字,此行被忽略。(如同注释一样)
# 这是一行普通的注释。
# 42-6 "new_file_name" # 新的逻辑文件名
# 这是一个逻辑行 # 36.
不建议使用这个特性,as未来的版本可能不再支持这个特性。
3.4 符号
符号是由一个或多个字符组成的,其中的字符可以是字母(大小写),数字和三个特殊字符
‘_.$’。在绝大多数机器上,您可以在符号名中使用字符$;注意有些例外,见第8章。[Machine
Dependencies], 61页。
符号名不能以数字开始,而且对大小写敏感。符号名没有长度限制:符号名的所有字符都有
意义。符号使用规定字符之外的字符定界;或者使用文件头(因为源文件中必须使用换行符
结束,文件尾不可能作为符号的定界符)。
3.5 语句
一个语句使用换行字符(‘n’)或者行作为行分隔符的字符结束。(除非与注释字符冲突,
行分隔符一般为‘;’;参见第8章[Machine Dependencies], 61页)换行符和分隔符被当作语
句的一部分。在字符常量中的换行符和分隔符例外:它们此时不是语句的结尾。
不能以文件结束来自动结束语句:任何输入文件的最后一个字节应该是换行符。
/*
译者注:作者的在这里的意思大概是文件最后一个语句的最后一个换行符号/分隔符不能省
略。Fix me!
*/
允许使用空语句,并且空语句中可以包括空白。空语句会被忽略。
一个语句可以以0个或多个标签开始,后面可带一个关键符号,这个关键符号决定语句的种
类。关键符号决定这个语句剩余部分的语法。如果符号以点‘.’开头,则此语句是一个汇
编器命令:这个规律对所有的机型都适用。如果符号以一个字母开头,则此语句是一个汇编
语言的机器指令:这个符号被汇编成机器语言指令。用于各种机型的as版本能够识别各自
机型的机器指令。实际上,在不同的机型上的相同符号可能代表不同的指令。
标签是一个后面跟着冒号(:)的符号。允许在标签的前后使用空白,但不能插在符号和冒
号之间。参见5.1 [Labels], 29页.
如果是HPPA目标格式的话,标签不必有冒号,但标签的定义必须从第0列开始。这同时意
味着每行只能定义一个标签。
label: .汇编器命令 后跟一些东西
another_label: # 这是一个空语句
指令 操作数_1, 操作数_2, ...
3.6 常量
一个常量是一个数字,写成各种形式,检查时得到它的值,而不是它的内容。如下:
.byte 74, 0112, 092, 0x4A, 0X4a, ’J, ’J # 全部是同一个值。
.ascii "Ring the bell7" # 一个字符串常量。
.octa 0x123456789abcdefABCDEF0 # 一个巨数。
.float 0f-3979323846264338327
95028841971.693993751E-40 # - pi, 一个浮点数。
3.6.1 字符常量
有两种类型的字符常量。一个字符代表一个单字节字符,并且它的值可以用数字表示。字符
串常量(严格来说叫做string literals)可以有多个字节,并且不能用算术表达式表示。
3.6.1.1 字符串
字符串被写在双引号之间。字符串可以包含双引号null字符。在字符串中使用特殊字符的
方法是增加逃逸符号:在特殊字符前插入一个反斜杠字符‘’。例如‘’代表一个反斜杠:
第1个是一个逃逸符号,它通知as把后面的字符当做反斜杠(防止as把第2个当作逃逸
符号)。下面有完整的特殊字符表:
b 退格的助记符号;它的八进制ASCII码为010。
f 进纸的助记符号;它的八进制ASCII码为014。
n 换行的助记符号;它的八进制ASCII码为012。
r 回车的助记符号;它的八进制ASCII码为015。
t 水平制表的助记符号;它的八进制ASCII码为011。
ddd
一个八进制的字符编码。这个数字编码是3个八进制阿拉伯数字。为了兼容其他的Unix系
统,8和9同样接受:例如,008 为八进制010, 009为八进制011。
x 16进制数字
一个16进制字符编码。x后所有数字都是的组合在一起的。大小写的x都可以。
表示一个‘’字符。
" 表示一个"字符。这个字符在字符串中必须这样表示,因为一个非逃逸的"字符代表字符串
结束。
其他字符
任何跟在后的其他字符将会引发一个警告,并如同不存在‘’一样汇编。这样做的意图是:
当您确实不想as解释后面的字符时,您可以使用这样一个逃逸序列。无论如何,as不进行
其他的解释,所以as知道自己在汇编不正常的编码,并警告用户真实的情况。
使用逃逸字符的字符,和这些字符所代表的值,在不同的汇编器上会有相当大的差别。当前
逃逸字符集是我们认为在BSD 4.2汇编器上被认可的,并且是决大多数C编译器所认可的
子集。如果您有所怀疑,请不要使用逃逸序列。
3.6.1.2 字符
一个单独的字符可以写成一个单引号后紧跟那个字符。
字符使用逃逸符号的情况与字符串相同。所以如果您想使用反斜杠字符,就必须写成 ’,
其中第1个是逃逸符号,第2个是字符。正如你看到的一样,引号是一个高音符,而不是
一个低音符。紧跟在高音符后的换行符被当作文字字符处理,并不当作语句的句尾。
字符常量的值如用数字表达,则等于此字符在该机型上的字节编码。As假定您使用的是
ASCII码:’A等于65,’B等于66,以此类推。
3.6.2 数字常量
as依靠数字在目标文件中的存储方式区分3种类型的数字。整数(Integer)是适合C语言
中int类型的数字。巨数(Bignum)是需要超过32位来存储的整数。浮点数(Flonums)是
后面具体描述的浮点数。
3.6.2.1 整数
2进制的整数由‘0b’ 或 ‘0B’打头,后跟0个或多个2进制数字‘01’
8进制的整数由由‘0’打头,后跟0个或多个8进制数字(‘01234567’)。
十进制整数由一个非零的数字打头,后跟后跟0个或多个十进制数字(‘’)。
16进制整数由‘0x’或0X打头,后跟一个或多个16进制的数字,这些数字可以是
‘abcdefABCDEF’。
整数都有值,如要指定一个负整数,要使用前缀‘-’,前缀在表达式一节有讨论(参见6.2.3
[Prefix Operators], 34页)。
3.6.2.2 巨数
巨数使用和整数一样语法和语意学,但一个2进制的巨数将使用超过32个位来表示。巨数
和整数的区别是:某些允许使用整数的地方却不允许使用巨数。
3.6.2.3 浮点数
Flonum代表一个浮点数。这个转换是间接的:文本中的十转换为进制浮点数被as转换为更
高精度的2进制浮点数。这种2进制浮点数被转换为某个特定机型的浮点格式,这个工作由
针对该机型的as专用部分实现。
浮点数的书写规则(规则也有次序)
* 数字‘0’(‘0’在HPPA上是可选的。)
* 一个字母,通知as本数字的剩余本分是浮点数。推荐使用字母e,大小写都行。
在H8/300, H8/500, Hitachi SH,和AMD 29K等机型上,上述字母必须使用‘DFPRSX’之中
的一个(大小写都行)。
在ARC上,上述字母必须使用‘DFRS’之中的一个(大小写都行)。
在intel 960上,上述字母必须使用‘DFT’之中的一个(大小写都行)。
在HPPA上,上述字母必须使用‘E’(只能大写)。
* 可选的符号:‘+’或‘-’两者中任一个。
* 可选的整数部分:0或多个十进制数字。
* 可选的小数部分:小数点‘.’后跟0个或多个十进制数字。
* 可选的指数本分,由下列组成:
* 一个‘E’或‘e’
* 可选的符号:‘+’或‘-’两者中任一个。
* 一个或多个十进制数字。
至少要存在一个整数部分或一个小数部分。浮点数一般是以10为底数的值。
as的使用整数(硬件单元)进行所有的处理。当运行as时,浮点数的计算不使用计算机中
任何的浮点硬件。
4.1 Background
Roughly, a section is a range of addresses, with no gaps; all data 'in' those addresses is treated the
same for some particular purpose. For example there may be a 'read only' section.
粗略地说,一个段是一个连续的地址范围;在地址范围内的所有数据都接受相同的加工,以
适应特殊的目的。例如,可能存在一个‘只读’段。
The linker ld reads many object files (partial programs) and combines their contents to form a
runnable program. When as emits an object file, the partial program is assumed to start at address
0. ld assigns the final addresses for the partial program, so that different partial programs do not
overlap. This is actually an oversimplification, but it suffices to explain how as uses sections.
连接器ld读取多个目标文件(局部程序),把他们组合在一起,以形成一个可运行的程序。
当as生成一个目标文件时,这个局部程序的首地址假定为0。ld为局部程序分配最终地址,
所以不同的局部程序不回重叠。这么说实际上过分的简化了,但足以解释as如何使用段。
ld moves blocks of bytes of your program to their run-time addresses. These blocks slide to their
run-time addresses as rigid units; their length does not change and neither does the order of bytes
within them. Such a rigid unit is called a section. Assigning runtime addresses to sections is called
relocation. It includes the task of adjusting mentions of object-file addresses so they refer to the
proper run-time addresses. For the H8/300 and H8/500, and for the Hitachi SH, as pads sections if
needed to ensure they end on a word (sixteen bit) boundary.
ld负责把您的程序块移动至运行地址。这些块作为固件可以改变位置。它们的长度不可改变,
内部的字节顺序也不会改变。这样的一个固件被称为一个段。为段分配运行地址叫做重定位。
它包括调整相关的目标文件的地址,以便将它们装入恰当的运行地址。针对H8/300 ,H8/500,
Hitachi SH,如果需要对齐段尾到word(16位)边界,as会填充这些段。
-
An object file written by as has at least three sections, any of which may be empty.
These are named text, data and bss sections.
一个由as生成的目标文件至少具有3个段,某些可能是空段。这3个段分别叫正文段(text),
数据段,bss段。
--------------------------------------------------------------------------------
When it generates COFF output, as can also generate whatever other named sections you specify
using the .section directive (see Section 7.66 [.section], page 52). If you do not use any directives
that place output in the text or data sections, these sections still exist, but are empty.
当它生成COFF格式的输出时,as也能够生成其它段,段名通过使用.section命令指定(见7.66
[.section], 52页)。即使您不使用任何能够在正文段和数据段中产生输出命令,这些段仍然存
在,但它们是空段。
When as generates SOM or ELF output for the HPPA, as can also generate whatever other named
sections you specify using the space and subspace directives. See HP9000 Series 800 Assembly
Language Reference Manual (HP 92432-90001) for details on the space and subspace assembler
directives.
当as为HPPA生成SOM或ELF格式的输出时,as也能够生成其它名字的段,您可以使
用.space和.subspace命令。见在《HP9000 Series 800 Assembly Language Reference Manual》
(HP 92432-90001)的.space和.subspace汇编命令中有详尽的描述。
Additionally, as uses different names for the standard text, data, and bss sections when generating
SOM output. Program text is placed into the ?CODE$? section, data into ?DATA$? and BSS
into ?BSS$? Within the object file, the text section starts at address 0, the data section follows, and
the bss section follows the data section.
另外,当生成SOM格式的输出文件时,as使用不同的名字来命名标准的正文段,数据段和
bss段,程序的正文被放进‘$CODE$’段,数据被放进‘$DATA$’段,BSS被放进‘$BSS$’
段。
在目标文件中,正文(text)段由地址0开始,数据段跟随正文段,BSS段跟随数据段。
When generating either SOM or ELF output files on the HPPA, the text section starts at address 0,
the data section at address 0x4000000, and the bss section follows the data section.
当在HPPA上生成SOM或ELF输出文件时,正文段从地址0开始,数据段由地址0x4000000
开始,BSS段跟随在数据段的后面。
To let ld know which data changes when the sections are relocated, and how to change that data,
as also writes to the object file details of the relocation needed. To perform relocation ld must
know, each time an address in the object file is mentioned:
为了让ld清楚在段重定位时那个数据有变化,怎样变化,as也把重定位需要使用信息细节
写入目标文件。为了完成重定位,ld必须清楚目标文件中每次声明的地址。
•Where in the object file is the beginning of this reference to an address?
寻址指令的首字节在目标文件中的何处?
•How long (in bytes) is this reference?
寻址指令的长度(单位字节)?
•Which section does the address refer to? What is the numeric value of (address) -
(start-address of section)?
•寻址的目标是哪个段?地址的数值是多少-(段首的地址)?
•Is the reference to an address “grogram-Counter relative?”
•本次寻址的地址是“程序-计数器相对地址吗?(Program-Counter relative)”
In fact, every address as ever uses is expressed as
(section) + (offset into section)
实际上,as使用的每个地址都表示为下列形式:
(段)+(段内偏移)
Further, most expressions as computes have this section-relative nature. (For some object formats,
such as SOM for the HPPA, some expressions are symbol-relative instead.)
更进一步地说,大多数表达式一般都通过这种段-相对地址(section-relative)来计算。(某些
目标格式,如HPPA上的SOM,部分表达式使用符号-相对地址)
In this manual we use the notation {secname N} to mean “offset N into section secname.”
在本手册中,我们使用符号{secname N}来表示“在secname段中的偏移量N”
Apart from text, data and bss sections you need to know about the absolute section. When ld
mixes partial programs, addresses in the absolute section remain unchanged. For example, address
{absolute 0} is “relocated” to run-time address 0 by ld. Although the linker never arranges two
partial programs’ data sections with overlapping addresses after linking, by definition their
absolute sections must overlap. Address {absolute 239} in one part of a program is always the
same address when the program is running as address {absolute 239} in any other part of the
program.
除了正文段,数据段和 bss段之外,您还要了解地址独立段(absolute section)。当ld连接
各个局部程序时,在地址独立段中的地址将保持不变。例如,地址{absolute 0}被ld重定位
到运行地址0处。虽然连接器从来不把两个局部程序数据段的地址重叠,但定义过的地址独
立段必须重叠。程序中的某部分地址{absolute 239}与程序中的其它部分地址{absolute 239}
总是相同的运行地址。
The idea of sections is extended to the undefined section. Any address whose section is unknown
at assembly time is by definition rendered {undefined U}-where U is filled in later. Since numbers
are always defined, the only way to generate an undefined address is to mention an undefined
symbol. A reference to a named common block would be such a symbol: its value is unknown at
assembly time so it has section undefined.
段的概念延伸到未定义段(undefined section)。段信息不明确的地址在汇编时被定义为
{undefined U}-U稍后加载。因为数字总是定义好的,唯一生成未定义地址的途径是使用一
个未定义的符号。访问一个指定的通用块(common block)将生成这样的一个符号:在汇编
时不知道它的值域,所以它是一个未定义段。
By analogy the word section is used to describe groups of sections in the linked program. ld puts
all partial programs’ text sections in contiguous addresses in the linked program. It is customary to
refer to the text section of a program, meaning all the addresses of all partial programs’ text
sections. Likewise for data and bss sections.
如此类推,段在连接好的程序中也经常用来表示多个段组成的段群。在连接好的程序中,ld
将所有局部程序的正文段都放在连续的地址中。这是一个习惯,访问一个程序的正文段,表
示所有的局部程序的正文段的所有地址。对数据段和bss段来说,也是同样的道理。
Some sections are manipulated by ld; others are invented for use of as and have no
meaning except during assembly.
有些段由ld来操作。有些段则是为as而设,除了汇编时有用,其他时间全无意义。
4.2 Linker Sections
ld deals with just four kinds of sections, summarized below.
Ld处理四个类型的段,下面总结一下:
named sections
text section
data section
These sections hold your program. as and ld treat them as separate but equal sections. Anything
you can say of one section is true another. When the program is running, however, it is customary
for the text section to be unalterable.
段名
正文段
数据段
这两种段保存您的程序。as和ld将他们分开处理,但是相同的段。在次段中成立的东西,
在另外那个段中也成立。当程序运行时,正文段是不可更改的。
The text section is often shared among processes: it contains instructions, constants and the like.
The data section of a running program is usually alterable:
for example, C variables would be stored in the data section.
正文段经常由多个进程共同使用:包含指令,常数和类似的东西。运行中的数据段通常是可
变的:例如,C语言的变量保存在数据段中。
bss section
bss段
This section contains zeroed bytes when your program begins running. It is used to hold
uninitialized variables or common storage. The length of each partial program’s bss section is
important, but because it starts out containing zeroed bytes there is no need to store explicit zero
bytes in the object file. The bss section was invented to eliminate those explicit zeros from object
files.
在您的程序开始时,bbs段包含的字节全部是0。一般这种段是用来保存未初始化的变量或
通用存储数据。各个局部过程包含的bbs段,它的长度是个重要的信息,因为在它开始时包
含的的数据全部是0,所以没有必要在目标文件中保存把这些0字节全部保存起来。目标文
件的bbs段中剔除了这些0字节。
absolute section
地址独立段
Address 0 of this section is always “relocated” to runtime address 0. This is useful if you want to
refer to an address that ld must not change when relocating. In this sense we speak of absolute
addresses being unrelocatable: they do not change during relocation.
这种段的地址0总是“重定向”到运行地址0。如果您想使用一个在重定向时不变的地址,
可以使用这种段。基于这种观念我们说绝对地址是“不可重定向的”:它们在重定向时不变。
undefined section
This section is a catch-all for address references to objects not in the preceding sections.
这个段在目标文件中提供一个万能的地址访问空间,不能放入前面说到的几种段的数据统统
可纳入此段。
An idealized example of three relocatable sections follows. The example uses the traditional
section names .text and .data. Memory addresses are on the horizontal axis.
下面是三个段重定向后的理想的情况。例子中使用传统的段名 “.text”和“.data”。内存地
址横向表示。
Partial program #1:
局部过程 #1:
text data bss
ttttt dddd 00
局部过程 #2:
text data bss
TTT DDDD 000
linked program:
连接后的程序:
text data bss
TTT ttttt dddd DDDD 00000 . . .
addresses:
0. . .
4.3 Assembler Internal Sections
4.3汇编器内部用段
These sections are meant only for the internal use of as. They have no meaning at run-time. You
do not really need to know about these sections for most purposes; but they can be mentioned in as
warning messages,:so it might be helpful to have an idea of their meanings to as. These sections
are used to permit the value of every expression in your assembly language program to be a
section-relative address. ASSEMBLER-INTERNAL-LOGIC-ERROR!
这些段只在as的内部使用时有意义,在运行时它们不再有意义。其实在大多数情况下您不
需要清楚这些段的具体事项:
但在as发出的警告信息中可能会提及这些段。所以了解它们在as中的作用可能会有益处。
这些段的使用提供这样的可能性:程序中的每个表达式的值都是段-相对地址。
ASSEMBLER-INTERNAL-LOGIC-ERROR!
An internal assembler logic error has been found. This means there is a bug in the assembler.
发现一个汇编器逻辑错误。这说明汇编器本身有漏洞。
expr 段
The assembler stores complex expression internally as combinations of symbols.
When it needs to represent an expression as a symbol, it puts it in the expr
当汇编器合并符号时在内部保存复杂的表达式。
当需要将表达式表示为一个符号时,汇编器把它放入expr段。
4.4 Sub-Sections
Assembled bytes conventionally fall into two sections: text and data. You may have separate
groups of data in named sections that you want to end up near to each other in the object file, even
though they are not contiguous in the assembler source. as allows you to use subsections for this
purpose. Within each section, there can be numbered subsections with values from 0 to 8192.
汇编好的字节按照惯例存入两个段:正文段和数据段。你可以有多个由自己命名的段,即使
这些段在源码中并不相连,但在目标文件中它们将首尾相接。As允许你使用子段
(subsections)来达成这个目的。在每个段中可以使用有限的子段,编号从0个到8192。
Objects assembled into the same subsection go into the object file together with other objects in
the same subsection. For example, a compiler might want to store constants in the text section, but
might not want to have them interspersed with the program being assembled. In this case, the
compiler could issue a ‘.text 0’before each section of code being output, and a ‘text 1’before each
group of constants being output.
每个子段中代码汇编后在目标文件中放在一起。例如,编译器可能希望在正文段保存常数,
但不希望汇编后它们散布在各处。在这种情况下,编译器可以先声明一个‘.text 0’段,再
编译各个段的代码,然后声明一个‘.text 1’段,再编译各种常数。
Subsections are optional. If you do not use subsections, everything goes in subsection number zero.
子段是可选使用的,如果您不使用子段,所有的东西将放入编号为0的子段中。
Each subsection is zero-padded up to a multiple of four bytes. (Subsections may be padded a
different amount on different flavors of as.)
每个子段都是四字节对齐的,使用0作为填充字节。(不同的as对子段的填充处理也有所不
同)
Subsections appear in your object file in numeric order, lowest numbered to highest. (All this to be
compatible with other people’s assemblers.) The object file contains no representation of
subsections; ld and other programs that manipulate object files see no trace of them. They just see
all your text subsections as a text section, and all your data subsections as a data section.
子段在目标文件中的次序由编号决定,自低向高排列。( 所有这些都是为了兼容其他的汇编
器。)各个的子段不再具体地体现在目标文件中;ld和处理目标文件其他的程序无法再发现
各个独立的子段。它们只能看见一个由所有程序子段总合成的正文段,一个所有数据子段总
和成的数据段。
To specify which subsection you want subsequent statements assembled into, use a numeric
argument to specify it, in a “text expression”or a ‘data expression’statement. When generating
COFF output, you can also use an extra subsection argument with arbitrary named sections:
‘section name, expression’ Expression should be an absolute expression. (See Chapter 6
[Expressions], page 33.) If you just say ‘text’then ‘text 0’ is assumed. Likewise ‘data’ means ‘data
0’ Assembly begins in text 0. For instance:
为了指定接下来的语句在哪个子段中进行汇编,在‘text expression’或‘data expression’ 伪
操作命令中使用一个数字参数来指定。当生成COFF目标格式时,您还可以使用一个额外的
子段参数随意命名这个段:‘section name, expression’其中参数expression必须是个可确定
的表达式。(见第6章[Expressions], 33页 。)如果您只是标明‘text’,汇编器则汇编为‘text
0’。同样,‘data’意味着‘data 0’。汇编从text 0中开始。举一个具体的例子:
.text 0 # The default subsection is text 0 anyway.
.ascii "This lives in the first text subsection. *"
.text 1
.ascii "But this lives in the second text subsection."
.data 0
.ascii "This lives in the data section,"
.ascii "in the first data subsection."
.text 0
.ascii "This lives in the first text section,"
.ascii "immediately following the asterisk (*)."
Each section has a location counter incremented by one for every byte assembled into that section.
Because subsections are merely a convenience restricted to as there is no concept of a subsection
location counter. There is no way to directly manipulate a location counter-but the .align directive
changes it, and any label definition captures its current value. The location counter of the section
where statements are being assembled is said to be the active location counter.
每个段都有一个位置计数器,在本段中每汇编好一个字节,位置计数器加1。因为子段只是
编程时的便利工具,受限制于as,并不存在子段计数器的概念。没有办法直接操作位置计
数器-只能通过.align命令改变它。
4.5 bss Section
The bss section is used for local common variable storage. You may allocate address space in the
bss section, but you may not dictate data to load into it before your program executes. When your
program starts running, all the contents of the bss section are zeroed bytes.
4.5 bss 段
bss段用来保存通用变量(common variable)的。您可以在bss段中分配地址空间,但在程
序执行前不可能将数据装入bss段。当程序开始运行时,bss段中的内容都是0字节。
The .lcomm pseudo-op defines a symbol in the bss section; see Section 7.42 [.lcomm], page 45.
.lcomm伪操作一般用来在bss段定义一个符号。见7.42[.lcomm], 45页。
The .comm pseudo-op may be used to declare a common symbol, which is another form of
uninitialized symbol; see Section 7.8 [.comm], page 39.
.comm伪操作一般用来声明一个通用符号,这是未初始化符号的另一种形式。见
7.8[.comm],39页。
When assembling for a target which supports multiple sections, such as ELF or COFF, you may
switch into the .bss section and define symbols as usual; see Section 7.66 [.section], page 52. You
may only assemble zero values into the section. Typically the
section will only contain symbol definitions and .skip directives (see Section 7.74 [.skip],page 54).
当汇编的目标格式支持多种段时,如ELF或COFF,您一样可以进入 .bss段定义符号。见
7.66[.section],52页。汇编时您只能在这个段中存入0值。典型的用法是这个段只包含符号定
义和.skip命令。见7。44[skip],54页。
5 符号(symbol)
符号是一个重要的概念:程序员使用符号为语句命名,链接器(linker)通过符号链接程序,
调试器(debugger)通过符号进行调试。
警告:as未必按照符号声明顺序在目标文件中存放符号,这可能会中断某些调式器的调试
过程。
5.1 标签(labels)
标签就是一个后面带着冒号":"的符号(symbol)。这个符号代表动态定位指针的当前值,并
且可以作为相应指令的操作数。如果在您使用一个符号代表两个不同位置,as会发出警告:
最先定义将会覆盖其他的同名定义。
在HPPA上,标签的一般形式不必后带冒号":",而是必须从第0列开始定义。只有标签才
可以使用一个单独的行来定义。针对这个特性,as的HPPA版本还提供一个特别的命令.lable,
使标签的定义更加灵活。
5.2 符号的赋值,
一个符号可以赋任意值,写成符号后跟一个等号"=",再跟一个表达式(见第六章[表达式],
p33)。这与用.set命令是等价的(见章节 7.68[.set],p53)。
5.3 符号名
符号名以一个字母或一个"._"打头。在大多数平台上,还可以用"$",注意在第八章[平台相
关],61页中的那些例外。首字符后可以跟随任意字符串,字符串可以由数字、字母、美元
符号"$"(有些不能使用的情况,见第八章[平台相关],61页)、以及下划线组成。AMD29K
系列的符号名中还可以使用字符"?",但不能用在首字符。
符号对字母的大小写是敏感的:foo和Foo是不同的符号名。
每一个符号都有一个唯一的名字,每个在汇编语言的源程序中的名字对应着一个唯一的符
号。这个符号名在程序中使用次数不限。
局部符号名
局部符号被编译器或程序员用作临时的名字。总共有10个局部符号名,在程序中可以被重
复使用。可以使用"0"、"1"、...、"9"作为局部符号名,在定义局部符号时,写成标签的形式
"N:"(其中N表示0~9任意一个数字)。如果要访问前面的最后一个标签,可以写成"Nb",”
N”为你定义标签时使用的那个数字;如果要访问后面定义的标签,则要写成"Nf",其中N
为前面提到的10个数字之一。语句中的"b"表示“回溯(backwards)”;"f"表示“后继
(forwards)”。
当前的GNU C编译器不生成局部符号。
使用局部标签是没有任何限制,但是必须记住的是,在汇编程序中的某一点,您最多能访问
该点前面的10个局部标签和后面的10个标签。
局部符号名只是一个助记符,在汇编器使用之前,他们会被转换成常规符号名。这些常规符
号名被保存在符号表中,当汇编器发出错误(error)信息时会显示出来,在目标文件中使用,
常规符号名包括下述部分:
L 所有的局部标签都以"L"开头,通常as和ld都不会保留以“L”开头的符号,这些局部标
签一般是些您没有必要见到的符号。如果你在汇编时使用了"-L"选项,as就会把这些符号保
留在目标文件中,链接时也可以让ld保留这些符号,以便于调试时使用这些符号。
数字 如果标签为”0:”,则这个数字为”0”;如果标签为”1:”,则这个数字为”1”;依此
类推一直到”9”。
C-A 使用这个不常用的字符,目的是防止您无意中再定义一个同名符号,” C-A”的ASCII
码为”001”。
序数 这是一组数字,用于区分不同的标签。你定义的首个”0:”标签,它的序数为”1”;
第15个”0:” ,它的序数为”15”;等等。同样,序数也适用于”1:”~”9:”命名的标签。
例如根据以上的规则,第一个”1:”标签:被转换成常规符号时,就成了”L1C-A1”;第44
个”3:”被转换成”L3C-A44”。
5.4 特殊的“点”符号
符号‘.’ 取当前汇编字节的地址值。如表达式‘melvin: .long .’ 定义melvin包含自己的
地址。为‘.’指定地址等价于使用命令‘.org’。同样,表达式”.=.+4”等价于.space 4”。
5.5 符号属性
就像每个符号都有它们的名字一样,每个符号都有它们的属性:”值域(Value)”和”类型
域(Type)”。根据输出格式的不同,符号还会有一些辅助属性域。
如果你使用了一个没有定义的符号,as可能不发出警告,而假定这个符号的所有属性域都
为0。正如您所期望的,这个符号就成为一个外部符号,
5.5.1值域(Value)
符号的值域(通常情况下)是32位的。对于一个符号来说,如果用来在一个代码段、数据段、
bss段或地址独立的段中标识位置,这个值域就是段首到该标签的地址。对于一个代码段、
数据段和bss段来说,一个符号的值域会在连接时随段基址的改变而不同。独立的符号(地
址独立的段中的符号)的值在链接时是不会改变的:这就是为什么称之为“独立(absolute)”
了。
处理未定义的符号的值域的方式比较特别。如果值域为0,则说明此符号在当前汇编的源程
序中未作定义,ld会根据连接到本程序的其它文件试图明确它的值。对于这类符号,你只需
要简单地写出该符号名就行了,无需定义之。如果值域为非零值,则说明此符号使用”.comm”
命令做了通用声明。值域等于为此符号保留的常规存储空间的数量,以字节为单位(地址)。
符号提供该存储空间的首地址。
5.5.2 类型域(Type)。
符号的类型属性域包含该符号的(段)重定位信息,所有的设置标志,这些标志表明该符号
为外部符号;或者提供其他用于链接器与调试器的信息(可选)。确切的格式要视目标输出
文件的格式而定。
5.5.3 格式的符号属性
5.5.3.1 描述符
描述符为一个16位的任意值。你可以通过.desc命令(见 7.11[.desc],p39)创建一个符号
的描述符值。描述符的值对as没有意义。
5.5.3.2 其它
一个8位的任意值,对as没有意义。
5.5.4 COFF的符号属性
COFF格式支持大多数辅助符号属性,和主要(primary)符号属性一样,它们的设置都要在.def
和.endef命令之间进行。
5.5.4.1 主要(primary)属性
符号名通过.def设置,值域和类型域分别通过.val和.type设置。
5.5.4.1 辅助(auxiliary)属性
as的命令.dim、.line、.scl、.size和.tag可以为COFF格式生成辅助符号表信息。
5.5.5 SOM的符号属性。
HPPA的SOM格式可以通过命令.EXPORT和.IMPORT设置大多数符号属性。
在《HP9000 Series 800 Assembly Language Reference Manual》(HP 92432-90001)的IMPORT
和EXPORT汇编命令文档中的对属性作了描述。
6 表达式(Expressions)
表达式规定了一个地址值或数字值。在表达式的前后都可以有空白。
表达式的结果必须是一个纯粹的数字,或是一个指定段内的偏移量。
如果表达式的结果不是纯粹的数字,并且as对表达式中所在的段没有足够的信息,则必需
对整个源程序进行第2遍汇编,以取得表达式的值—但是as目前不支持进行第2遍汇编,
而是终止汇编,并发出一个错误信息。
6.1 空表达式(Empty Expressions)
空表达式没有值:就是空白或null。无论在哪里需要纯粹数字的表达式,您都可以省略它,
as假定它的值为0,这兼容与其他的汇编器。
6.2 整数表达式(Integer Expressions)
一个整数表达式是由操作符限定的一个参数或者多个参数组成的。
6.2.1 参数(Argument)
参数可以是符号、数字或子表达式(subexpression)。在其它文章中,参数有时被称为“算术
操作数(arithmetic operands)”。在本手册中,为了避免与机器语言中的“指令操作数(instruction
operands)”相混淆,我们只使用术语“参数”来指出表达式的某些部分,将“操作数”保留
给机器语言中的指令操作数使用。
符号参数被换算为{section NNN}的形式,其中section代表一个段,它可以是正文段,数据
段,bss、地址独立段或未定义的段。NNN是个带符号的32位的2进制补码。
数字参数可以是任何一个的整数。
你可以使用一个浮点数(flonum)或巨数(bignum),在这种情况下,as会发出警告:只有其中最
低的32位有效,并认为这是一个32位的整数。你可以在整数操作指令处理外来的常量,这
兼容与其他的汇编器。
子表达式是由用左括号”(“,整数表达式,右 ”)”组成的,或者是一个带有前缀操作符
的参数。
6.2.2 操作符(Operators)
操作符提供了算术功能,如”+”和”%”。前缀(prefix)操作符后面需跟随一个参数,而中缀
(infix)操作符必须处在两个参数之间。操作符的前后都可以有空白。
6.2.3 前缀操作符(Prefix Operators)
as提供如下两个前缀操作符,每个操作符都必须跟随一个参数,这个参数必须是纯粹的数
字。
- 取补码。
~ 取反,按位取反。
6.2.2 中缀操作符(Infix Operators)
中缀操作符必须在两个参数之间。操作符有优先级,同等优先级的操作符按照从左向右的顺
序执行,除了”+”和”-“操作符,其它操作符的参数必须是纯粹的数字。计算结果也是纯
粹的数字。
1.最高优先级
* 乘法操作。
/ 除法操作。
% 取余操作。
<
<< 左移操作。与C语言的操作符’<<’相同
>
>> 右移操作。与C语言的操作符’>>’相同
2.中等优先级
| 按位或。
& 按位与。
^ 按位异或。
! 按位或非。
3.低优先级
+ 加法。如果两个参数中有一个是纯粹的数字,则结果归属于另一个参数所在的段。两个
不同段中的参数不能相加。
- 减法。如果右边的参数为纯粹的数字,则结果归属于左边参数所在的段。如果两个参数都
属于同一个段,则结果为纯粹的数字。不同段中的两个参数不能相减。
== 等于。
<> 不等于。
< 小于。
> 大于。
>= 大于或等于。
<= 小于或等于。
比较操作符用作中缀操作符。如果结果为真(true),则值为-1;如果结果为假(false),则值为
0。值得注意的是,这些操作符都执行符号检测。
4.最低优先级
&& 逻辑与。
|| 逻辑或。
这两个逻辑操作符可以连接多个子表达式的结果。与比较操作符不同,如果结果为真(true),
则值为1;如果结果为假(false),则值为0。另外注意逻辑或操作的优先级比逻辑和操作低。
简言之,只有地址的偏移量(offset)之间的加减才有意义;两个参数中只能有一个参数具有相
应的段定义。
7 汇编器命令
所有的汇编器命令名都由句号('.')开头。命令名的其余是字母,通常使用小写。
本章讨论可用命令,不理会gun汇编器针对目标机器配置。某些机器的配置提供附加的命令。
见第8章[机器相关性],第61页。
7.1 .abort
This directive stops the assembly immediately. It is for compatibility with other assemblers. The
original idea was that the assembly language source would be piped into the assembler. If the
sender of the source quit, it could use this directive tells as to quit also. One day .abort will not be
supported.
7.1 .abort
本命令立即终止汇编过程。这是为了兼容其它的汇编器。早期的想法是汇编语言的源码会被
输送进汇编器。如果发送源码的程序要退出,它可以使用本命令通知as退出。将来可能不
再支持使用.abort
7.2 .ABORT
When producing COFF output, as accepts this directive as a synonym for ‘.abort’.
When producing output, as accepts this directive, but ignores it.
7.2 .ABORT
当生成COFF输出时,汇编器把这条命令作为.abort接受。
当产成输出时,汇编器允许使用这条命令,但忽略它。
7.3 .align abs-expr, abs-expr, abs-expr
Pad the location counter (in the current subsection) to a particular storage boundary. The first
expression (which must be absolute) is the alignment required, as described below.
The second expression (also absolute) gives the fill value to be stored in the padding bytes. It (and
the comma) may be omitted. If it is omitted, the padding bytes are normally zero. However, on
some systems, if the section is marked as containing code and the fill value is omitted, the space is
filled with no-op instructions.
The third expression is also absolute, and is also optional. If it is present, it is the maximum
number of bytes that should be skipped by this alignment directive. If doing the alignment would
require skipping more bytes than the specified maximum, then the alignment is not done at all.
You can omit the fill value (the second argument) entirely by simply using two commas after the
required alignment; this can be useful if you want the alignment to be filled with no-op
instructions when appropriate.
The way the required alignment is specified varies from system to system. For the a29k, hppa,
m68k, m88k, w65, sparc, and Hitachi SH, and i386 using ELF format, the first expression is the
alignment request in bytes. For example ‘.align 8’ advances the location counter until it is a
multiple of 8. If the location counter is already a multiple of 8, no change is needed.
For other systems, including the i386 using format, and the arm and strongarm, it is the
number of low-order zero bits the location counter must have after advancement. For example
‘.align 3’ advances the location counter until it a multiple of 8. If the location counter is already a
multiple of 8, no change is needed.
This inconsistency is due to the different behaviors of the various native assemblers for these
systems which GAS must emulate. GAS also provides .balign and .p2align directives, described
later, which have a consistent behavior across all architectures (but are specific to GAS).
7.3 .align abs-expr, abs-expr, abs-expr
增加位置计数器(在当前的子段)使它指向规定的存储边界。第一个表达式参数(结果必须是纯
粹的数字)是必需参数:边界基准,见后面的描述。
第二个表达式参数(结果必须是纯粹的数字)给出填充字节的值,用这个值填充位置计数器越
过的地方。这个参数(和逗点)可以省略,如果省略它,填充字节的值通常是0。但在某些系
统上,如果本段标识为包含代码,而填充值被省略,则使用no-op指令填充这个空间。
第3个参数表达式的结果也必须是纯粹的数字,这个参数是可选的。如果存在第3个参数,
它代表本对齐命令允许越过字节数的最大值。如果完成这个对齐需要跳过的字节比指定的最
大值还多,则根本无法完成对齐。您可以在边界基准后简单地使用两个逗号,以省略填充值
参数(第二参数);如果您想在适当的时候,对齐操作自动使用no-op指令填充,这个方法将
非常奏效。
边界基准的定义因系统而有差异。a29k,hppa,m68k,m88k,w65,sparc,Hitachi SH, 和
使用ELF格式的i386,第一个表达式是边界基准,单位是字节。例如‘.align 8’向后移动位
置计数器至8的倍数。如果地址已经是8的倍数,则无需移动。
有些其它系统,包括使用格式的i386,ARM和strongarm,这代表位置计数器移动后,
计数器中连续为0的低序位数量。例如‘.align 3’向后移动位置计数器直至8的倍数(计数
器的最低的3位为0)。如果地址已经是8倍数,则无需移动。
之所以存在这样的区别,是因为GAS需要模仿各种汇编器的不同动作。GAS还提供.balign
和.p2align命令,在以后详细讲述,这两条命令在所有的机型上使用相同的动作 (但需要向
GAS明确说明机型)。
7.4 .ascii "string". . .
.ascii expects zero or more string literals (see Section 3.6.1.1 [Strings], page 19) separated by
commas. It assembles each string (with no automatic trailing zero byte) into consecutive addresses.
7.4 .ascii "string"...
.ascii可不带参数或者带多个由逗点分开的字符串(见3.6.1.1节[Strings],第19页)。它把汇编
好的每个字符串(在字符串末不自动追加零字节)存入连续的地址。
7.5 .asciz "string". . .
.asciz is just like .ascii, but each string is followed by a zero byte. The “z” in ‘.asciz’ stands for
“zero”.
7.5 .asciz "string"...
.asciz类似与.ascii,但在每个字符串末自动追加一个零字节。‘.asciz’中的‘z’代表“zero”。
7.6 .balign[wl] abs-expr, abs-expr, abs-expr
Pad the location counter (in the current subsection) to a particular storage boundary. The first
expression (which must be absolute) is the alignment request in bytes. For example ‘.balign 8’
advances the location counter until it is a multiple of 8. If the location counter is already a multiple
of 8, no change is needed.
The second expression (also absolute) gives the fill value to be stored in the padding bytes. It (and
the comma) may be omitted. If it is omitted, the padding bytes are normally zero. However, on
some systems, if the section is marked as containing code and the fill value is omitted, the space is
filled with no-op instructions.
The third expression is also absolute, and is also optional. If it is present, it is the maximum
number of bytes that should be skipped by this alignment directive. If doing the alignment would
require skipping more bytes than the specified maximum, then the alignment is not done at all.
You can omit the fill value (the second argument) entirely by simply using two commas after the
required alignment; this can be useful if you want the alignment to be filled with no-op
instructions when appropriate.
The .balignw and .balignl directives are variants of the .balign directive. The .balignw directive
treats the fill pattern as a two byte word value. The .balignl directives treats the fill pattern as a
four byte longword value. For example, .balignw 4,0x368d will align to a multiple of 4. If it skips
two bytes, they will be filled in with the value 0x368d (the exact placement of the bytes depends
upon the endianness of the processor). If it skips 1 or 3 bytes, the fill value is undefined.
7.6
.balign[wl] abs-expr, abs-expr, abs-expr
增加位置计数器(在当前子段)使它指向规定的存储边界。第一个表达式参数(结果必须是纯粹
的数字)是必需参数:边界基准,单位为字节。例如,‘.balign 8’向后移动位置计数器直至计
数器的值等于8的倍数。如果位置计数器已经是8的倍数,则无需移动。
第2个表达式参数(结果必须是纯粹的数字)给出填充字节的值,用这个值填充位置计数器越
过的地方。第2个参数(和逗点)可以省略。如果省略它,填充字节的值通常是0。但在某些
系统上,如果本段标识为包含代码,而填充值被省略,则使用no-op指令填充空白区。
第3个参数的结果也必须是纯粹的数字,这个参数是可选的。如果存在第3个参数,它代表
本对齐命令允许跳过字节数的最大值。如果完成这个对齐需要跳过的字节数比规定的最大值
还多,则根本无法完成对齐。您可以在边界基准参数后简单地使用两个逗号,以省略填充值
参数(第二参数);如果您在想在适当的时候,对齐操作自动使用no-op指令填充,本方法将
非常奏效。
.balignw和.balignl是.balign命令的变化形式。.balignw使用2个字节来填充空白区。.balignl
使用4字节来填充。例如,.balignw 4,0x368d将地址对齐到4的倍数,如果它跳过2个字节,
GAS将使用0x368d填充这2个字节(字节的确切存放位置视处理器的存储方式而定)。如果
它跳过1或3个字节,则填充值不明确。
7.7 .byte expressions
.byte expects zero or more expressions, separated by commas. Each expression is assembled into
the next byte.
expressions
.byte可不带参数或者带多个表达式参数,表达式之间由逗点分隔。每个表达式参数都被汇
编成下一个字节。
7.8 .comm symbol , length
.comm declares a common symbol named symbol. When linking, a common symbol in one object
file may be merged with a defined or common symbol of the same name in another object file. If
ld does not see a definition for the symbol–just one or more common symbols–then it will allocate
length bytes of uninitialized memory. length must be an absolute expression. If ld sees multiple
common symbols with the same name, and they do not all have the same size, it will allocate
space using the largest size.
When using ELF, the .comm directive takes an optional third argument. This is the desired
alignment of the symbol, specified as a byte boundary (for example, an alignment of 16 means
that the least significant 4 bits of the address should be zero). The alignment must be an absolute
expression, and it must be a power of two. If ld allocates uninitialized memory for the common
symbol, it will use the alignment when placing the symbol. If no alignment is specified, as will set
the alignment to the largest power of two less than or equal to the size of the symbol, up to a
maximum of 16.
The syntax for .comm differs slightly on the HPPA. The syntax is ‘symbol .comm, length’;symbol
is optional.
7.8 .comm symbol , length
.comm声明一个符号名为symbol的通用符号(common symbol)。当连接时,目标文件中的通
用符号可能被并入其它目标文件中已定义的符号,或者被并入其他目标文件中同名通用符
号。如果ld无法找到该符号的定义——只有一个或多个通用符号——则分配length个字节
的未初始化内存。Length必须是一个纯粹的表达式。如果ld发现多个同名的通用符号,并
且它们的长度不同,ld将按照它们之中最大的length值为符号分配内存。
当使用ELF格式时,.comm可以使用第3个参数。它代表符号需要对齐的边界基准(例如,
边界基准为16时意味着符号存放地址的最低4位应该是零)。第3个参数表达式结果必须是
纯粹的数字,而且一定是2的幂。当ld为通用符号分配未初始化内存时,在存放符号时要
使用到这个参数。如果没有规定边界基准,as将把边界基准设置成以2为底的该符号长度
的对数,并向下取整。最大值为16。
.comm的语法在HPPA上稍微有些不同。语法是‘symbol .comm, length’;其中参数symbol
是可选的。
7.9 .data subsection
.data tells as to assemble the following statements onto the end of the data subsection numbered
subsection (which is an absolute expression). If subsection is omitted, it defaults to zero.
7.9 .data subsection
.data通知as汇编后续语句,将它们追加在编号为subsection(subsection必须是纯粹的表达式)
数据段末。如果参数subsection省略,则默认是0。
7.10 .def name
Begin defining debugging information for a symbol name; the definition extends until the .endef
directive is encountered. This directive is only observed when as is configured for COFF format
output; when producing , ‘.def’ is recognized, but ignored.
7.10 .def name
开始定义符号'name'的调试信息;定义区延伸至遇到.endef命令。本命令只在as被配置成
COFF格式输出时才使用;当输出为格式时,可以使用‘.def’命令,但被忽略。
7.11 .desc symbol, abs-expression
This directive sets the descriptor of the symbol (see Section 5.5 [Symbol Attributes],page 30) to
the low 16 bits of an absolute expression.
The ‘.desc’ directive is not available when as is configured for COFF output; it is only for or
object format. For the sake of compatibility, as accepts it, but produces no output, when
configured for COFF.
7.11 .desc symbol, abs-expression
本命令用一个纯粹表达式的低16位的值设置符号symbol的描述符(见5.5[符号属性],第30
页)。当as被配置成COFF输出时,‘.desc’命令无效;它只适用于或目标格式。
为兼容起见,当配置为COFF时,as接受此命令,但不产生输出。
7.12 .dim
This directive is generated by compilers to include auxiliary debugging information in the symbol
table. It is only permitted inside .def/.endef pairs.
‘.dim’ is only meaningful when generating COFF format output; when as is generating , it
accepts this directive but ignores it.
7.12 .dim
这条命令由编译器生成的,以便在符号表中加入辅助调试信息。只可以在.def/.endef对之间
使用此命令。
'.dim'仅仅在生成COFF格式输出时是有意义的;当生成时,as接受这条命令,但忽略它。
7.13 .double flonums
.double expects zero or more flonums, separated by commas. It assembles floating point numbers.
The exact kind of floating point numbers emitted depends on how as is configured. See Chapter 8
[Machine Dependencies], page 61.
7.13 .double flonums
.double后跟着零个或由逗点分开多个的浮点数。本指令汇编出浮点数字。生成的浮点数的
确切类型视as的配置而定。见第8章[机器相关性],第61页。
7.14 .eject
Force a page break at this point, when generating assembly listings.
7.14 .eject
当生成汇编清单时,强制清单页在此点中断。
7.15 .else
.else is part of the as support for conditional assembly; see Section 7.35 [.if], page 43. It marks the
beginning of a section of code to be assembled if the condition for the preceding
.if was false.
7.15 .else
.else 是支持as进行的条件汇编指令之一;见7.35[.if],第43页。如果前面.if命令的条件不成
立,则表示需要汇编.else后的一段代码。
7.16 .elseif
.elseif is part of the as support for conditional assembly; see Section 7.35 [.if],page 43. It is
shorthand for beginning a new .if block that would otherwise fill the entire .else section.
7.16 .elseif
.elseif 是支持as进行的条件汇编指令之一。见7.35节 [.if],第43页。它可以在.esle段中快
速产生一个新的.if块。
7.17 .end
.end marks the end of the assembly file. as does not process anything in the file past the .end
directive.
7.17 .end
.end标记着汇编文件的结束。as不处理.end命令后的任何语句。
7.18 .endef
This directive flags the end of a symbol definition begun with .def.
‘.endef’ is only meaningful when generating COFF format output; if as is configured to generate
, it accepts this directive but ignores it.
7.18 .endef
这条命令标志着从.def开始的符号定义结束。
‘.endef’命令仅仅在生成COFF格式的输出有意义;如果as被配置为生成输出,虽然
as接受这条命令,但忽略它。
7.19 .endfunc
.endfunc marks the end of a function specified with .func.
7.19 .endfunc
.endfunc标志着一个由.func命令定义的函数的结束。
7.20 .endif
.endif is part of the as support for conditional assembly; it marks the end of a block of code that is
only assembled conditionally. See Section 7.35 [.if], page 43.
7.20 .endif
.endif是支持as进行的条件汇编的指令之一.它标志着条件汇编代码块的结束。见7.35节[.if],
第43页。
7.21 .equ symbol, expression
This directive sets the value of symbol to expression. It is synonymous with ‘.set’; see Section
7.68 [.set], page 53.
The syntax for equ on the HPPA is ‘symbol .equ expression’.
7.21 .equ symbol, expression
本命令把符号symbol值设置为expression。它等同与'.set'命令。见7.68[.set],第53页。
在HPPA上的equ语法是‘symbol .equ expression’。
7.22 .equiv symbol, expression
The .equiv directive is like .equ and .set, except that the assembler will signal an error if symbol is
already defined.
Except for the contents of the error message, this is roughly equivalent to
.ifdef SYM
.err
.endif
.equ SYM,VAL
7.22 .equiv symbol, expression
.equiv 类似与.equ & .set命令, 不同之处在于,如果符号已经定义过,as会发出错误信号。
除了错误信息的内容之外,它大体上等价与:
.ifdef SYM
.err
.endif
.equ SYM,VAL
7.23 .err
If as assembles a .err directive, it will print an error message and, unless the -Z option was used, it
will not generate an object file. This can be used to signal error an conditionally compiled code.
7.23 .err
如果as汇编一条.err命令, 将打印一条错误信息,除非使用了-Z 选项, as不会生成目标文件。
可以在条件编译代码中使用它来发出错误信息。
7.24 .exitm
Exit early from the current macro definition. See Section 7.50 [Macro], page 47.
7.24 .exitm
从当前宏定义体中提前退出。见7.50 [Macro],第47页。
7.25 .extern
.extern is accepted in the source program—for compatibility with other assemblers—but it is
ignored. as treats all undefined symbols as external.
7.25 .extern
.extern可以在源程序中使用--以便兼容其他的汇编器—但会被忽略。as将所有未定义的符号
都当作外部符号处理。
7.26 .fail expression
Generates an error or a warning. If the value of the expression is 500 or more, as will print a
warning message. If the value is less than 500, as will print an error message. The message will
include the value of expression. This can occasionally be useful inside complex nested macros or
conditional assembly.
7.26 .fail expression
生成一个错误(error)或警告(warning)。如果expression的值大于或等于500,as会打印一条
“警告”消息。如果expression的值小于500,as会打印一条“错误”消息。消息中包含了
expression的值。这在复杂的宏嵌套或条件汇编时偶尔用到。
7.27 .file string
.file tells as that we are about to start a new logical file. string is the new file name.
In general, the filename is recognized whether or not it is surrounded by quotes ‘"’; but if you
wish to specify an empty file name, you must give the quotes–"". This statement may go away in
future: it is only recognized to be compatible with old as programs. In some configurations of
as, .file has already been removed to avoid conflicts with other assemblers. See Chapter 8
[Machine Dependencies], page 61.
7.27 .file string
.file 通告as我们准备开启一个新的逻辑文件。 string 是新文件名。总的来说,文件名是否
使用引号‘"’都可以;但如果您希望规定一个空文件名时,必须使用引号-""。本语句将来
可能不再使用—允许使用它只是为了与旧版本的as程序兼容。在as的一些配置中,已经删
除了.file以避免与其它的汇编器冲突。见第8章 [Machine Dependencies], 第61页。
7.28 .fill repeat , size , value
repeat, size and value are absolute expressions. This emits repeat copies of size bytes. Repeat may
be zero or more. Size may be zero or more, but if it is more than 8, then it is deemed to have the
value 8, compatible with other people’s assemblers. The contents of each repeat bytes are taken
from an 8-byte number. The highest order 4 bytes are zero. The lowest order 4 bytes are value
rendered in the byte-order of an integer on the computer as is assembling for. Each size bytes in a
repetition is taken from the lowest order size bytes of this number. Again, this bizarre behavior is
compatible with other people’s assemblers.
size and value are optional. If the second comma and value are absent, value is assumed zero. If
the first comma and following tokens are absent, size is assumed to be 1.
7.28 .fill repeat , size , value
repeat, size 和value都必须是纯粹的表达式。本命令生成size个字节的repeat个副本。Repeat
可以是0或更大的值。Size 可以是0或更大的值, 但即使size大于8,也被视作8,以兼容其
它的汇编器。各个副本中的内容取自一个8字节长的数。最高4个字节为零,最低的4个字
节是value,它以as正在汇编的目标计算机的整数字节顺序排列。每个副本中的size个字节
都取值于这个数最低的size个字节。再次说明,这个古怪的动作只是为了兼容其他的汇编
器。
size参数和value参数是可选的。如果不存在第2个逗号和value参数,则假定value为零。
如果不存在第1个逗号和其后的参数,则假定size为1。
7.29 .float flonums
This directive assembles zero or more flonums, separated by commas. It has the same effect
as .single. The exact kind of floating point numbers emitted depends on how as is configured. See
Chapter 8 [Machine Dependencies], page 61.
7.29 .float flonums
本命令汇编0个或多个浮点数,浮点数之间由逗号分隔。它和.single的汇编效果相同。生成
的浮点数的确切类型视as的配置而定。见第8章 [Machine Dependencies], 61页。
7.30 .func name[,label]
.func emits debugging information to denote function name, and is ignored unless the file is
assembled with debugging enabled. Only ‘--gstabs’ is currently supported. Label is the entry point
of the function and if omitted name prepended with the ‘leading char’ is used. ‘leading char’ is
usually _ or nothing, depending on the target. All functions are currently defined to have void
return type. The function must be terminated with .endfunc.
7.30 .func name[,label]
.func发出一个调试信息用以指示函数name,这个信息将被忽略,除非文件使用debugging
enabled方式的汇编。目前只支持‘--gstabs’。label是函数的入口点,如果name被省略则使
用预定的‘引导符’。‘引导符’通常可以是 _ 或者什么也没有,视目标机型而定。所有函
数现时被定义为void返回类型,函数体必须使用.endfunc来结束
7.31 .global symbol, .globl symbol
.global makes the symbol visible to ld. If you define symbol in your partial program, its value is
made available to other partial programs that are linked with it. Otherwise, symbol takes its
attributes from a symbol of the same name from another file linked into the same program.
Both spellings (‘.globl’ and ‘.global’) are accepted, for compatibility with other assemblers.
On the HPPA, .global is not always enough to make it accessible to other partial programs. You
may need the HPPA-only .EXPORT directive as well. See Section 8.8.5 [HPPA Assembler
Directives], page 84.
7.31 .global symbol, .globl symbol
.global 使符号symbol对连接器ld可见。如果您在局部过程中定义符号symbol,其它和此
的局部过程都可以访问它的值。另外,symbol从连接到本过程的另一个文件中的同名符号
获取自己的属性。
两种写法都可以(‘.globl’ 和‘.global’),以便兼容多种汇编器。
在HPPA上, .global未必总能够使符号被其它局部过程访问。可能同时需要使用
HPPA-only .EXPORT命令。见8.8.5[HPPA Assembler Directives],84页。
7.32 .hidden names
This one of the ELF visibility directives. The other two are .internal (see Section 7.39 [.internal],
page 44) and .protected (see Section 7.58 [.protected], page 50).
This directive overrides the named symbols default visibility (which is set by their binding: local,
global or weak). The directive sets the visibility to hidden which means that the symbols are not
visible to other components. Such symbols are always considered to be protected as well.
7.32 .hidden names
这是一条关于ELF可见度的命令。其它两条是.internal(见7.39[.internal],44页) 和 .protected
(见7.58 [.protected], 50页)。本命令取消指定符号的缺省可见度(可见度由其他命令捆绑设定:
local,global,weak)。本命令把可见度设置为hidden,这意味着本符号对其他部分不可见。这最
好是一些需要长期保护的符号。
7.33 .hword expressions
This expects zero or more expressions, and emits a 16 bit number for each.
This directive is a synonym for ‘.short’; depending on the target architecture, it may also be a
synonym for ‘.word’.
7.33 .hword expressions
本命令后可以不带或带多个expressions,并且为每个参数生成一个16位数。
本命令等同与'.short'命令。在某些架构上,也可能等同与'.word'。
7.34 .ident
This directive is used by some assemblers to place tags in object files. as simply accepts the
directive for source-file compatibility with such assemblers, but does not actually emit anything
for it.
7.34 .ident
本命令被某些汇编器用来在目标文件中加入标饰。为了使汇编源码文件兼容上述的汇编器,
as简单地接受本命令,但实际上不产生东西。
7.35 .if absolute expression
.if marks the beginning of a section of code which is only considered part of the source program
being assembled if the argument (which must be an absolute expression) is nonzero. The end of
the conditional section of code must be marked by .endif (see Section 7.20 [.endif], page 40);
optionally, you may include code for the alternative condition, flagged by .else (see Section 7.15
[.else], page 40). If you have several conditions to check, .elseif may be used to avoid nesting
blocks if/else within each subsequent .else block.
The following variants of .if are also supported:
.ifdef symbol
Assembles the following section of code if the specified symbol has been defined.
.ifc string1,string2
Assembles the following section of code if the two strings are the same. The strings may be
optionally quoted with single quotes. If they are not quoted, the first string stops at the first
comma, and the second string stops at the end of the line. Strings which contain whitespace should
be quoted. The string comparison is case sensitive.
.ifeq absolute expression
Assembles the following section of code if the argument is zero.
.ifeqs string1,string2
Another form of .ifc. The strings must be quoted using double quotes.
.ifge absolute expression
Assembles the following section of code if the argument is greater than or equal to zero.
.ifgt absolute expression
Assembles the following section of code if the argument is greater than zero.
.ifle absolute expression
Assembles the following section of code if the argument is less than or equal to zero.
.iflt absolute expression
Assembles the following section of code if the argument is less than zero.
.ifnc string1,string2.
Like .ifc, but the sense of the test is reversed: this assembles the following section of code if the
two strings are not the same.
.ifndef symbol
.ifnotdef symbol
Assembles the following section of code if the specified symbol has not been defined. Both
spelling variants are equivalent.
.ifne absolute expression
Assembles the following section of code if the argument is not equal to zero (in other words, this
is equivalent to .if).
.ifnes string1,string2
Like .ifeqs, but the sense of the test is reversed: this assembles the following section of code if the
two strings are not the same.
7.35 .if absolute expression
.if 标志着一段代码的开始,这段代码只有在参数absolute experession(必须是一个独立的表
达式)不为0时才进行汇编。这段条件汇编代码必须使用.endif标志结束。(见7.20[.endif], 40
页);另外,可以使用.esle来标记一个代码块(见7.15 [.else],40页),这个代码块与前面那段代
码只有一个会进行汇编。 如果您需要检查数个汇编条件,可以在使用.elseif命令,以避免
在.else代码块中进行if/else语句块的嵌套。
同样可以使用下面.if的变体:
.ifdef symbol
如果指定的符号symbol已经定义过,汇编下面那段代码。
.ifc string1,string2
如果两个字符串相同的话,汇编下面那段代码。 字符串可以可选地使用单引号。如果不使
用引号则第1个字符串在逗号处结束。第2个字符串在本行末结束。包含空白的字符串应该
使用引号标注。字符串比较时是区分大小写的。
.ifeq absolute expression
如果参数的值为0,汇编下面那段代码。
.ifeqs string1,string2
这是.ifc的另一种形式,字符串必须使用双引号标注。
.ifge absolute expression
如果参数的值大于等于0,汇编下面那段代码。
.ifgt absolute expression
如果参数的值大于0,汇编下面那段代码。
.ifle absolute expression
如果参数的值小于等于0,汇编下面那段代码。
.iflt absolute expression
如果参数的值小于0,汇编下面那段代码。
.ifnc string1,string2.
类似与.ifc,不过使用反向的测试: 如果两个字符串不相等的话,汇编下面那段代码。
.ifndef symbol
.ifnotdef symbol
如果指定的符号symbol不曾被定义过,汇编下面那段代码。 上面两种写法是等效的。
.ifne absolute expression
如果参数的值为不等于0,汇编下面那段代码。 (换句话说, 这是.if的另一种写法).
.ifnes string1,string2
类似与.ifeqs,不过使用反向的测试: 如果两个字符串不相等的话,汇编下面那段代码。
7.36 .incbin "file"[,skip[,count]]
The incbin directive includes file verbatim at the current location. You can control the search paths
used with the ‘-I’ command-line option (see Chapter 2 [Command-Line Options], page 11).
Quotation marks are required around file.
The skip argument skips a number of bytes from the start of the file. The count argument indicates
the maximum number of bytes to read. Note that the data is not aligned in any way, so it is the
user’s responsibility to make sure that proper alignment is provided both before and after the
incbin directive.
7.36 .incbin "file"[,skip[,count]]
这条incbin命令在当前位置逐字地引入file文件的内容。您可以使用命令行选项参数“-I”
来控制搜索路径。(见第2章[Command-Line Options], 11页)。文件名必须使用引号。
参数skip表示需要从文件头跳过的字节数目。参数count表示读入的最大字节数目。注意,
数据没有进行任何方式的对齐操作,所以用户需要在 .incbin命令的前后进行必要的边界对
齐。
7.37 .include "file"
This directive provides a way to include supporting files at specified points in your source
program. The code from file is assembled as if it followed the point of the .include; when the end
of the included file is reached, assembly of the original file continues. You can control the search
paths used with the ‘-I’ command-line option (see Chapter 2 [Command-Line Options], page 11).
Quotation marks are required around file.
7.37 .include "file"
本命令提供在源程序中指定点引入支撑文件的手段。file中的代码如同紧跟.include后一样被
汇编。当引入文件汇编结束,继续汇编原来的文件。您可以使用命令行选项参数“-I”来控
制搜索路径(见第2章[Command-Line Options], 11页)。文件名必须使用引号来标注。
7.38 .int expressions
Expect zero or more expressions, of any section, separated by commas. For each expression, emit
a number that, at run time, is the value of that expression. The byte order and bit size of the
number depends on what kind of target the assembly is for.
7.38 .int expressions
可以不带参数或带多个expressions,参数之间由逗号分隔。每个expressions都生成一个数字,
这个数字等于表达式在目标机器运行时的值。字节顺序和数字的位数视汇编的目标机器而
定。
7.39 .internal names
This one of the ELF visibility directives. The other two are .hidden (see Section 7.32 [.hidden],
page 42) and .protected (see Section 7.58 [.protected], page 50).
This directive overrides the named symbols default visibility (which is set by their binding: local,
global or weak). The directive sets the visibility to internal which means that the symbols are
considered to be hidden (ie not visible to other components), and that some extra, processor
specific processing must also be performed upon the symbols as well.
7.39 .internal names
这是一条与ELF可见度相关的命令。另外的两条是.hidden(见7.32[.hidden],42页)
和 .protected (见7.58 [.protected],50页)。
本命令取消指定符号的缺省可见度(可见度由其他命令捆绑设定:local,global,weak)。本命令
把指定符号可见度设置为internal,这意味着此符号需要被隐藏(即对其他部分不可见),另
外,符号还必须经过处理器的特别的处理。
7.40 .irp symbol,values . . .
加工一个需要用values替代symbol的语句序列。语句序列从.irp命令开始,在.endr命令前
结束。对于每个value都进行如下加工:用value替代Symbol,并对此语句序列进行汇编。
如果没有给出value,则用空字符串(null sting)替代symbol,并将此语句序列汇编一次。使用
symbol, 把参数symbol提交给语句序列。
例如下列代码
.irp param,1,2,3
move dparam,sp@-
.endr
等同与
move d1,sp@-
move d2,sp@-
move d3,sp@-
7.41 .irpc symbol,values . . .
Evaluate a sequence of statements assigning different values to symbol. The sequence of
statements starts at the .irpc directive, and is terminated by an .endr directive. For each character
in value, symbol is set to the character, and the sequence of statements is assembled. If no value is
listed, the sequence of statements is assembled once, with symbol set to the null string. To refer to
symbol within the sequence of statements, use symbol.
For example, assembling
.irpc param,123
move dparam,sp@-
.endr
is equivalent to assembling
move d1,sp@-
move d2,sp@-
move d3,sp@-
7.41 .irpc symbol,values. . .
加工一个需要用values替代symbol的语句序列。语句序列从.irpc命令开始,在.endr命令前
结束。对于value中的每个字符,都进行如下加工;用此字符替代symbol,并对此语句序列
进行汇编。如果没有给出value参数,则用空字符串(null sting)替代symbol,并将此语句序
列汇编一次。使用symbol, 把参数symbol提交给语句序列。
例如下列代码
.irpc param,123
move dparam,sp@-
.endr
等同与
move d1,sp@-
move d2,sp@-
move d3,sp@-
7.42 .lcomm symbol , length
Reserve length (an absolute expression) bytes for a local common denoted by symbol. The section
and value of symbol are those of the new local common. The addresses are allocated in the bss
section, so that at run-time the bytes start off zeroed. Symbol is not declared global (see Section
7.31 [.global], page 42), so is normally not visible to ld.
Some targets permit a third argument to be used with .lcomm. This argument specifies the desired
alignment of the symbol in the bss section.
The syntax for .lcomm differs slightly on the HPPA. The syntax is ‘symbol .lcomm, length’;
symbol is optional.
7.42 .lcomm symbol , length
为一个本地通用符号symbol预留length个字节的内存。symbol 的段(属性)和值(属性)被设
置为一个新的本地通用符号应有的属性:内存是在bss段中分配的,所以在运行时,这些字节
开始都是零。因为symbol没有被声明为全局性的符号,所以symbol对ld通常不可见。
某些目标格式允许在.lcomm命令中使用第3个参数。这个参数指出这个bss段中的符号对
齐操作所需要的边界基准。
.lcomm的语法在HPPA上稍有不同。表示为‘symbol .lcomm, length’; symbol 是可选的。
7.43 .lflags
as accepts this directive, for compatibility with other assemblers, but ignores it.
7.43 .lflags
as接受本命令,以兼容其他的汇编器,但忽略之。
7.44 .line line-number
Change the logical line number. line-number must be an absolute expression. The next line has
that logical line number. Therefore any other statements on the current line (after a statement
separator character) are reported as on logical line number line-number - 1. One day as will no
longer support this directive: it is recognized only for compatibility with existing assembler
programs.
Warning: In the AMD29K configuration of as, this command is not available; use the synonym .ln
in that context.
Even though this is a directive associated with the or object-code formats, as still
recognizes it when producing COFF output, and treats ‘.line’ as though it were the COFF ‘.ln’ if it
is found outside a .def/.endef pair.
Inside a .def, ‘.line’ is, instead, one of the directives used by compilers to generate auxiliary
symbol information for debugging.
7.44 .line line-number
更改逻辑行号,参数line-number必须是个纯粹的表达式。本命令后的下一行将被赋予此逻
辑行号。因此在当前行之前任何其他的语句(在语句分隔符后)的逻辑行号将被视作
line-number - 1。以后 as将不在支持这条命令:只是为了兼容现存的汇编器而接受本命令。
Warning: 在为AMD29K目标机器配置的as中,不能使用本指令。在这种场合可以使用.ln命
令。
尽管这是与a. out或b. out目标代码格式相关的命令,在生成COFF输出时as仍然接受它,
并且如果‘.line’出现在.def/endef之外的话,就把它视为‘.ln’命令。
如果‘.line’在.def语句块中的话,.line命令则是一条编译器使用的命令,用来为调式生成
辅助符号信息。
7.45 .linkonce [type]
Mark the current section so that the linker only includes a single copy of it. This may be used to
include the same section in several different object files, but ensure that the linker will only
include it once in the final output file. The .linkonce pseudo-op must be used for each instance of
the section. Duplicate sections are detected based on the section name, so it should be unique.
This directive is only supported by a few object file formats; as of this writing, the only object file
format that supports it is the Portable Executable format used on Windows NT.
The type argument is optional. If specified, it must be one of the following strings. For example:
.linkonce same_size
Not all types may be supported on all object file formats.
discard Silently discard duplicate sections. This is the default.
one_only Warn if there are duplicate sections, but still keep only one copy.
same_size Warn if any of the duplicates have different sizes.
same_contents
Warn if any of the duplicates do not have exactly the same contents.
7.45 .linkonce [type]
给当前段做一个标志,以便连接器只包含它的一个拷贝。这个命令可以用于几个不同的目标
文件中包含同样的段,但需要连接器在最终的输出文件中只包含一个这样的段。. linkouce
伪操作必须在每个段的实例都中使用。对重复段的探测基于段名来进行,因此这个段将是唯
一的。
本命令只在少数目标格式文件中有效,到写本文为止,只有基于Windows NT的PE (Portable
Executable)格式的目标文件支持本命令,
参数type是可选的,如果指定了此参数,它必须是下列字符串之一。例如
. Linkonce same_size
不是在所有的格式目标文件都可以使用所有类型的参数。
discard 静静地舍弃重复的段,这也是默认值。
one_only 如果存在重复的段则发出警告,但只保存一个拷贝。
same_size 如果重复的段有不同的大小则发出警告。
same_contents 如果重复段的内容不是精确的相符则发出警告。
7.46 .ln line-number
‘.ln’ is a synonym for ‘.line’.
7.46 .ln line-number
‘.ln’命令等同与‘.line’.
7.47 .mri val
If val is non-zero, this tells as to enter MRI mode. If val is zero, this tells as to exit MRI mode.
This change affects code assembled until the next .mri directive, or until the end of the file. See
Section 2.8 [MRI mode], page 13.
7.47 .mri val
如果参数val是非零值,这将通知as进入MRI模式。如果参数val的值是零,这通知as退
出MRI模式。这个变化会影响汇编的结果,直到下个.mri命令,或者直到文件尾。见2.8 [MRI
mode], 13页。
7.48 .list
Control (in conjunction with the .nolist directive) whether or not assembly listings are generated.
These two directives maintain an internal counter (which is zero initially). .list increments the
counter, and .nolist decrements it. Assembly listings are generated whenever the counter is greater
than zero.
By default, listings are disabled. When you enable them (with the ‘-a’ command line option; see
Chapter 2 [Command-Line Options], page 11), the initial value of the listing counter is one.
7.48 .list
控制(和.nolist命令配合)是否生成汇编清单。这两个命令维护一个内部的计数器(计数器
初始值为0).list命令增加计数器的值,.nolist减少计数器的值。当计数器的值大与0时将
汇编列表。
缺省状态汇编列表的生成是关闭的。当您打开它的时候(使用带-a选项的命令行)第2章
[Command-Line Options], 11页), 内部计数器的初始值为1。
7.49 .long expressions
.long is the same as ‘.int’, see Section 7.38 [.int], page 44.
7.49 .long expressions
.long是.int的等价命令,见7.38 [.int], 44页.
7.50 .macro
The commands .macro and .endm allow you to define macros that generate assembly output. For
example, this definition specifies a macro sum that puts a sequence of numbers into memory:
.macro sum from=0, to=5
.long from
.if to-from
sum "(from+1)",to
.endif
.endm
With that definition, ‘SUM 0,5’ is equivalent to this assembly input:
.long 0
.long 1
.long 2
.long 3
.long 4
.long 5
.macro macname
.macro macname macargs ...
Begin the definition of a macro called macname. If your macro definition requires arguments,
specify their names after the macro name, separated by commas or spaces. You can supply a
default value for any macro argument by following the name with ‘=deflt’. For example, these are
all valid .macro statements:
.macro comm
Begin the definition of a macro called comm, which takes no arguments.
.macro plus1 p, p1
.macro plus1 p p1
Either statement begins the definition of a macro called plus1,which takes two arguments; within
the macro definition, write ‘p’ or ‘p1’ to evaluate the arguments.
.macro reserve_str p1=0 p2
Begin the definition of a macro called reserve_str, with two arguments. The first argument has a
default value, but not the second. After the definition is complete, you can call the macro either as
‘reserve_str a, b’ (with ‘p1’ evaluating to a and ‘p2’ evaluating to b), or as ‘reserve_str ,b’ (with
‘p1’ evaluating as the default, in this case ‘0’, and ‘p2’ evaluating to b).
When you call a macro, you can specify the argument values either by position, or by keyword.
For example, ‘sum 9,17’ is equivalent to ‘sum to=17, from=9’.
.endm Mark the end of a macro definition.
.exitm Exit early from the current macro definition.
@ as maintains a counter of how many macros it has executed in this pseudov-ariable; you can
copy that number to your output with ‘@’, but only within a macro definition.
7.50 .macro
本命令.macro和.endm命令允许您定义宏来生成汇编输出。例如,下面的语句定义了一个宏
sum,这个宏把一个数字序列放入内存。
.macro sum from=0, to=5
.long from
.if to-from
sum "(from+1)",to
.endif
.endm
使用上述定义,'SUM 0,5'语句就等于输入下面的汇编语句:
.long 0
.long 1
.long 2
.long 3
.long 4
.long 5
.macro macname
.macro macname macargs ...
开始定义一个名为macname的宏。如果您的宏需要使用参数,则在宏的名字后指定他们的
名字,参数之间用逗号或空格分隔。您可以为任意的参数提供参数的缺省值,只需要在参数
后使用“=deflt”,。例如,下列都是合法的宏定义语句:
.macro comm
定义一个名为comm宏,不使用参数。
.macro plus1 p, p1
.macro plus1 p p1
两个语句都声明要定义一个名为plus1的宏,这个宏需要两个参数,在宏定义体内,使用'p'
或'p1'来引用参数的值。
.macro reserve_str p1=0 p2
声明要定义一个名为reserve_str的宏,使用两个参数。第一个参数有缺省值,第二个没有缺
省值。宏定义完成后,您可以通过‘reserve_str a, b’(宏体中‘p1’引用a的值,‘p2’引
用b值)或通过‘reserve_str ,b’(‘p1’使用缺省值,在此为‘0’,‘p2’引用b的值)来调
用这个宏。
当调用一个宏时,您既可以通过位置指定参数值,也可以通过关键字指定参数值。例如,‘sum
9,17’和‘sum to=17, from=9’是等价的。
.endm 标志宏定义体的结束。
.exitm 提前从当前宏定义体中退出。
@ 这个伪变量其实是as维护的一个计数器,用来统计执行了多少个宏。您可以通过使用@
把这个数字复制到您的输出中,但仅限于在宏定义体中使用。
7.51 .nolist
Control (in conjunction with the .list directive) whether or not assembly listings are generated.
These two directives maintain an internal counter (which is zero initially). .list increments the
counter, and .nolist decrements it. Assembly listings are generated whenever the counter is greater
than zero.
7.51 .nolist
控制(和.list命令配合)是否生成汇编列表。这两个命令维护一个内部的计数器(计数器初
始值为0).list命令增加计数器的值,.nolist减少计数器的值。当计数器的值大与0时将汇
编列表。
7.52 .octa bignums
This directive expects zero or more bignums, separated by commas. For each bignum, it emits a
16-byte integer.
The term “octa” comes from contexts in which a “word” is two bytes; hence octa-word for 16
bytes.
7.52 .octa bignums
本命令可以不带参数或多个由逗号分隔开的巨数bignum,针对每个巨数bignum,它生成一个
16个字节的整数。
术语"octa"来源:word为2个字节,故此octa-word为16个字节。
7.53 .org new-lc , fill
Advance the location counter of the current section to new-lc. new-lc is either an absolute
expression or an expression with the same section as the current subsection. That is, you can’t
use .org to cross sections: if new-lc has the wrong section, the .org directive is ignored. To be
compatible with former assemblers, if the section of new-lc is absolute, as issues a warning, then
pretends the section of new-lc is the same as the current subsection.
.org may only increase the location counter, or leave it unchanged; you cannot use .org to move
the location counter backwards.
Because as tries to assemble programs in one pass, new-lc may not be undefined. If you really
detest this restriction we eagerly await a chance to share your improved assembler.
Beware that the origin is relative to the start of the section, not to the start of the subsection. This
is compatible with other people’s assemblers.
When the location counter (of the current subsection) is advanced, the intervening bytes are filled
with fill which should be an absolute expression. If the comma and fill are omitted, fill defaults to
zero.
7.53 .org new-lc , fill
向后移动当前段的位置计数器至new-lc。new-lc要么是一个纯粹的表达式,要么这个表达式
与当前子段在同一个段中。换句话说,就是您不能使用.org进行段超越。如果new-lc指向错
误的段,则忽略.org命令。为了兼容以前的汇编器,如果new-lc指向一个地址独立的段,as
发出一个警告,并假定new-lc指向当前子段。
.org 仅仅可以增大位置计数器,或者保持位置计数器不变;您不能使用.org命令把位置计数
器向回移动。
因为as尽量一次完成程序汇编,所以不能使用未定义的new-lc。如果您厌恶这个限制,我
们急切期待有机会分享经过您改进的汇编器。
注意起点相对于段的首地址,而不是子段的首地址。这与其他的汇编器相兼容。
当(当前语句块)位置计数器到达指定位置,用fill填充该字节,fill必须是纯粹的表达式。
如果没有给出逗号和fill,fill值缺省为0。
7.54 .p2align[wl] abs-expr, abs-expr, abs-expr
Pad the location counter (in the current subsection) to a particular storage boundary. The first
expression (which must be absolute) is the number of low-order zero bits the location counter
must have after advancement. For example ‘.p2align 3’ advances the location counter until it a
multiple of 8. If the location counter is already a multiple of 8, no change is needed.
The second expression (also absolute) gives the fill value to be stored in the padding bytes. It (and
the comma) may be omitted. If it is omitted, the padding bytes are normally zero. However, on
some systems, if the section is marked as containing code and the fill value is omitted, the space is
filled with no-op instructions.
The third expression is also absolute, and is also optional. If it is present, it is the maximum
number of bytes that should be skipped by this alignment directive. If doing the alignment would
require skipping more bytes than the specified maximum, then the alignment is not done at all.
You can omit the fill value (the second argument) entirely by simply using two commas after the
required alignment; this can be useful if you want the alignment to be filled with no-op
instructions when appropriate.
The .p2alignw and .p2alignl directives are variants of the .p2align directive. The .p2alignw
directive treats the fill pattern as a two byte word value. The .p2alignl directives treats the fill
pattern as a four byte longword value. For example, .p2alignw 2,0x368d will align to a multiple of
4. If it skips two bytes, they will be filled in with the value 0x368d (the exact placement of the
bytes depends upon the endianness of the processor). If it skips 1 or 3 bytes, the fill value is
undefined.
7.54 .p2align[wl] abs-expr, abs-expr, abs-expr
增加位置计数器(在当前的子段)使它指向规定的存储边界。第一个表达式参数(结果必须是纯
粹的数字) 代表位置计数器移动后,计数器中连续为0的低序位数量。例如‘.align 3’向后
移动位置指针直至8的倍数(指针的最低的3位为0)。如果地址已经是8倍数,则无需移
动。
第二个表达式参数(结果必须是纯粹的数字)给出填充字节的值。用这个值填充位置计数器越
过的地方。这个参数(和逗点)可以省略。如果省略它,填充字节的值通常默认为0。但在某
些系统上,如果本段标识为包含代码,而填充值被省略,则使用no-op指令填充填充区。
第3个参数表达式的结果也必须是纯粹的数字,这个参数是可选的。如果存在第3个参数,
它代表本对齐命令允许越过字节数的最大值。如果完成这个对齐需要跳过的字节比指定的最
大值还多,则根本无法完成对齐。您可以在边界基准后简单地使用两个逗号,以省略填充值
参数(第二参数);如果您想在适当的时候,对齐操作自动使用no-op指令填充,这个方法将
非常奏效。
.p2alignw和.p2alignl是.p2align命令的变化形式。.p2alignw 使用2个字节来填充填充
区。.p2alignl使用4字节来填充。例如,. .p2alignw 2,0x368d将地址对齐到4的倍数,如果它
跳过2个字节,GAS将使用0x368d填充这2个字节(字节的准确的位置视处理器的存储方
式而定)。如果它跳过1或3个字节,填充值则不明确。
7.55 .previous
This is one of the ELF section stack manipulation directives. The others are .section (see Section
7.66 [Section], page 52), .subsection (see Section 7.79 [SubSection], page 56), .pushsection (see
Section 7.61 [PushSection], page 50), and .popsection (see Section 7.56 [PopSection], page 50).
This directive swaps the current section (and subsection) with most recently referenced section
(and subsection) prior to this one. Multiple .previous directives in a row will flip between two
sections (and their subsections).
In terms of the section stack, this directive swaps the current section with the top section on the
section stack.
7.55 .previous
这是一个ELF段堆栈操作命令。其他的段堆栈操作命令还有.section (见 7.66 [Section], 52
页), .subsection (见 7.79 [SubSection], 56页),.pushsection (见 7.61 [PushSection], 50页),
和 .popsection (见 7.56 [PopSection], 50页)。
本命令交换当前段(及其子段)和最近访问过的段(及其子段)。多个连续的.previous命令
将使当前位置两个段(及其子段)之间反复切换。
用段堆栈的术语来说,本命令使当前段和堆顶段交换位置。
7.56 .popsection
This is one of the ELF section stack manipulation directives. The others are .section (see Section
7.66 [Section], page 52), .subsection (see Section 7.79 [SubSection], page 56), .pushsection (see
Section 7.61 [PushSection], page 50), and .previous (see Section 7.55 [Previous], page 49).
This directive replaces the current section (and subsection) with the top section (and subsection)
on the section stack. This section is popped off the stack.
7.56 .popsection
这是一个ELF段堆栈操作命令。其他的段堆栈操作命令还有.section(见 7.66 [Section], 52
页), .subsection (见 7.79 [SubSection], 56页),.pushsection (见 7.61 [PushSection], 50页),
和 .previous (见 7.55 [Previous], 49页).
本命令用堆栈顶段(及其子段)替代当前段(及其子段)。堆栈顶段出栈。
7.57 .print string
as will print string on the standard output during assembly. You must put string in double quotes.
7.57 .print string
as会在标准输出上打印string字符串。String必须使用双引号。
7.58 .protected names
This one of the ELF visibility directives. The other two are .hidden (see Section 7.32 [Hidden],
page 42) and .internal (see Section 7.39 [Internal], page 44).
This directive overrides the named symbols default visibility (which is set by their binding: local,
global or weak). The directive sets the visibility to protected which means that any references to
the symbols from within the components that defines them must be resolved to the definition in
that component, even if a definition in another component would normally preempt this.
7.58 .protected names
这是一条ELF可见度的相关命令。其它两条是.hidden (参见 7.32 [Hidden], 42页)和 .internal
(参见 7.39 [Internal], 44页)。
本命令将取消指定符号的可见度缺省值(可见度由其他命令捆绑设定:local, global, weak)
本命令将可见度设置为protected,这个可见度意味着:在定义此符号的部件内对此符号的任
何访问,都必须解析到这个部件内的定义体。即使其他部件中存在一个正常情况下比此优先
的定义体。
7.59 .psize lines, columns
Use this directive to declare the number of lines—and, optionally, the number of columns—to use
for each page, when generating listings.
If you do not use .psize, listings use a default line-count of 60. You may omit the comma and
columns specification; the default width is 200 columns.
as generates formfeeds whenever the specified number of lines is exceeded (or whenever you
explicitly request one, using .eject).
If you specify lines as 0, no formfeeds are generated save those explicitly specified with .eject.
7.59 .psize lines , columns
当生成清单列表时,使用本命令声明每页的行数—还可以可选地声明列数。
如果您不使用本命令,清单列表的行数为默认的60行。可以省略逗号和列参数:默认值为
200列。
当指定的行数过多的话,as会产生进纸操作。(如果您确实需要一个进纸动作,可以使用.eject
命令)
如果您指定行数为0,则不产生进纸操作,除非您明确地使用了.eject命令。
7.60 .purgem name
Undefine the macro name, so that later uses of the string will not be expanded. See Section 7.50
[Macro], page 47.
7.60 .purgem name
取消name的宏定义,后面使用字符串name不会被宏扩展。参见 7.50 [Macro], 47页。
7.61 .pushsection name , subsection
This is one of the ELF section stack manipulation directives. The others are .section (see Section
7.66 [Section], page 52), .subsection (see Section 7.79 [SubSection], page 56), .popsection (see
Section 7.56 [PopSection], page 50), and .previous (see Section 7.55 [Previous], page 49).
This directive is a synonym for .section. It pushes the current section (and subsection) onto the top
of the section stack, and then replaces the current section and subsection with name and subsection.
7.61 .pushsection name , subsection
本命令是一个ELF段堆栈操作命令。其余的几个是.section (参见 7.66 [Section], 52
页) , .subsection (参见7.79 [SubSection], 56页),.popsection (参见 7.56 [PopSection], 50页),
和 .previous (参见 7.55 [Previous], 49页)。
本命令与.section命令是等价的。它将当前段(及子段)推入段堆栈的顶部。并使用name
和subsection来替代当前段和子段。
7.62 .quad bignums
.quad expects zero or more bignums, separated by commas. For each bignum, it emits an 8-byte
integer. If the bignum won’t fit in 8 bytes, it prints a warning message; and just takes the lowest
order 8 bytes of the bignum.
The term “quad” comes from contexts in which a “word” is two bytes; hence quad-word for 8
bytes.
7.62 .quad bignums
.quad 可带0或多个bignum参数,每个参数由逗号分隔。对于每个bignum都汇编成一个8
字节的整数。如果某个bignum用8字节无法表示,则给出警告信息;只汇编这个bignum
的最低8字节。
术语“quad”源于一个“word”代表2个字节,所以quad-word代表8个字节。
7.63 .rept count
Repeat the sequence of lines between the .rept directive and the next .endr directive count times.
For example, assembling
.rept 3
.long 0
.endr
is equivalent to assembling
.long 0
.long 0
.long 0
7.63 .rept count
汇编.rept和.endr之间的语句count次。
如, 汇编下列语句:
.rept 3
.long 0
.endr
与下列语句是等价的:
.long 0
.long 0
.long 0
7.64 sbttl "subheading"
Use subheading as the title (third line, immediately after the title line) when generating assembly
listings.
This directive affects subsequent pages, as well as the current page if it appears within ten lines of
the top of a page.
7.64 sbttl "subheading"
当生成汇编清单时,使用subheading作为标题(第3行,紧跟在标题行之后)。
本命令对清单的后续页起作用,如果它位于当前页的前10行内,则对当前页也起作用。
7.65 .scl class
Set the storage-class value for a symbol. This directive may only be used inside a .def/.endef pair.
Storage class may flag whether a symbol is static or external, or it may record further symbolic
debugging information.
The ‘.scl’ directive is primarily associated with COFF output; when configured to generate
output format, as accepts this directive but ignores it.
7.65 .scl class
设置一个符号的存储类型值(storage-class value)。本命令只能在.def/.endef之间使用。符号
的存储类型可以表明符号是static类型或是external类型,或者进一步记录符号的调试信息。
‘.scl’命令主要与在COFF输出有关,当生成输出格式时,as接受本命令,但忽略本
命令。
7.66 .section name (COFF version)
Use the .section directive to assemble the following code into a section named name.
This directive is only supported for targets that actually support arbitrarily named sections; on
targets, for example, it is not accepted, even with a standard section name.
For COFF targets, the .section directive is used in one of the following ways:
.section name [, "flags"]
.section name [, subsegment]
If the optional argument is quoted, it is taken as flags to use for the section. Each flag is a single
character. The following flags are recognized:
b bss section (uninitialized data)
n section is not loaded
w writable section
d data section
r read-only section
x executable section
s shared section (meaningful for PE targets)
If no flags are specified, the default flags depend upon the section name. If the section name is not
recognized, the default will be for the section to be loaded and writable. Note the n and w flags
remove attributes from the section, rather than adding them, so if they are used on their own it will
be as if no flags had been specified at all.
If the optional argument to the .section directive is not quoted, it is taken as a subsegment number
(see Section 4.4 [Sub-Sections], page 25).
7.66 .section name (COFF 版本)
使用.section命令将后续的代码汇编进一个定名为name的段。
本命令只能在目标格式真正支持任意命名段时使用;例如,汇编一个目标格式时,即
使name是一个标准的段名,本命令也不被接受。
当目标格式为COFF时,.section命令的使用为下面某一种格式:
.section name[, "flags"]
.section name[, subsegment]
如可选参数使用了引号,它将被视为该段的标志(flags)。每个标记是单个的字符。下列是认
可的标志。
b bss 段 (未初始化的数据)
n 未装入内存的段
w 可写的段
d 数据段
r 只读段
x 代码段 (executable section)
s 共享段 (目标为PE格式有意义)
如果本命令没有指定标志,则依靠段名来确定标志缺省值。如果该段名没有使用标准段名,
则默认该段已装入内存并且可写。注意在使用n和w标志组合时,不是增加这组属性,而
是删除该段的属性。所以如果只存在这两个标志,就代表该段没有指定任何标志。
如果本命令的可选参数没有使用引号,参数将被视为子段的编号。(参见 4.4 [Sub-Sections],
25页)。
7.67 .section name (ELF 版本)
This is one of the ELF section stack manipulation directives. The others are .subsection (see
Section 7.79 [SubSection], page 56), .pushsection (see Section 7.61 [PushSection], page
50), .popsection (see Section 7.56 [PopSection], page 50), and .previous (see Section 7.55
[Previous], page 49).
For ELF targets, the .section directive is used like this:
.section name [, "flags"[, @type]]
The optional flags argument is a quoted string which may contain any combination of the
following characters:
a section is allocatable
w section is writable
x section is executable
The optional type argument may contain one of the following constants:
@progbits section contains data
@nobits section does not contain data (i.e., section only occupies space)
If no flags are specified, the default flags depend upon the section name. If the section name is not
recognized, the default will be for the section to have none of the above flags: it will not be
allocated in memory, nor writable, nor executable. The section will contain data.
For ELF targets, the assembler supports another type of .section directive for compatibility with
the Solaris assembler:
.section "name"[, ]
Note that the section name is quoted. There may be a sequence of comma separated flags:
#alloc section is allocatable
#write section is writable
#execinstr section is executable
This directive replaces the current section and subsection. The replaced section and subsection are
pushed onto the section stack. See the contents of the gas testsuite directory gas/testsuite/gas/elf
for some examples of how this directive and the other section stack directives work.
7.67 .section name (ELF 版本)
本命令是ELF的段堆栈操作命令之一,其他的段堆栈命令为.subsection (见 Section 7.79
[SubSection], page 56), .pushsection (见Section 7.61 [PushSection], page 50), .popsection (见
Section 7.56 [PopSection], page 50), and .previous (见 Section 7.55 [Previous], page 49).
当目标格式为ELF时,.section命令应如下使用:
.section name [, "flags"[, @type]]
可选参数flags是被引号包围的字符串,可以由下列字符的任意组合:
a 可分配的段(allocatable)
w 可写段
x 代码段
可选的参数type可以包含下列的任一常量:
@progbits 包含数据的段
@nobits 不包含数据的段(只占用空间的段)
如果本命令没有指定标志,则依靠段名来确定标志缺省值。如果段名不是标准的段名,则默
认的该段不包含上述标志:该段不可分配内存,不可写,不可执行。该段是包含数据的段。
当目标格式为ELF时,as还支持另一种形式的.section命令,以便兼容Solaris的汇编器:
.section "name"[, ]
注意段名是使用引号包围的,可能存在一系列由逗号分隔分隔的标志:
#alloc 可分配的段(section is allocatable)
#write 可写的段
#execinstr 可执行的段
本命令将(用段名为name的段)替代当前段和子段。被替换的段将被推入段堆栈。参见gas
的测试套件目录gas/testsuite/gas/elf,可以找到一些本命令和其他段堆栈操作命令的例子。
7.68 .set symbol, expression
Set the value of symbol to expression. This changes symbol’s value and type to conform to
expression. If symbol was flagged as external, it remains flagged (see Section 5.5 [Symbol
Attributes], page 30).
You may .set a symbol many times in the same assembly.
If you .set a global symbol, the value stored in the object file is the last value stored into it.
The syntax for set on the HPPA is ‘symbol .set expression’.
7.68 .set symbol, expression
设置symbol为expression。这将改变symbol的值域和类型领域以符合expression参数。如
果symbol已被标志为external,则symbol保持它的标志。(见 5.5 [Symbol Attributes], 30页)。
您可以在同一个汇编程序中多次使用.set命令来设置同一个符号。
如果设置一个全局符号,该符号在目标文件中值为最后设定的值。
在HPPA上的语法是‘symbol .set expression’。
7.69 .short expressions
.short is normally the same as ‘.word’. See Section 7.92 [.word], page 59.
In some configurations, however, .short and .word generate numbers of different lengths; see
Chapter 8 [Machine Dependencies], page 61.
7.69 .short expressions
本命令通常和’.word’命令一样,见7.92 [.word], 59页.
然而在某些配置中,.short和.word命令生成的数字长度却不相同;见第8章 [Machine
Dependencies], 61页.
7.70 .single flonums
This directive assembles zero or more flonums, separated by commas. It has the same effect
as .float. The exact kind of floating point numbers emitted depends on how as is configured. See
Chapter 8 [Machine Dependencies], page 61.
7.70 .single flonums
本命令可以汇编0个或多个浮点参数,各个参数之间使用逗号分隔。它的作用和.float相同。
生成浮点数的具体类型视as的配置而定。见第8章 [Machine Dependencies], 61页。
2024年6月10日发(作者:掌夜绿)
GNU汇编器as的用户手册。
Here is a brief summary of how to invoke as. For details, see section
Command-Line Options.
以下是调用as的命令概要,详细内容请见命令行选项一节。
as [ -a[cdhlns][=file] ] [ -D ] [ --defsym sym=val ]
[ -f ] [ --gstabs ] [ --help ] [ -I dir ] [ -J ] [ -K ] [ -L ]
[ --keep-locals ] [ -o objfile ] [ -R ] [ --statistics ] [ -v ]
[ -version ] [ --version ] [ -W ] [ -w ] [ -x ] [ -Z ]
[ -mbig-endian | -mlittle-endian ]
[ -m[arm]1 | -m[arm]2 | -m[arm]250 | -m[arm]3 | -m[arm]6 | -m[arm]7[t][[d]m[i]] ]
[ -m[arm]v2 | -m[arm]v2a | -m[arm]v3 | -m[arm]v3m | -m[arm]v4 | -m[arm]v4t ]
[ -mthumb | -mall ]
[ -mfpa10 | -mfpa11 | -mfpe-old | -mno-fpu ]
[ -EB | -EL ]
[ -mapcs-32 | -mapcs-26 ]
[ -O ]
[ -Av6 | -Av7 | -Av8 | -Asparclet | -Asparclite
-Av8plus | -Av8plusa | -Av9 | -Av9a ]
[ -xarch=v8plus | -xarch=v8plusa ] [ -bump ] [ -32 | -64 ]
[ -ACA | -ACA_A | -ACB | -ACC | -AKA | -AKB | -AKC | -AMC ]
[ -b ] [ -no-relax ]
[ -l ] [ -m68000 | -m68010 | -m68020 | ... ]
[ -nocpp ] [ -EL ] [ -EB ] [ -G num ] [ -mcpu=CPU ]
[ -mips1 ] [ -mips2 ] [ -mips3 ] [ -m4650 ] [ -no-m4650 ]
[ --trap ] [ --break ]
[ --emulation=name ]
[ -- | files ... ]
-a[cdhlmns]
Turn on listings, in any of a variety of ways:
打开清单输出选项,可以任意使用以下各种方法:
-ac
omit false conditionals
忽略假条件
-ad
omit debugging directives
忽略调试指示
-ah
include high-level source
包含高层源代码
-al
include assembly
包含汇编代码
-am
include macro expansions
包含宏扩展
-an
omit forms processing
忽略forms处理
-as
include symbols
包含符号表
=file
set the name of the listing file
设置清单文件名
You may combine these options; for example, use `-aln' for assembly listing
without forms processing. The `=file' option, if used, must be the last one.
By itself, `-a' defaults to `-ahls'.
你可以联合使用这些选项;例如,要获得未经过forms处理的汇编代码清单可使用 '-aln',
如果要使用 ‘=file’选项,它必须在最后一个位置,选项‘-a’缺省含义是'-ahls'。
-D
Ignored. This option is accepted for script compatibility with calls to other
assemblers.
忽略。为和使用其它汇编器的脚本兼容而保留。
--defsym sym=value
Define the symbol sym to be value before assembling the input file. value must
be an integer constant. As in C, a leading `0x' indicates a hexadecimal value,
and a leading `0' indicates an octal value.
处理输入文件前,定义符号sym的值为value。value必须是整形常量。同在'C'中一样,前导
字符'0x'标志十六进制值,前导字符'0'标志八进制值。
-f
"fast"---skip whitespace and comment preprocessing (assume source is compiler
output).
“加速处理”---跳过空白和注释处理(假定输入源文件是一可信赖的编译器产生的)
--gstabs
Generate stabs debugging information for each assembler line. This may help
debugging assembler code, if the debugger can handle it.
生成逐行的stabs格式调试信息,如果调试器可以处理这种格式的信息将有助于汇编代码调
试。
--help
Print a summary of the command line options and exit.
打印命令行选项概要后退出。
-I dir
Add directory dir to the search list for .include directives.
为.include汇编指示增加搜索目录。
-J
Don't warn about signed overflow.
不警告符号溢出。
-K
Issue warnings when difference tables altered for long displacements.
长跳切换表时发出警告。
-L
--keep-locals
Keep (in the symbol table) local symbols. On traditional systems these
start with `L', but different systems have different local label prefixes.
保留(符号表中的)局部符号。在传统的系统中这些符号有'L'前缀,但是在不同
的系统中有不同的局部符号前缀。
-o objfile
Name the object-file output from as objfile.
as输出的目标文件名。
-R
Fold the data section into the text section.
交迭数据段和代码段。
--statistics
Print the maximum space (in bytes) and total time (in seconds) used by
assembly.
打印汇编过程使用的最大空间(字节)和总计时间(秒)。
--strip-local-absolute
Remove local absolute symbols from the outgoing symbol table.
从输出符号表中移除局部绝对符号。
-v
-version
Print the as version.
打印as的版本。
--version
Print the as version and exit.
打印as的版本后退出。
-W
Suppress warning messages.
压制警告信息。
-w
Ignored.
忽略。
-x
Ignored.
忽略。
-Z
Generate an object file even after errors.
即使发生错误也要生成目标文件。
-- | files ...
Standard input, or source files to assemble.
标准输入或汇编源文件。
The following options are available when as is configured for an ARC processor.
以下选项,当配置as为ARC处理器时有效。
-mbig-endian
Generate "big endian" format output.
生成“大端”格式输出。
-mlittle-endian
Generate "little endian" format output.
生成“小端”格式输出。
The following options are available when as is configured for the ARM processor
family.
以下选项,当配置as为ARM处理器族时有效。
-m[arm]1 | -m[arm]2 | -m[arm]250 | -m[arm]3 | -m[arm]6 | -m[arm]7[t][[d]m] |
-m[arm]v2 | -m[arm]v2a | -m[arm]v3 | -m[arm]v3m | -m[arm]v4 | -m[arm]v4t
Specify which variant of the ARM architecture is the target.
指定不同的目标架构。
-mthumb | -mall
Enable or disable Thumb only instruction decoding.
禁止或使能仅用Thumb指令译码。
-mfpa10 | -mfpa11 | -mfpe-old | -mno-fpu
Select which Floating Point architcture is the target.
选择不同的浮点目标架构。
-mapcs-32 | -mapcs-26
Select which procedure calling convention is in use.
选择使用的调用习惯。
-EB | -EL
Select either big-endian (-EB) or little-endian (-EL) output.
选择大端(-EB)或小端(-EL)输出格式。
The following options are available when as is configured for a D10V processor.
以下选项,当配置as为D10V处理器时有效。
-O
Optimize output by parallelizing instructions.
优化并行指令输出。
The following options are available when as is configured for the Intel 80960
processor.
以下选项,当配置as为英特尔80960处理器时有效。
-ACA | -ACA_A | -ACB | -ACC | -AKA | -AKB | -AKC | -AMC
Specify which variant of the 960 architecture is the target.
指定不同的960目标架构。
-b
Add code to collect statistics about branches taken.
加入分支统计代码。
-no-relax
Do not alter compare-and-branch instructions for long displacements; error if
necessary.
不为长跳改变比较和分支指令;如果必须改变就发出错误指示。
The following options are available when as is configured for the Motorola 68000
series.
以下选项,当配置as为摩托罗拉68000系列处理器时有效。
-l
Shorten references to undefined symbols, to one word instead of two.
缩写未定义符号引用,用单字代替双字。
-m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060
| -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -mcpu32 | -m5200
Specify what processor in the 68000 family is the target. The default is
normally the 68020, but this can be changed at configuration time.
指定68000族的目标架构,缺省是普通的68020,可在配置时更改。
-m68881 | -m68882 | -mno-68881 | -mno-68882
The target machine does (or does not) have a floating-point coprocessor. The
default is to assume a coprocessor for 68020, 68030, and cpu32. Although the
basic 68000 is not compatible with the 68881, a combination of the two can be
specified, since it's possible to do emulation of the coprocessor instructions
with the main processor.
目标机有或没有浮点协处理器。缺省假定有68020,68030和cpu32的协处理器。虽然基本
的
68000和68881不兼容,但是通过主处理器的协处理器指令模拟,两者还是可以联合使用。
-m68851 | -mno-68851
The target machine does (or does not) have a memory-management unit
coprocessor. The default is to assume an MMU for 68020 and up.
目标机有或没有内存管理单元协处理器。缺省假定有68020或以上的内存管理单元。
The following options are available when as is configured for the SPARC
architecture:
以下选项,当配置as为SPARC架构处理器时有效。
-Av6 | -Av7 | -Av8 | -Asparclet | -Asparclite
-Av8plus | -Av8plusa | -Av9 | -Av9a
Explicitly select a variant of the SPARC architecture. `-Av8plus' and
`-Av8plusa' select a 32 bit environment. `-Av9' and `-Av9a' select a 64 bit
environment. `-Av8plusa' and `-Av9a' enable the SPARC V9 instruction set with
UltraSPARC extensions.
明确选择不同的SPARC架构。'-Av8plus'和'-Av8plusa' 选择32位环境。'-Av9' 和 '-Av9a'
选择64位环境。'-Av8plusa' 和 '-Av9a' 使用带UltraSPARC扩展的SPARC V9指令集。
-xarch=v8plus | -xarch=v8plusa
For compatibility with the Solaris v9 assembler. These options are equivalent
to -Av8plus and -Av8plusa, respectively.
兼容Solaris V9汇编器。这些选项分别等于-Av8plus和-Av8plusa。
-bump
Warn when the assembler switches to another architecture.
汇编器转换到其他架构时发出警告。
The following options are available when as is configured for a MIPS processor.
以下选项,当配置as为MIPS处理器时有效。
-G num
This option sets the largest size of an object that can be referenced
implicitly with the gp register. It is only accepted for targets that use
ECOFF format, such as a DECstation running Ultrix. The default value is 8.
设置可以被gp寄存器隐含引用对象的最大尺寸。这只是为目标代码格式为ECOFF的情况
而设置,例如运行Ultrix的DECstation。缺省值是8。
-EB
Generate "big endian" format output.
生成“大端”格式输出。
-EL
Generate "little endian" format output.
生成“小端”格式输出。
-mips1
-mips2
-mips3
Generate code for a particular MIPS Instruction Set Architecture level.
`-mips1' corresponds to the R2000 and R3000 processors, `-mips2' to the R6000
processor, and `-mips3' to the R4000 processor.
生成特定MIPS指令集架构层的代码。'-mips1'对应R2000和R3000处理器,'-mips2'对应R6000
处理器,'-mips3'对应R4000处理器。
-m4650
-no-m4650
Generate code for the MIPS R4650 chip. This tells the assembler to accept the
`mad' and `madu' instruction, and to not schedule `nop' instructions around
accesses to the `HI' and `LO' registers. `-no-m4650' turns off this option.
生成MIPS R4650芯片代码。告诉汇编器接受'mad'和'madu'指令,访问'HI'和'LO'寄存器时
不调整'nop'指令。'-no-m4650'关闭这个选项。
-mcpu=CPU
Generate code for a particular MIPS cpu. This has little effect on the
assembler, but it is passed by gcc.
生成特定MIPS cpu的代码,如果输入文件是经过gcc相应处理而得,对汇编器的影响不大。
--emulation=name
This option causes as to emulate as configured for some other target, in all
respects, including output format (choosing between ELF and ECOFF only),
handling of pseudo-opcodes which may generate debugging information or store
symbol table information, and default endianness. The available configuration
names are: `mipsecoff', `mipself', `mipslecoff', `mipsbecoff', `mipslelf',
`mipsbelf'. The first two do not alter the default endianness from that of the
primary target for which the assembler was configured; the others change the
default to little- or big-endian as indicated by the `b' or `l' in the name.
Using `-EB' or `-EL' will override the endianness selection in any case. This
option is currently supported only when the primary target as is configured
for is a MIPS ELF or ECOFF target. Furthermore, the primary target or others
specified with `--enable-targets=...' at configuration time must include
support for the other format, if both are to be available. For example, the
Irix 5 configuration includes support for both. Eventually, this option will
support more configurations, with more fine-grained control over the
assembler's behavior, and will be supported for more processors.
模拟其他目标架构,包括输出文件格式(ELF或ECOFF二者其一),伪指令处理,生成的调
试
信息,存储的符号表信息,以及缺省的大小端格式。有效的配置名是:`mipsecoff', `mipself',
`mipslecoff', `mipsbecoff', `mipslelf',`mipsbelf'。前两个不改变相应目标的缺省大小端格式。
其它的分别依据其配置名中包含的字符'b'或'l'改变目标代码的大小端格式。这个选项当前
只支持主目标代码格式是MIPS ELF或ECOFF的情况。另外,如果二者都是有效格式,主
目标格式或配
置时通过'--enable-targets=...' 指定的格式必须包含支持另一格式。例如Irix 5配置包含对二
者
的支持。最终这个选项将会支持更多的配置,对汇编器行为进行更细微的控制,而且会支持
更多的处理器。
-nocpp
as ignores this option. It is accepted for compatibility with the native
tools.
as忽略这个选项。这是为兼容本地工具而设。
--trap
--no-trap
--break
--no-break
Control how to deal with multiplication overflow and division by zero.
`--trap' or `--no-break' (which are synonyms) take a trap exception (and only
work for Instruction Set Architecture level 2 and higher); `--break' or
`--no-trap' (also synonyms, and the default) take a break exception.
控制如何处理乘法溢出和除零。'--trap'或'--no-break'(二者意义相同)导致陷阱(trap)异常
(只工作在指令集架构层2或更高);'--break'或'--no-trap'(二者意义相同,并且是缺省选项)
导致终止(break)异常。
Structure of this Manual
手册结构
This manual is intended to describe what you need to know to use GNU as. We
cover the syntax expected in source files, including notation for symbols,
constants, and expressions; the directives that as understands; and of course
how to invoke as.
本手册的目的是介绍GNU as的使用知识。包括源文件中的语法,符号标记,表达式,as能
够理解
和处理的指示标记;当然还有如何调用as。
This manual also describes some of the machine-dependent features of various
flavors of the assembler.
手册也介绍本汇编器在机器相关情况下的各种使用特点。
On the other hand, this manual is not intended as an introduction to programming
in assembly language--let alone programming in general! In a similar vein, we
make no attempt to introduce the machine architecture; we do not describe the
instruction set, standard mnemonics, registers or addressing modes that are
standard to a particular architecture. You may want to consult the
manufacturer's machine architecture manual for this information.
但另一方面,手册并不介绍汇编语言编程,同样也不会介绍特定机器架构的指令集,标准内
存,寄存器,
以及寻址方式。这方面信息您可以参考特定机器架构的生产商手册。
The GNU Assembler
GNU汇编器
GNU as is really a family of assemblers. If you use (or have used) the GNU
assembler on one architecture, you should find a fairly similar environment when
you use it on another architecture. Each version has much in common with the
others, including object file formats, most assembler directives (often called
pseudo-ops) and assembler syntax.
GNU as 实际上是一个汇编器族。如果你在一种架构上使用(或已经使用过)GNU汇编器,当
您
使用其它架构时,你会发现一个你熟悉的环境。每一个版本和其他版本有很大的共同之处,
包括目标文件格式,大部分的汇编指示(常被称作伪指令pseudo-ops)和汇编语法。
as is primarily intended to assemble the output of the GNU C compiler gcc for
use by the linker ld. Nevertheless, we've tried to make as assemble correctly
everything that other assemblers for the same machine would assemble. Any
exceptions are documented explicitly (see section Machine Dependent Features).
This doesn't mean as always uses the same syntax as another assembler for the
same architecture; for example, we know of several incompatible versions of
680x0 assembly language syntax.
as的主要目的是处理GNU的C编译器gcc的输出文件以便生成目标文件,从而被连接器ld
使用。
但是,我们尽量使as能够正确的汇编为其他汇编器生成的文件。例外情况有专门文档介绍(
见机器相关部分);但是这并不是意味着对于相同架构as和其它汇编器使用相同的语法;例
如:
我们知道有几个相互不兼容的680x0汇编语言语法。
Unlike older assemblers, as is designed to assemble a source program in one pass
of the source file. This has a subtle impact on the .org directive (see section
.org new-lc , fill).
和其他老汇编器不同,as被设计成对汇编源文件进行一次性处理。这对汇编指示.org将产生
微妙的影响(见.org new-lc ,fill部分)。
Object File Formats
目标文件格式
The GNU assembler can be configured to produce several alternative object file
formats. For the most part, this does not affect how you write assembly language
programs; but directives for debugging symbols are typically different in
different file formats. See section Symbol Attributes. On the machine specific,
as can be configured to produce either or COFF format object files. On the
machine specific, as can be configured to produce either or COFF format
object files. On the machine specific, as can be configured to produce either
SOM or ELF format object files.
GNU汇编器可以被配置成处理不同的目标文件格式。大部分情况下,并不影响你的汇编语
言编程;
但是,典型的符号调试汇编指示在不同的文件格式中不同。见符号属性部分。在某些机器
as可被
配制成生成或COFF目标文件,在某些机器as可被配制成生成或COFF目标文
件,
在某些机器as可被配制成生成SOM或ELF格式目标文件。
Command Line
命令行
After the program name as, the command line may contain options and file names.
Options may appear in any order, and may be before, after, or between file
names. The order of file names is significant.
程序名as之后的命令行包含选项和文件名,选项可以以任何顺序出现,可以在文件名之前
之后
或是其间出现,但是文件名出现的先后顺序是有含义的。
`--' (two hyphens) by itself names the standard input file explicitly, as one of
the files for as to assemble.
'--'(双链字符)的含义是标准输入文件,这时汇编器从标准输入获得输入文件。
Except for `--' any command line argument that begins with a hyphen (`-') is an
option. Each option changes the behavior of as. No option changes the way
another option works. An option is a `-' followed by one or more letters; the
case of the letter is important. All options are optional.
Some options expect exactly one file name to follow them. The file name may
either immediately follow the option's letter (compatible with older assemblers)
or it may be the next command argument (GNU standard). These two command lines
are equivalent:
as -o my-object-file.o mumble.s
as -omy-object-file.o mumble.s
除了'--'以外,任何以链字符'-'开始的参数都是选项参数。每一个选项都会更改as的处理方
式。
任何选项都不会更改其他选项的工作方式。每个选项都是以链字符'-'开始,后跟一个或多个
字符;字符大小写的含义是有区分的。所有的选项都是可选的。有些选项后面必须有正确的
文件
名跟随。文件名必须立即跟随在选项字符后面或者是这一选项参数后面紧跟着的那个参数位
子。
以下两个命令行是等价的:
as -o my-object-file.o mumble.s
as -omy-object-file.o mumble.s
Input Files
输入文件
We use the phrase source program, abbreviated source, to describe the program
input to one run of as. The program may be in one or more files; how the source
is partitioned into files doesn't change the meaning of the source.
The source program is a concatenation of the text in all the files, in the order
specified.
被as处理的汇编语言源程序可以放在一个或多个文件中,这并不改变源程序的内在含义,
源程序
可以被看作是所有这些文件按一定的顺序将文件中的文本串接而成。
Each time you run as it assembles exactly one source program. The source program
is made up of one or more files. (The standard input is also a file.)
You give as a command line that has zero or more input file names. The input
files are read (from left file name to right). A command line argument (in any
position) that has no special meaning is taken to be an input file name.
If you give as no file names it attempts to read one input file from the as
standard input, which is normally your terminal. You may have to type ctl-D to
tell as there is no more program to assemble.
Use `--' if you need to explicitly name the standard input file in your command
line.
If the source is empty, as produces a small, empty object file.
as每次处理一个源程序,源程序有一个或多个文件构成(标准输入也是一个文件),你可以在
命令
行给出或不给源文件名,如果给出多个源文件名,as就依次读入他们(从左到右)。命令行参
数(
任何位子)如果没有特别的定义就被当作一个输入文件名。如果你没有给出文件名,as就尝
试从标准
输入获得输入文件,通常就是从你的终端。你得通过键入ctl-d告诉as输入文件结束。你可
以在命令
行中使用'--'来明确告诉as你使用标准输入作为你的输入文件。如果源文件为空,as将产生
一个小的
空目标文件。
Filenames and Line-numbers
文件名和行号
There are two ways of locating a line in the input file (or files) and either
may be used in reporting error messages. One way refers to a line number in a
physical file; the other refers to a line number in a "logical" file. See
section Error and Warning Messages.
有两种方法来定位文件的行号,这些行号可以用来报告错误信息。一种是物理文件行号,
一种是逻辑文件行号。请参考错误和警告信息部分。
Physical files are those files named in the command line given to as.
Logical files are simply names declared explicitly by assembler directives; they
bear no relation to physical files. Logical file names help error messages
reflect the original source file, when as source is itself synthesized from
other files. See section .app-file string.
物理文件名指那些你在命令行中给出的文件名。逻辑文件名是指你在源文件中通过特定的汇
编指示
明确指定的简记名称。当as的源文件来自其他文件的合成时,逻辑文件名可以帮助定位产
生错误的
原始文件。
Output (Object) File
输出(目标)文件
Every time you run as it produces an output file, which is your assembly
language program translated into numbers. This file is the object file. Its
default name is , or when as is configured for the Intel 80960. You
can give it another name by using the -o option. Conventionally, object file
names end with `.o'. The default name is used for historical reasons: older
assemblers were capable of assembling self-contained programs directly into a
runnable program. (For some formats, this isn't currently possible, but it can
be done for the format.)
The object file is meant for input to the linker ld. It contains assembled
program code, information to help ld integrate the assembled program into a
runnable file, and (optionally) symbolic information for the debugger.
每次运行as都会产生输出文件,输出文件就是汇编器将你的汇编语言源程序翻译的结果。
这个由as产生的文件就是目标文件,却省文件名是,如果处理器配置为英特尔80960
缺省
就是。你可以通过设置-o选项更改输出文件名。习惯上目标文件名都以'.o'结尾。缺省
文件
名的使用是由于历史原因:老的汇编器可以从完善的汇编语言源程序直接生成可执行程序。
(
对有些格式来说这是不可能的,但是有些格式就可以,比如格式)产生目标文件的目的
是提供给
连接程序ld使用,以便生成可执行程序。目标文件一般只包含汇编过的程序代码,帮助ld
组织合并
目标文件以便生成可执行文件的信息,以及帮助调试器进行调试的信息。
Error and Warning Messages
错误和警告信息
as may write warnings and error messages to the standard error file (usually
your terminal). This should not happen when a compiler runs as automatically.
Warnings report an assumption made so that as could keep assembling a flawed
program; errors report a grave problem that stops the assembly.
Warning messages have the format
file_name:NNN:Warning Message Text
(where NNN is a line number). If a logical file name has been given (see section
.app-file string) it is used for the filename, otherwise the name of the current
input file is used. If a logical line number was given (see section .line
line-number) (see section .ln line-number) then it is used to calculate the
number printed, otherwise the actual line in the current source file is printed.
The message text is intended to be self explanatory (in the grand Unix
tradition).
Error messages have the format
file_name:NNN:FATAL:Error Message Text
The file name and line number are derived as for warning messages. The actual
message text may be rather less explanatory because many of them aren't supposed
to happen.
as通常会写警告和错误信息到标准错误文件(通常就是你的终端),但是如果as是被编译器
自动调用
的情况除外。警告信息通常表明你的程序有缺点但不会终止汇编过程,错误信息一般表明你
的程序
有致命错误将停止汇编过程。
警告信息有如下格式:
文件名:NNN:警告信息文本
(NNN是行号)。如果给出逻辑文件名(见.app-file string)就使用逻辑文件名,没有就使用当前
的输
入文件名。如果给出逻辑行号(见.line line-number)(见.ln line-number)就使用逻辑行号,没有
就
使用文件中的真实行号。警告信息文本一般会表明产生警告的原因(Unix的伟大传统)。
错误信息有如下格式:
文件名:NNN:FATAL:错误信息文本
文件名和行号的产生方式和警告信息相同。错误信息文本一般不能很好的解释产生错误的原
因,因为
通常情况下都假定他们不会发生。
2 命令行选项
这一章讲述所有版本的gnu汇编器中可用的命令行选项,如果想了解特定机器体系结构的相
关选项,请看61页(第八章的机器相关性)
如果你是通过GNU 编译器(版本2)调用as,你可以使用‘-Wa’选项,把参数传给汇编
器,这些参数(包括选项-Wa)必须使用逗号分隔。例如:
gcc -c -g -O -Wa,-alh,-L file.c
这个例子传递了两个参数给汇编器:‘-alh’(以高级语言和汇编语言的形式生成清单到标准
输出)‘-L’(在符号表中保留局部符号)。通常你没必要使用‘-Wa‘选项,因为编译器把
很多命令行选项自动传递给汇编器。(你可以通过’-v‘选项使用GNU编译器,来确切了解
有什么选项被传递给编译过程,包括传递给汇编器的选项)
2.1 Enable Listings: -a[cdhlns]
2.1 开启清单选项:-a[cdhlns]
这些选项开启了汇编器的清单输出。如果只有‘-a’选项,代表需要生成高级语言,汇编语
言和符号清单。你可以用其他字母去选择特定的清单选项:‘-ah’需要生成一个高级语言清
单,'-al '需要生成一个输出程序的汇编语言清单,‘-as’需要生成符号表的清单。生成高级语
言清单需要使用一个‘-g‘之类的编译调试选项,汇编语言清单(’-al’)也需要上述调试
选项。
删去清单中汇编条件为false的语句,下列语句行不进行汇编:一个条件为false的.if语句块
(或是.ifdef语句块,或是其他的条件汇编语句块),条件为true的.if后面的那个.else语句块,
所有没有被汇编行都会从清单中删去。
使用选项‘-ad’删除清单中的调试命令。
一旦你使用了上述某个选项,你就可以使用.list ,.nolist,.psize,.title,和.sbttl 命令进一步控制清
单输出格式。选项‘-an’关闭所有清单表格的处理过程。如果你不需要输出清单,就不必
使用一个‘-a’系列的选项,那么清单控制命令就没有效果。
选项‘-a’后的字母可以合成一个选项(例如‘-aln’)。
注意,如果汇编源码来自标准输入(例如源码是由GCC创建,并且使用了‘-pipe’命令行
开关),则清单中不含有注释和预处理命令。这是因为只有在源代码必须被汇编器预处理后,
清单代码缓冲区才从标准输入中读取源代码行。这样减少了内存的使用,并且使生成的代码
更有效率。
2.2 -D
这个选项没什么作用,但as接受这个选项,使那些写给其他汇编器的脚本文件也能被as使
用。
2.3 Work Faster: -f
2.3 加快汇编:-f
只有在被汇编程序的源码是由可信任的编译器产生的情况下,才能使用‘-f’选项。 使用
选项‘-f’时,如果汇编器在汇编输入文件前要对它们进行空格和注释的预处理,则会终止
汇编器的汇编。
警告:如果文件事实上需要预处理时(如果它们包含有注释),而你使用了‘-f’,as将不能
正常工作。
2.4 .include search path: -I path
2.4 .include命令搜索路径的选项: -I path
使用这个选项给目录清单加一个路径path,这个目录清单是.Include命令在搜索指定文件使用
的,(见 7.37 [ .include],第44页)。 你可以视需要多次使用‘-I’来加入不同的路径。第一
个搜索的总是当前工作目录;然后,as安照命令行中的顺序(从左到右)搜索‘-I’选项指定
的目录。
2.5 Difference Tables: -K
altered
在as中使用‘.word sym1-sym2’形式的命令有时会改变生成的代码(参考Section 7.92
[ .word],page 59)。如果在遇到上述情况时您希望as会发出一个警告,您可以使用选项‘-K’。
2.6 Include Local Labels: -L
2.6包含局部标签:-L
以‘L’(必须大写)字母开头的标签叫做局部标签(参考Section 5.3 [Symbol Names],page 29)。
通常调试时你看不见它们,因为它们是供生成汇编源程序的程序(如编译器)使用的,而不
是为了引起你的注意。一般来讲as和ld丢弃这些标签,所以你不能用它们来调试。
这个选项让as在目标文件中保留那些‘L…’符号。一般如果你这样做了,你也应该让连接
器ld保留那些以符号名‘L’ 开头的符号。
默认情况下,以‘L’开始的标签是一个局部标签,不过每一个目标允许重新定义一个局部
标签的前缀。在HPPA上,局部标签以‘L$’开始。
2.7 Configuringh listing output: --listing
通过命令行开关‘-a‘可以开启汇编程序的清单功能(see
Section 2.1 [a], page 11)。这个功能使输入源文件和输出目标文件的16进制映象组合起来,
并且以清单文件的形式显示它们。清单的格式可以通过汇编源代码中的伪操作来控制(参考
Section 7.48 [List], page 47 ;Section 7.83 [Title], page 57 ;Section 7.64 [Sbttl], page 51 ;
Section 7.59 [Psize], page 50 ; Section 7.14 [Eject], page 40)也可以通过以下开关:
--listing-lhs-width=‘number’
设置16进制字节映象第一行的最大宽度,宽度单位为字(16位)。这个映象显示在清单输
出的左边。
--listing-lhs-width2=‘number’
由给定的源代码行生成的16进制字节映象,设置这个映象的除第1行外的所有行的最大宽
度,宽度单位为字。如果没有指定宽度值,那它默认等于‘--listing-lhs-width’的设定值。
如果两个开关都没指定,那么默认值是1。
--listing-rhs-width=‘number’
设置源代码行的最大宽度,宽度单位字符数,源代码显示在16进制映象旁边。默认宽度值
是100。源代码行显示在输出清单的右边。
--listing-cont-lines=‘number’
对于给定的一行源代码输入,设置16进制映象连续行数的最大值。默认值是4。
2.8 Assemble in MRI Compatibility Mode: -M
以MRI兼容模式汇编
选项 –M 或 –-mri 选择 MRI 兼容模式。它改变了 as 的语法和伪操作处理,使它兼容
于Microtec Research 的 ASM68K 或者 ASM960 (视配置目标而定)汇编器。这里没有给
出 MRI 语法具体形式,您可以查看 MRI 的手册。需要特别注意的是宏和宏参数的处理有
一些不同。这个选项的目的是允许使用 as 汇编现存的MRI汇编器代码。
与MRI的兼容工作没有做完。MRI 汇编器的具体操作依赖于目标文件格式,使用其他目标
文件格式不支持这些操作。要想支持这些需要分别增强目标文件格式。它们是:
•公共段中的全局符号
M68K的MRI汇编器允许使用公共段,公共段将被连接器合并。其它目标文件格式并不支
持使用公共段。 as 通过把公共段看成一个单独的普通符号来处理它。它允许在公共段中定
义局部符号,但是它不支持公共段中全局符号,因为没法描述它们。
•复杂重定向
MRI汇编器允许错误段址的重定向,允许联合了多个段的起始地址的重定向。其它目标文
件格式都不支持这些。
• END伪操作指定的启始地址
MRI中的END伪操作允许指定一个开始地址。其它目标文件格式不允许这么做。你也可以
对连接程序使用选项 ‘-e’来指定起始地址,也可以在连接脚本中指定。
IDNT, .ident and NAME伪操作
MRI 中的IDNT, .ident 和 NAME 伪操作给输出文件分配一个模块名。其它目标文件格式
不支持。
ORG 伪操作
m68k的MRI中ORG伪操作在一个给定的地址开辟一个具有独立地址的段。这和通常的 as
的 .ORG 伪操作不同,它在当前的段中改变定位。别的目标文件格式不支持独立段。因为
一个段的地址可能在连接脚本中分配。
还有一些MRI汇编器的功能as不支持,大体上,它们都难于实现,而且似乎无关紧要。其
中的一些特性可能在今后的版本中将会支持。
•EBCDIC strings
不支持EBCDIC 字符串。
•packed binary coded decimal
不支持包装BCD 码。这表示不支持 DC.P 和 DCB.P 伪操作。
•FEQU pseudo-op
不支持m68k 的 FEQU 伪操作。
•NOOBJ pseudo-op
不支持m68k 的 NOOBJ 伪操作。
•OPT branch control options
忽略 m68k 的OPT分支控制选项—B, BRS, BRB, BRL, 还有BRW。as 自动的放松所有的
分支(不管是向前还是向后)到一个合适的大小,所以这些选项不起作用。
•OPT list control options
以下m68k的OPT清单控制选项被忽略:C, CEX, CL, CRE, E, G, I, M, MEX, MC, MD, X.
•other OPT options
以下的m68k的OPT选项被忽略:NEST, O, OLD, OP, P, PCO, PCR, PCS, R.
•OPT D option is default
不象 MRI 汇编程序,m68k OPT的选项D是默认的。可以用选项 NOD 关闭它。
• XREF pseudo-op.
忽略m68k的XREF。
• .debug pseudo-op
不支持i960 的.debug伪操作。
•.extended pseudo-op
不支持 i960 的 .extended 伪操作。
•.list pseudo-op.
不支持 i960 的 .list 伪操作的各种选项。
•.optimize pseudo-op
不支持 i960 的 .optimize 伪操作。
•.output pseudo-op
不支持 i960 的 .output 伪操作。
•.setreal pseudo-op
不支持 i960 的 .setreal 伪操作。
2.9 Dependency tracking: --MD
2.9 相关性跟踪:--MD
as can generate a dependency file for the file it creates. This file consists of a single rule
suitable for make describing the dependencies of the main source file.
The rule is written to the file named in its argument.
This feature is used in the automatic updating of makefiles.
as 能为它创造的文件产生一个从属文件。这个文件包括一个合适的单一规则,用来描述主
要的源文件的依赖性。
规则写进文件,文件名规则的参数中指定。
自动更新 makefiles 使用了这个功能。
2.10 Name the Object File: -o
2.10 命名目标文件:-o
当你运行 as 时,总是产生一个目标文件。在默认的情况下,它的名字是 ’(或者是
‘’仅对 Intel 960 )。你用这个选项(选项后跟一个文件名)给目标文件指定一个不
同的文件名。
不管目标文件叫什么,as覆盖现存的同名文件。
2.11 Join Data and Text Sections: -R
2.11 连接数据段和正文段:-R
选项 -R 让 as 输出目标文件,在目标文件中数据段中的数据保存在正文段。这一步只在最
后做:你得到的二进制数据一样,可是数据段部分的重定向不同。你的目标文件的数据段部
分只有零字节长度,因为所有的字节都被追加到代码段后面(第4章 [Sections and
Relocation], 23页.)
当你指定了选项 –R ,它可能会产生更短的地址移动(因为我们不必在数据段和代码段之
间转移)。为了兼容老版本的 as 我们应尽量避免使用这个选项。以后,可以使用–R 这样
做。
as 配置成输出 COFF 的文件格式,只有你使用名字为 ‘.text’ 和 ‘.data’ 的段时,这
个选项才有用。
任何HPPA处理器的目标格式都不支持选项 –R 。如果使用了,as 会产生一个警告。
2.12 Display Assembly Statistics: --statistics
2.12 列出汇编的统计资料: --statistics
使用 ‘--statistics’ 来显示 as 使用资源的两个统计数据:汇编时分配的最大空间(字节)
和汇编过程的花费的时间(占用cpu的秒数)。
2.13 Compatible output: --traditional-format
2.13 兼容输出: --traditional-format
对一些目标格式来讲,as 的输出和一些现存的汇编器有点不同。这个开关要求 as 使用传
统的格式。
例如,它关闭了异常结构优化,而在默认情况下,as对gcc的输出都进行异常结构优化。
2.14 显示版本: -v
通过在命令行中加上选项 ‘-v’ (也可写成 ‘-version’),你能找出当前运行as的版本号。
2.15 Control Warnings: -W, --warn, --no-warn,
--fatal-warnings
2.15 控制警告选项: -W, --warn, --no-warn,--fatal-warnings
当 as 汇编编译器的输出时,从不发出警告或错误信息。但人们写的程序经常引发as产生
警告,警告指出已触发了一个特定的条件。这些警告都被定向到标准的错误文件。
如果你使用了选项 –W 和 --no-warn ,就不会产生警告。这只影响到警告的信息:它不会
影响到as如何汇编你的文件。而错误,将会终止汇编过程,仍会被报告。
如果使用选项 --fatal-warnings ,as将认为那些产生警告的文件含有错误。
你可以通过指定选项 –-warn 来关掉这些选项,使那些警告正常输出。
2.16 Generate Object File in Spite of Errors: -Z
2.16 在讨厌的错误中生成目标文件: -Z
当出现了一个错误信息,as 通常不产生输出。如果as对你的程序给出错误信息后,你对目
标文件感兴趣的话,可以使用选项 ‘-Z’。即使发生任何错误,as会继续进行汇编,最后发
出一条警告信息‘n errors, m warnings , generating bad object file.’,然后生成一个(坏的)目
标文件
3 语法
本章描述在各种机器平台上源程序文件可以使用的语法。as的语法与其他众多的汇编器都
很相似;它深受BSD4.2汇编器的影响,只是as不可以汇编Vax的位域(Vax bit-fields?)。
/*没有机会学习接触过Vax机器,这里指的是什么?*/
3.1 预处理
as的内部预处理:
*调整并删除多余的空白字符。在每行的关键字前保留一个空格或制表字符,并把每行中其
他的空白字符转换为一个空格字符。
*删除所有的注释,在注释处使用一个空格字符或者适当数量的换行字符进行替换。
*将字符常量转换为适当的数值。
as的内部预处理不进行宏处理,引入文件的操作处理,或者可以由C编译器预处理做好的
其它任何事项。您可以使用 .include命令 (参见 7.37 [.include], 44页)做引入文件的工作。
可以使用GNU C编译器(原文为gnu C compiler driver)获得一种“CPP”风格的预处理:方
法是给编译器一个“.S”尾缀的输入文件进行编译。见Using GNU CC中的“Options Controlling
the Kind of Output”一章
如果输入文本不经过预处理,则不可以在其中使用多余的空白,注释,和字符常量。
如果一个输入文件的首行是#NO_APP或者您使用了‘-f’选项,则不删除输入文件中的空
白和注释。在一个输入文件内,在可能包含空白和注释的文本前,您可以增加一个#APP
行,以请求删除这些部分的空白和注释,并在此文本后增加一个#NO_APP行。这个特征主
要用来支持编译器输出的汇编语句,这些语句往往包含大量的注释和空白。
3.2 空白
空白是指一个或多个空格符或制表符,它们可以是任意的次序。空白一般用来分隔符号,并
使程序更整洁以便人们阅读。除了在字符常量中的空白(参见 3.6.1 [Character Constants], 19
页),任意个数的空白和一个空格符是等价的。
3.3 注释
有两种方法表示注释。用这两种方法表示的注释都等价于一个空格符。
一切以/*开始的语句到下一个*/都是一个注释。这意味着您不能嵌套使用注释。
/*
这是唯一可以在一个注释中包含换行符(’n’)的方法。
*/
/* 使用这种方法注释不能进行嵌套 */
从行注释符开始到换行符的一切语句都被当作注释而忽略。AMD 29K系列的行注释符为
‘;’;ARC上为‘;’ARM上为‘@’; H8/300系列为‘;’;H8/500系列为‘!’; HPPA
上为‘;’;i386和x86-64家族为‘#’;i960上为‘#’;PDP-11上为‘;’;picoJava上为‘;’;
Hitachi SH上为‘!’;SPARC上为‘!’;m32r上为‘#’;680x0上为‘|’;68HC11 和 68HC12
上为‘#’;M880x0上为‘;’;Vax上为‘#’;Z8000上为‘!’; V850上为‘#’;参见第8
章[Machine Dependencies],61页。
某些机器上有两种不同的行注释符。一个只用作行中第一个字符是非空白字符的注释的开
始。而另一个可以用作注释的开始。
V850的汇编器还允许使用双破折号作为注释的开始,注释到行末为止。
为了兼容旧的汇编器,以‘#’开始的行具有特殊的意义。‘#’后面可以是一个纯粹表达式(参
见第6章[Expressions], 33页): 下一行的逻辑行号。后面还允许一个字符串(参见3.6.1.1
[Strings], 19页):如果存在,这个字符串是一个新的逻辑文件名。行的剩余部分,即便存在,
也应该是空白。
If the first non-whitespace characters on the line are not numeric, the line is ignored.(Just like a
comment.)
如果行中第一个非空白字符不是数字,此行被忽略。(如同注释一样)
# 这是一行普通的注释。
# 42-6 "new_file_name" # 新的逻辑文件名
# 这是一个逻辑行 # 36.
不建议使用这个特性,as未来的版本可能不再支持这个特性。
3.4 符号
符号是由一个或多个字符组成的,其中的字符可以是字母(大小写),数字和三个特殊字符
‘_.$’。在绝大多数机器上,您可以在符号名中使用字符$;注意有些例外,见第8章。[Machine
Dependencies], 61页。
符号名不能以数字开始,而且对大小写敏感。符号名没有长度限制:符号名的所有字符都有
意义。符号使用规定字符之外的字符定界;或者使用文件头(因为源文件中必须使用换行符
结束,文件尾不可能作为符号的定界符)。
3.5 语句
一个语句使用换行字符(‘n’)或者行作为行分隔符的字符结束。(除非与注释字符冲突,
行分隔符一般为‘;’;参见第8章[Machine Dependencies], 61页)换行符和分隔符被当作语
句的一部分。在字符常量中的换行符和分隔符例外:它们此时不是语句的结尾。
不能以文件结束来自动结束语句:任何输入文件的最后一个字节应该是换行符。
/*
译者注:作者的在这里的意思大概是文件最后一个语句的最后一个换行符号/分隔符不能省
略。Fix me!
*/
允许使用空语句,并且空语句中可以包括空白。空语句会被忽略。
一个语句可以以0个或多个标签开始,后面可带一个关键符号,这个关键符号决定语句的种
类。关键符号决定这个语句剩余部分的语法。如果符号以点‘.’开头,则此语句是一个汇
编器命令:这个规律对所有的机型都适用。如果符号以一个字母开头,则此语句是一个汇编
语言的机器指令:这个符号被汇编成机器语言指令。用于各种机型的as版本能够识别各自
机型的机器指令。实际上,在不同的机型上的相同符号可能代表不同的指令。
标签是一个后面跟着冒号(:)的符号。允许在标签的前后使用空白,但不能插在符号和冒
号之间。参见5.1 [Labels], 29页.
如果是HPPA目标格式的话,标签不必有冒号,但标签的定义必须从第0列开始。这同时意
味着每行只能定义一个标签。
label: .汇编器命令 后跟一些东西
another_label: # 这是一个空语句
指令 操作数_1, 操作数_2, ...
3.6 常量
一个常量是一个数字,写成各种形式,检查时得到它的值,而不是它的内容。如下:
.byte 74, 0112, 092, 0x4A, 0X4a, ’J, ’J # 全部是同一个值。
.ascii "Ring the bell7" # 一个字符串常量。
.octa 0x123456789abcdefABCDEF0 # 一个巨数。
.float 0f-3979323846264338327
95028841971.693993751E-40 # - pi, 一个浮点数。
3.6.1 字符常量
有两种类型的字符常量。一个字符代表一个单字节字符,并且它的值可以用数字表示。字符
串常量(严格来说叫做string literals)可以有多个字节,并且不能用算术表达式表示。
3.6.1.1 字符串
字符串被写在双引号之间。字符串可以包含双引号null字符。在字符串中使用特殊字符的
方法是增加逃逸符号:在特殊字符前插入一个反斜杠字符‘’。例如‘’代表一个反斜杠:
第1个是一个逃逸符号,它通知as把后面的字符当做反斜杠(防止as把第2个当作逃逸
符号)。下面有完整的特殊字符表:
b 退格的助记符号;它的八进制ASCII码为010。
f 进纸的助记符号;它的八进制ASCII码为014。
n 换行的助记符号;它的八进制ASCII码为012。
r 回车的助记符号;它的八进制ASCII码为015。
t 水平制表的助记符号;它的八进制ASCII码为011。
ddd
一个八进制的字符编码。这个数字编码是3个八进制阿拉伯数字。为了兼容其他的Unix系
统,8和9同样接受:例如,008 为八进制010, 009为八进制011。
x 16进制数字
一个16进制字符编码。x后所有数字都是的组合在一起的。大小写的x都可以。
表示一个‘’字符。
" 表示一个"字符。这个字符在字符串中必须这样表示,因为一个非逃逸的"字符代表字符串
结束。
其他字符
任何跟在后的其他字符将会引发一个警告,并如同不存在‘’一样汇编。这样做的意图是:
当您确实不想as解释后面的字符时,您可以使用这样一个逃逸序列。无论如何,as不进行
其他的解释,所以as知道自己在汇编不正常的编码,并警告用户真实的情况。
使用逃逸字符的字符,和这些字符所代表的值,在不同的汇编器上会有相当大的差别。当前
逃逸字符集是我们认为在BSD 4.2汇编器上被认可的,并且是决大多数C编译器所认可的
子集。如果您有所怀疑,请不要使用逃逸序列。
3.6.1.2 字符
一个单独的字符可以写成一个单引号后紧跟那个字符。
字符使用逃逸符号的情况与字符串相同。所以如果您想使用反斜杠字符,就必须写成 ’,
其中第1个是逃逸符号,第2个是字符。正如你看到的一样,引号是一个高音符,而不是
一个低音符。紧跟在高音符后的换行符被当作文字字符处理,并不当作语句的句尾。
字符常量的值如用数字表达,则等于此字符在该机型上的字节编码。As假定您使用的是
ASCII码:’A等于65,’B等于66,以此类推。
3.6.2 数字常量
as依靠数字在目标文件中的存储方式区分3种类型的数字。整数(Integer)是适合C语言
中int类型的数字。巨数(Bignum)是需要超过32位来存储的整数。浮点数(Flonums)是
后面具体描述的浮点数。
3.6.2.1 整数
2进制的整数由‘0b’ 或 ‘0B’打头,后跟0个或多个2进制数字‘01’
8进制的整数由由‘0’打头,后跟0个或多个8进制数字(‘01234567’)。
十进制整数由一个非零的数字打头,后跟后跟0个或多个十进制数字(‘’)。
16进制整数由‘0x’或0X打头,后跟一个或多个16进制的数字,这些数字可以是
‘abcdefABCDEF’。
整数都有值,如要指定一个负整数,要使用前缀‘-’,前缀在表达式一节有讨论(参见6.2.3
[Prefix Operators], 34页)。
3.6.2.2 巨数
巨数使用和整数一样语法和语意学,但一个2进制的巨数将使用超过32个位来表示。巨数
和整数的区别是:某些允许使用整数的地方却不允许使用巨数。
3.6.2.3 浮点数
Flonum代表一个浮点数。这个转换是间接的:文本中的十转换为进制浮点数被as转换为更
高精度的2进制浮点数。这种2进制浮点数被转换为某个特定机型的浮点格式,这个工作由
针对该机型的as专用部分实现。
浮点数的书写规则(规则也有次序)
* 数字‘0’(‘0’在HPPA上是可选的。)
* 一个字母,通知as本数字的剩余本分是浮点数。推荐使用字母e,大小写都行。
在H8/300, H8/500, Hitachi SH,和AMD 29K等机型上,上述字母必须使用‘DFPRSX’之中
的一个(大小写都行)。
在ARC上,上述字母必须使用‘DFRS’之中的一个(大小写都行)。
在intel 960上,上述字母必须使用‘DFT’之中的一个(大小写都行)。
在HPPA上,上述字母必须使用‘E’(只能大写)。
* 可选的符号:‘+’或‘-’两者中任一个。
* 可选的整数部分:0或多个十进制数字。
* 可选的小数部分:小数点‘.’后跟0个或多个十进制数字。
* 可选的指数本分,由下列组成:
* 一个‘E’或‘e’
* 可选的符号:‘+’或‘-’两者中任一个。
* 一个或多个十进制数字。
至少要存在一个整数部分或一个小数部分。浮点数一般是以10为底数的值。
as的使用整数(硬件单元)进行所有的处理。当运行as时,浮点数的计算不使用计算机中
任何的浮点硬件。
4.1 Background
Roughly, a section is a range of addresses, with no gaps; all data 'in' those addresses is treated the
same for some particular purpose. For example there may be a 'read only' section.
粗略地说,一个段是一个连续的地址范围;在地址范围内的所有数据都接受相同的加工,以
适应特殊的目的。例如,可能存在一个‘只读’段。
The linker ld reads many object files (partial programs) and combines their contents to form a
runnable program. When as emits an object file, the partial program is assumed to start at address
0. ld assigns the final addresses for the partial program, so that different partial programs do not
overlap. This is actually an oversimplification, but it suffices to explain how as uses sections.
连接器ld读取多个目标文件(局部程序),把他们组合在一起,以形成一个可运行的程序。
当as生成一个目标文件时,这个局部程序的首地址假定为0。ld为局部程序分配最终地址,
所以不同的局部程序不回重叠。这么说实际上过分的简化了,但足以解释as如何使用段。
ld moves blocks of bytes of your program to their run-time addresses. These blocks slide to their
run-time addresses as rigid units; their length does not change and neither does the order of bytes
within them. Such a rigid unit is called a section. Assigning runtime addresses to sections is called
relocation. It includes the task of adjusting mentions of object-file addresses so they refer to the
proper run-time addresses. For the H8/300 and H8/500, and for the Hitachi SH, as pads sections if
needed to ensure they end on a word (sixteen bit) boundary.
ld负责把您的程序块移动至运行地址。这些块作为固件可以改变位置。它们的长度不可改变,
内部的字节顺序也不会改变。这样的一个固件被称为一个段。为段分配运行地址叫做重定位。
它包括调整相关的目标文件的地址,以便将它们装入恰当的运行地址。针对H8/300 ,H8/500,
Hitachi SH,如果需要对齐段尾到word(16位)边界,as会填充这些段。
-
An object file written by as has at least three sections, any of which may be empty.
These are named text, data and bss sections.
一个由as生成的目标文件至少具有3个段,某些可能是空段。这3个段分别叫正文段(text),
数据段,bss段。
--------------------------------------------------------------------------------
When it generates COFF output, as can also generate whatever other named sections you specify
using the .section directive (see Section 7.66 [.section], page 52). If you do not use any directives
that place output in the text or data sections, these sections still exist, but are empty.
当它生成COFF格式的输出时,as也能够生成其它段,段名通过使用.section命令指定(见7.66
[.section], 52页)。即使您不使用任何能够在正文段和数据段中产生输出命令,这些段仍然存
在,但它们是空段。
When as generates SOM or ELF output for the HPPA, as can also generate whatever other named
sections you specify using the space and subspace directives. See HP9000 Series 800 Assembly
Language Reference Manual (HP 92432-90001) for details on the space and subspace assembler
directives.
当as为HPPA生成SOM或ELF格式的输出时,as也能够生成其它名字的段,您可以使
用.space和.subspace命令。见在《HP9000 Series 800 Assembly Language Reference Manual》
(HP 92432-90001)的.space和.subspace汇编命令中有详尽的描述。
Additionally, as uses different names for the standard text, data, and bss sections when generating
SOM output. Program text is placed into the ?CODE$? section, data into ?DATA$? and BSS
into ?BSS$? Within the object file, the text section starts at address 0, the data section follows, and
the bss section follows the data section.
另外,当生成SOM格式的输出文件时,as使用不同的名字来命名标准的正文段,数据段和
bss段,程序的正文被放进‘$CODE$’段,数据被放进‘$DATA$’段,BSS被放进‘$BSS$’
段。
在目标文件中,正文(text)段由地址0开始,数据段跟随正文段,BSS段跟随数据段。
When generating either SOM or ELF output files on the HPPA, the text section starts at address 0,
the data section at address 0x4000000, and the bss section follows the data section.
当在HPPA上生成SOM或ELF输出文件时,正文段从地址0开始,数据段由地址0x4000000
开始,BSS段跟随在数据段的后面。
To let ld know which data changes when the sections are relocated, and how to change that data,
as also writes to the object file details of the relocation needed. To perform relocation ld must
know, each time an address in the object file is mentioned:
为了让ld清楚在段重定位时那个数据有变化,怎样变化,as也把重定位需要使用信息细节
写入目标文件。为了完成重定位,ld必须清楚目标文件中每次声明的地址。
•Where in the object file is the beginning of this reference to an address?
寻址指令的首字节在目标文件中的何处?
•How long (in bytes) is this reference?
寻址指令的长度(单位字节)?
•Which section does the address refer to? What is the numeric value of (address) -
(start-address of section)?
•寻址的目标是哪个段?地址的数值是多少-(段首的地址)?
•Is the reference to an address “grogram-Counter relative?”
•本次寻址的地址是“程序-计数器相对地址吗?(Program-Counter relative)”
In fact, every address as ever uses is expressed as
(section) + (offset into section)
实际上,as使用的每个地址都表示为下列形式:
(段)+(段内偏移)
Further, most expressions as computes have this section-relative nature. (For some object formats,
such as SOM for the HPPA, some expressions are symbol-relative instead.)
更进一步地说,大多数表达式一般都通过这种段-相对地址(section-relative)来计算。(某些
目标格式,如HPPA上的SOM,部分表达式使用符号-相对地址)
In this manual we use the notation {secname N} to mean “offset N into section secname.”
在本手册中,我们使用符号{secname N}来表示“在secname段中的偏移量N”
Apart from text, data and bss sections you need to know about the absolute section. When ld
mixes partial programs, addresses in the absolute section remain unchanged. For example, address
{absolute 0} is “relocated” to run-time address 0 by ld. Although the linker never arranges two
partial programs’ data sections with overlapping addresses after linking, by definition their
absolute sections must overlap. Address {absolute 239} in one part of a program is always the
same address when the program is running as address {absolute 239} in any other part of the
program.
除了正文段,数据段和 bss段之外,您还要了解地址独立段(absolute section)。当ld连接
各个局部程序时,在地址独立段中的地址将保持不变。例如,地址{absolute 0}被ld重定位
到运行地址0处。虽然连接器从来不把两个局部程序数据段的地址重叠,但定义过的地址独
立段必须重叠。程序中的某部分地址{absolute 239}与程序中的其它部分地址{absolute 239}
总是相同的运行地址。
The idea of sections is extended to the undefined section. Any address whose section is unknown
at assembly time is by definition rendered {undefined U}-where U is filled in later. Since numbers
are always defined, the only way to generate an undefined address is to mention an undefined
symbol. A reference to a named common block would be such a symbol: its value is unknown at
assembly time so it has section undefined.
段的概念延伸到未定义段(undefined section)。段信息不明确的地址在汇编时被定义为
{undefined U}-U稍后加载。因为数字总是定义好的,唯一生成未定义地址的途径是使用一
个未定义的符号。访问一个指定的通用块(common block)将生成这样的一个符号:在汇编
时不知道它的值域,所以它是一个未定义段。
By analogy the word section is used to describe groups of sections in the linked program. ld puts
all partial programs’ text sections in contiguous addresses in the linked program. It is customary to
refer to the text section of a program, meaning all the addresses of all partial programs’ text
sections. Likewise for data and bss sections.
如此类推,段在连接好的程序中也经常用来表示多个段组成的段群。在连接好的程序中,ld
将所有局部程序的正文段都放在连续的地址中。这是一个习惯,访问一个程序的正文段,表
示所有的局部程序的正文段的所有地址。对数据段和bss段来说,也是同样的道理。
Some sections are manipulated by ld; others are invented for use of as and have no
meaning except during assembly.
有些段由ld来操作。有些段则是为as而设,除了汇编时有用,其他时间全无意义。
4.2 Linker Sections
ld deals with just four kinds of sections, summarized below.
Ld处理四个类型的段,下面总结一下:
named sections
text section
data section
These sections hold your program. as and ld treat them as separate but equal sections. Anything
you can say of one section is true another. When the program is running, however, it is customary
for the text section to be unalterable.
段名
正文段
数据段
这两种段保存您的程序。as和ld将他们分开处理,但是相同的段。在次段中成立的东西,
在另外那个段中也成立。当程序运行时,正文段是不可更改的。
The text section is often shared among processes: it contains instructions, constants and the like.
The data section of a running program is usually alterable:
for example, C variables would be stored in the data section.
正文段经常由多个进程共同使用:包含指令,常数和类似的东西。运行中的数据段通常是可
变的:例如,C语言的变量保存在数据段中。
bss section
bss段
This section contains zeroed bytes when your program begins running. It is used to hold
uninitialized variables or common storage. The length of each partial program’s bss section is
important, but because it starts out containing zeroed bytes there is no need to store explicit zero
bytes in the object file. The bss section was invented to eliminate those explicit zeros from object
files.
在您的程序开始时,bbs段包含的字节全部是0。一般这种段是用来保存未初始化的变量或
通用存储数据。各个局部过程包含的bbs段,它的长度是个重要的信息,因为在它开始时包
含的的数据全部是0,所以没有必要在目标文件中保存把这些0字节全部保存起来。目标文
件的bbs段中剔除了这些0字节。
absolute section
地址独立段
Address 0 of this section is always “relocated” to runtime address 0. This is useful if you want to
refer to an address that ld must not change when relocating. In this sense we speak of absolute
addresses being unrelocatable: they do not change during relocation.
这种段的地址0总是“重定向”到运行地址0。如果您想使用一个在重定向时不变的地址,
可以使用这种段。基于这种观念我们说绝对地址是“不可重定向的”:它们在重定向时不变。
undefined section
This section is a catch-all for address references to objects not in the preceding sections.
这个段在目标文件中提供一个万能的地址访问空间,不能放入前面说到的几种段的数据统统
可纳入此段。
An idealized example of three relocatable sections follows. The example uses the traditional
section names .text and .data. Memory addresses are on the horizontal axis.
下面是三个段重定向后的理想的情况。例子中使用传统的段名 “.text”和“.data”。内存地
址横向表示。
Partial program #1:
局部过程 #1:
text data bss
ttttt dddd 00
局部过程 #2:
text data bss
TTT DDDD 000
linked program:
连接后的程序:
text data bss
TTT ttttt dddd DDDD 00000 . . .
addresses:
0. . .
4.3 Assembler Internal Sections
4.3汇编器内部用段
These sections are meant only for the internal use of as. They have no meaning at run-time. You
do not really need to know about these sections for most purposes; but they can be mentioned in as
warning messages,:so it might be helpful to have an idea of their meanings to as. These sections
are used to permit the value of every expression in your assembly language program to be a
section-relative address. ASSEMBLER-INTERNAL-LOGIC-ERROR!
这些段只在as的内部使用时有意义,在运行时它们不再有意义。其实在大多数情况下您不
需要清楚这些段的具体事项:
但在as发出的警告信息中可能会提及这些段。所以了解它们在as中的作用可能会有益处。
这些段的使用提供这样的可能性:程序中的每个表达式的值都是段-相对地址。
ASSEMBLER-INTERNAL-LOGIC-ERROR!
An internal assembler logic error has been found. This means there is a bug in the assembler.
发现一个汇编器逻辑错误。这说明汇编器本身有漏洞。
expr 段
The assembler stores complex expression internally as combinations of symbols.
When it needs to represent an expression as a symbol, it puts it in the expr
当汇编器合并符号时在内部保存复杂的表达式。
当需要将表达式表示为一个符号时,汇编器把它放入expr段。
4.4 Sub-Sections
Assembled bytes conventionally fall into two sections: text and data. You may have separate
groups of data in named sections that you want to end up near to each other in the object file, even
though they are not contiguous in the assembler source. as allows you to use subsections for this
purpose. Within each section, there can be numbered subsections with values from 0 to 8192.
汇编好的字节按照惯例存入两个段:正文段和数据段。你可以有多个由自己命名的段,即使
这些段在源码中并不相连,但在目标文件中它们将首尾相接。As允许你使用子段
(subsections)来达成这个目的。在每个段中可以使用有限的子段,编号从0个到8192。
Objects assembled into the same subsection go into the object file together with other objects in
the same subsection. For example, a compiler might want to store constants in the text section, but
might not want to have them interspersed with the program being assembled. In this case, the
compiler could issue a ‘.text 0’before each section of code being output, and a ‘text 1’before each
group of constants being output.
每个子段中代码汇编后在目标文件中放在一起。例如,编译器可能希望在正文段保存常数,
但不希望汇编后它们散布在各处。在这种情况下,编译器可以先声明一个‘.text 0’段,再
编译各个段的代码,然后声明一个‘.text 1’段,再编译各种常数。
Subsections are optional. If you do not use subsections, everything goes in subsection number zero.
子段是可选使用的,如果您不使用子段,所有的东西将放入编号为0的子段中。
Each subsection is zero-padded up to a multiple of four bytes. (Subsections may be padded a
different amount on different flavors of as.)
每个子段都是四字节对齐的,使用0作为填充字节。(不同的as对子段的填充处理也有所不
同)
Subsections appear in your object file in numeric order, lowest numbered to highest. (All this to be
compatible with other people’s assemblers.) The object file contains no representation of
subsections; ld and other programs that manipulate object files see no trace of them. They just see
all your text subsections as a text section, and all your data subsections as a data section.
子段在目标文件中的次序由编号决定,自低向高排列。( 所有这些都是为了兼容其他的汇编
器。)各个的子段不再具体地体现在目标文件中;ld和处理目标文件其他的程序无法再发现
各个独立的子段。它们只能看见一个由所有程序子段总合成的正文段,一个所有数据子段总
和成的数据段。
To specify which subsection you want subsequent statements assembled into, use a numeric
argument to specify it, in a “text expression”or a ‘data expression’statement. When generating
COFF output, you can also use an extra subsection argument with arbitrary named sections:
‘section name, expression’ Expression should be an absolute expression. (See Chapter 6
[Expressions], page 33.) If you just say ‘text’then ‘text 0’ is assumed. Likewise ‘data’ means ‘data
0’ Assembly begins in text 0. For instance:
为了指定接下来的语句在哪个子段中进行汇编,在‘text expression’或‘data expression’ 伪
操作命令中使用一个数字参数来指定。当生成COFF目标格式时,您还可以使用一个额外的
子段参数随意命名这个段:‘section name, expression’其中参数expression必须是个可确定
的表达式。(见第6章[Expressions], 33页 。)如果您只是标明‘text’,汇编器则汇编为‘text
0’。同样,‘data’意味着‘data 0’。汇编从text 0中开始。举一个具体的例子:
.text 0 # The default subsection is text 0 anyway.
.ascii "This lives in the first text subsection. *"
.text 1
.ascii "But this lives in the second text subsection."
.data 0
.ascii "This lives in the data section,"
.ascii "in the first data subsection."
.text 0
.ascii "This lives in the first text section,"
.ascii "immediately following the asterisk (*)."
Each section has a location counter incremented by one for every byte assembled into that section.
Because subsections are merely a convenience restricted to as there is no concept of a subsection
location counter. There is no way to directly manipulate a location counter-but the .align directive
changes it, and any label definition captures its current value. The location counter of the section
where statements are being assembled is said to be the active location counter.
每个段都有一个位置计数器,在本段中每汇编好一个字节,位置计数器加1。因为子段只是
编程时的便利工具,受限制于as,并不存在子段计数器的概念。没有办法直接操作位置计
数器-只能通过.align命令改变它。
4.5 bss Section
The bss section is used for local common variable storage. You may allocate address space in the
bss section, but you may not dictate data to load into it before your program executes. When your
program starts running, all the contents of the bss section are zeroed bytes.
4.5 bss 段
bss段用来保存通用变量(common variable)的。您可以在bss段中分配地址空间,但在程
序执行前不可能将数据装入bss段。当程序开始运行时,bss段中的内容都是0字节。
The .lcomm pseudo-op defines a symbol in the bss section; see Section 7.42 [.lcomm], page 45.
.lcomm伪操作一般用来在bss段定义一个符号。见7.42[.lcomm], 45页。
The .comm pseudo-op may be used to declare a common symbol, which is another form of
uninitialized symbol; see Section 7.8 [.comm], page 39.
.comm伪操作一般用来声明一个通用符号,这是未初始化符号的另一种形式。见
7.8[.comm],39页。
When assembling for a target which supports multiple sections, such as ELF or COFF, you may
switch into the .bss section and define symbols as usual; see Section 7.66 [.section], page 52. You
may only assemble zero values into the section. Typically the
section will only contain symbol definitions and .skip directives (see Section 7.74 [.skip],page 54).
当汇编的目标格式支持多种段时,如ELF或COFF,您一样可以进入 .bss段定义符号。见
7.66[.section],52页。汇编时您只能在这个段中存入0值。典型的用法是这个段只包含符号定
义和.skip命令。见7。44[skip],54页。
5 符号(symbol)
符号是一个重要的概念:程序员使用符号为语句命名,链接器(linker)通过符号链接程序,
调试器(debugger)通过符号进行调试。
警告:as未必按照符号声明顺序在目标文件中存放符号,这可能会中断某些调式器的调试
过程。
5.1 标签(labels)
标签就是一个后面带着冒号":"的符号(symbol)。这个符号代表动态定位指针的当前值,并
且可以作为相应指令的操作数。如果在您使用一个符号代表两个不同位置,as会发出警告:
最先定义将会覆盖其他的同名定义。
在HPPA上,标签的一般形式不必后带冒号":",而是必须从第0列开始定义。只有标签才
可以使用一个单独的行来定义。针对这个特性,as的HPPA版本还提供一个特别的命令.lable,
使标签的定义更加灵活。
5.2 符号的赋值,
一个符号可以赋任意值,写成符号后跟一个等号"=",再跟一个表达式(见第六章[表达式],
p33)。这与用.set命令是等价的(见章节 7.68[.set],p53)。
5.3 符号名
符号名以一个字母或一个"._"打头。在大多数平台上,还可以用"$",注意在第八章[平台相
关],61页中的那些例外。首字符后可以跟随任意字符串,字符串可以由数字、字母、美元
符号"$"(有些不能使用的情况,见第八章[平台相关],61页)、以及下划线组成。AMD29K
系列的符号名中还可以使用字符"?",但不能用在首字符。
符号对字母的大小写是敏感的:foo和Foo是不同的符号名。
每一个符号都有一个唯一的名字,每个在汇编语言的源程序中的名字对应着一个唯一的符
号。这个符号名在程序中使用次数不限。
局部符号名
局部符号被编译器或程序员用作临时的名字。总共有10个局部符号名,在程序中可以被重
复使用。可以使用"0"、"1"、...、"9"作为局部符号名,在定义局部符号时,写成标签的形式
"N:"(其中N表示0~9任意一个数字)。如果要访问前面的最后一个标签,可以写成"Nb",”
N”为你定义标签时使用的那个数字;如果要访问后面定义的标签,则要写成"Nf",其中N
为前面提到的10个数字之一。语句中的"b"表示“回溯(backwards)”;"f"表示“后继
(forwards)”。
当前的GNU C编译器不生成局部符号。
使用局部标签是没有任何限制,但是必须记住的是,在汇编程序中的某一点,您最多能访问
该点前面的10个局部标签和后面的10个标签。
局部符号名只是一个助记符,在汇编器使用之前,他们会被转换成常规符号名。这些常规符
号名被保存在符号表中,当汇编器发出错误(error)信息时会显示出来,在目标文件中使用,
常规符号名包括下述部分:
L 所有的局部标签都以"L"开头,通常as和ld都不会保留以“L”开头的符号,这些局部标
签一般是些您没有必要见到的符号。如果你在汇编时使用了"-L"选项,as就会把这些符号保
留在目标文件中,链接时也可以让ld保留这些符号,以便于调试时使用这些符号。
数字 如果标签为”0:”,则这个数字为”0”;如果标签为”1:”,则这个数字为”1”;依此
类推一直到”9”。
C-A 使用这个不常用的字符,目的是防止您无意中再定义一个同名符号,” C-A”的ASCII
码为”001”。
序数 这是一组数字,用于区分不同的标签。你定义的首个”0:”标签,它的序数为”1”;
第15个”0:” ,它的序数为”15”;等等。同样,序数也适用于”1:”~”9:”命名的标签。
例如根据以上的规则,第一个”1:”标签:被转换成常规符号时,就成了”L1C-A1”;第44
个”3:”被转换成”L3C-A44”。
5.4 特殊的“点”符号
符号‘.’ 取当前汇编字节的地址值。如表达式‘melvin: .long .’ 定义melvin包含自己的
地址。为‘.’指定地址等价于使用命令‘.org’。同样,表达式”.=.+4”等价于.space 4”。
5.5 符号属性
就像每个符号都有它们的名字一样,每个符号都有它们的属性:”值域(Value)”和”类型
域(Type)”。根据输出格式的不同,符号还会有一些辅助属性域。
如果你使用了一个没有定义的符号,as可能不发出警告,而假定这个符号的所有属性域都
为0。正如您所期望的,这个符号就成为一个外部符号,
5.5.1值域(Value)
符号的值域(通常情况下)是32位的。对于一个符号来说,如果用来在一个代码段、数据段、
bss段或地址独立的段中标识位置,这个值域就是段首到该标签的地址。对于一个代码段、
数据段和bss段来说,一个符号的值域会在连接时随段基址的改变而不同。独立的符号(地
址独立的段中的符号)的值在链接时是不会改变的:这就是为什么称之为“独立(absolute)”
了。
处理未定义的符号的值域的方式比较特别。如果值域为0,则说明此符号在当前汇编的源程
序中未作定义,ld会根据连接到本程序的其它文件试图明确它的值。对于这类符号,你只需
要简单地写出该符号名就行了,无需定义之。如果值域为非零值,则说明此符号使用”.comm”
命令做了通用声明。值域等于为此符号保留的常规存储空间的数量,以字节为单位(地址)。
符号提供该存储空间的首地址。
5.5.2 类型域(Type)。
符号的类型属性域包含该符号的(段)重定位信息,所有的设置标志,这些标志表明该符号
为外部符号;或者提供其他用于链接器与调试器的信息(可选)。确切的格式要视目标输出
文件的格式而定。
5.5.3 格式的符号属性
5.5.3.1 描述符
描述符为一个16位的任意值。你可以通过.desc命令(见 7.11[.desc],p39)创建一个符号
的描述符值。描述符的值对as没有意义。
5.5.3.2 其它
一个8位的任意值,对as没有意义。
5.5.4 COFF的符号属性
COFF格式支持大多数辅助符号属性,和主要(primary)符号属性一样,它们的设置都要在.def
和.endef命令之间进行。
5.5.4.1 主要(primary)属性
符号名通过.def设置,值域和类型域分别通过.val和.type设置。
5.5.4.1 辅助(auxiliary)属性
as的命令.dim、.line、.scl、.size和.tag可以为COFF格式生成辅助符号表信息。
5.5.5 SOM的符号属性。
HPPA的SOM格式可以通过命令.EXPORT和.IMPORT设置大多数符号属性。
在《HP9000 Series 800 Assembly Language Reference Manual》(HP 92432-90001)的IMPORT
和EXPORT汇编命令文档中的对属性作了描述。
6 表达式(Expressions)
表达式规定了一个地址值或数字值。在表达式的前后都可以有空白。
表达式的结果必须是一个纯粹的数字,或是一个指定段内的偏移量。
如果表达式的结果不是纯粹的数字,并且as对表达式中所在的段没有足够的信息,则必需
对整个源程序进行第2遍汇编,以取得表达式的值—但是as目前不支持进行第2遍汇编,
而是终止汇编,并发出一个错误信息。
6.1 空表达式(Empty Expressions)
空表达式没有值:就是空白或null。无论在哪里需要纯粹数字的表达式,您都可以省略它,
as假定它的值为0,这兼容与其他的汇编器。
6.2 整数表达式(Integer Expressions)
一个整数表达式是由操作符限定的一个参数或者多个参数组成的。
6.2.1 参数(Argument)
参数可以是符号、数字或子表达式(subexpression)。在其它文章中,参数有时被称为“算术
操作数(arithmetic operands)”。在本手册中,为了避免与机器语言中的“指令操作数(instruction
operands)”相混淆,我们只使用术语“参数”来指出表达式的某些部分,将“操作数”保留
给机器语言中的指令操作数使用。
符号参数被换算为{section NNN}的形式,其中section代表一个段,它可以是正文段,数据
段,bss、地址独立段或未定义的段。NNN是个带符号的32位的2进制补码。
数字参数可以是任何一个的整数。
你可以使用一个浮点数(flonum)或巨数(bignum),在这种情况下,as会发出警告:只有其中最
低的32位有效,并认为这是一个32位的整数。你可以在整数操作指令处理外来的常量,这
兼容与其他的汇编器。
子表达式是由用左括号”(“,整数表达式,右 ”)”组成的,或者是一个带有前缀操作符
的参数。
6.2.2 操作符(Operators)
操作符提供了算术功能,如”+”和”%”。前缀(prefix)操作符后面需跟随一个参数,而中缀
(infix)操作符必须处在两个参数之间。操作符的前后都可以有空白。
6.2.3 前缀操作符(Prefix Operators)
as提供如下两个前缀操作符,每个操作符都必须跟随一个参数,这个参数必须是纯粹的数
字。
- 取补码。
~ 取反,按位取反。
6.2.2 中缀操作符(Infix Operators)
中缀操作符必须在两个参数之间。操作符有优先级,同等优先级的操作符按照从左向右的顺
序执行,除了”+”和”-“操作符,其它操作符的参数必须是纯粹的数字。计算结果也是纯
粹的数字。
1.最高优先级
* 乘法操作。
/ 除法操作。
% 取余操作。
<
<< 左移操作。与C语言的操作符’<<’相同
>
>> 右移操作。与C语言的操作符’>>’相同
2.中等优先级
| 按位或。
& 按位与。
^ 按位异或。
! 按位或非。
3.低优先级
+ 加法。如果两个参数中有一个是纯粹的数字,则结果归属于另一个参数所在的段。两个
不同段中的参数不能相加。
- 减法。如果右边的参数为纯粹的数字,则结果归属于左边参数所在的段。如果两个参数都
属于同一个段,则结果为纯粹的数字。不同段中的两个参数不能相减。
== 等于。
<> 不等于。
< 小于。
> 大于。
>= 大于或等于。
<= 小于或等于。
比较操作符用作中缀操作符。如果结果为真(true),则值为-1;如果结果为假(false),则值为
0。值得注意的是,这些操作符都执行符号检测。
4.最低优先级
&& 逻辑与。
|| 逻辑或。
这两个逻辑操作符可以连接多个子表达式的结果。与比较操作符不同,如果结果为真(true),
则值为1;如果结果为假(false),则值为0。另外注意逻辑或操作的优先级比逻辑和操作低。
简言之,只有地址的偏移量(offset)之间的加减才有意义;两个参数中只能有一个参数具有相
应的段定义。
7 汇编器命令
所有的汇编器命令名都由句号('.')开头。命令名的其余是字母,通常使用小写。
本章讨论可用命令,不理会gun汇编器针对目标机器配置。某些机器的配置提供附加的命令。
见第8章[机器相关性],第61页。
7.1 .abort
This directive stops the assembly immediately. It is for compatibility with other assemblers. The
original idea was that the assembly language source would be piped into the assembler. If the
sender of the source quit, it could use this directive tells as to quit also. One day .abort will not be
supported.
7.1 .abort
本命令立即终止汇编过程。这是为了兼容其它的汇编器。早期的想法是汇编语言的源码会被
输送进汇编器。如果发送源码的程序要退出,它可以使用本命令通知as退出。将来可能不
再支持使用.abort
7.2 .ABORT
When producing COFF output, as accepts this directive as a synonym for ‘.abort’.
When producing output, as accepts this directive, but ignores it.
7.2 .ABORT
当生成COFF输出时,汇编器把这条命令作为.abort接受。
当产成输出时,汇编器允许使用这条命令,但忽略它。
7.3 .align abs-expr, abs-expr, abs-expr
Pad the location counter (in the current subsection) to a particular storage boundary. The first
expression (which must be absolute) is the alignment required, as described below.
The second expression (also absolute) gives the fill value to be stored in the padding bytes. It (and
the comma) may be omitted. If it is omitted, the padding bytes are normally zero. However, on
some systems, if the section is marked as containing code and the fill value is omitted, the space is
filled with no-op instructions.
The third expression is also absolute, and is also optional. If it is present, it is the maximum
number of bytes that should be skipped by this alignment directive. If doing the alignment would
require skipping more bytes than the specified maximum, then the alignment is not done at all.
You can omit the fill value (the second argument) entirely by simply using two commas after the
required alignment; this can be useful if you want the alignment to be filled with no-op
instructions when appropriate.
The way the required alignment is specified varies from system to system. For the a29k, hppa,
m68k, m88k, w65, sparc, and Hitachi SH, and i386 using ELF format, the first expression is the
alignment request in bytes. For example ‘.align 8’ advances the location counter until it is a
multiple of 8. If the location counter is already a multiple of 8, no change is needed.
For other systems, including the i386 using format, and the arm and strongarm, it is the
number of low-order zero bits the location counter must have after advancement. For example
‘.align 3’ advances the location counter until it a multiple of 8. If the location counter is already a
multiple of 8, no change is needed.
This inconsistency is due to the different behaviors of the various native assemblers for these
systems which GAS must emulate. GAS also provides .balign and .p2align directives, described
later, which have a consistent behavior across all architectures (but are specific to GAS).
7.3 .align abs-expr, abs-expr, abs-expr
增加位置计数器(在当前的子段)使它指向规定的存储边界。第一个表达式参数(结果必须是纯
粹的数字)是必需参数:边界基准,见后面的描述。
第二个表达式参数(结果必须是纯粹的数字)给出填充字节的值,用这个值填充位置计数器越
过的地方。这个参数(和逗点)可以省略,如果省略它,填充字节的值通常是0。但在某些系
统上,如果本段标识为包含代码,而填充值被省略,则使用no-op指令填充这个空间。
第3个参数表达式的结果也必须是纯粹的数字,这个参数是可选的。如果存在第3个参数,
它代表本对齐命令允许越过字节数的最大值。如果完成这个对齐需要跳过的字节比指定的最
大值还多,则根本无法完成对齐。您可以在边界基准后简单地使用两个逗号,以省略填充值
参数(第二参数);如果您想在适当的时候,对齐操作自动使用no-op指令填充,这个方法将
非常奏效。
边界基准的定义因系统而有差异。a29k,hppa,m68k,m88k,w65,sparc,Hitachi SH, 和
使用ELF格式的i386,第一个表达式是边界基准,单位是字节。例如‘.align 8’向后移动位
置计数器至8的倍数。如果地址已经是8的倍数,则无需移动。
有些其它系统,包括使用格式的i386,ARM和strongarm,这代表位置计数器移动后,
计数器中连续为0的低序位数量。例如‘.align 3’向后移动位置计数器直至8的倍数(计数
器的最低的3位为0)。如果地址已经是8倍数,则无需移动。
之所以存在这样的区别,是因为GAS需要模仿各种汇编器的不同动作。GAS还提供.balign
和.p2align命令,在以后详细讲述,这两条命令在所有的机型上使用相同的动作 (但需要向
GAS明确说明机型)。
7.4 .ascii "string". . .
.ascii expects zero or more string literals (see Section 3.6.1.1 [Strings], page 19) separated by
commas. It assembles each string (with no automatic trailing zero byte) into consecutive addresses.
7.4 .ascii "string"...
.ascii可不带参数或者带多个由逗点分开的字符串(见3.6.1.1节[Strings],第19页)。它把汇编
好的每个字符串(在字符串末不自动追加零字节)存入连续的地址。
7.5 .asciz "string". . .
.asciz is just like .ascii, but each string is followed by a zero byte. The “z” in ‘.asciz’ stands for
“zero”.
7.5 .asciz "string"...
.asciz类似与.ascii,但在每个字符串末自动追加一个零字节。‘.asciz’中的‘z’代表“zero”。
7.6 .balign[wl] abs-expr, abs-expr, abs-expr
Pad the location counter (in the current subsection) to a particular storage boundary. The first
expression (which must be absolute) is the alignment request in bytes. For example ‘.balign 8’
advances the location counter until it is a multiple of 8. If the location counter is already a multiple
of 8, no change is needed.
The second expression (also absolute) gives the fill value to be stored in the padding bytes. It (and
the comma) may be omitted. If it is omitted, the padding bytes are normally zero. However, on
some systems, if the section is marked as containing code and the fill value is omitted, the space is
filled with no-op instructions.
The third expression is also absolute, and is also optional. If it is present, it is the maximum
number of bytes that should be skipped by this alignment directive. If doing the alignment would
require skipping more bytes than the specified maximum, then the alignment is not done at all.
You can omit the fill value (the second argument) entirely by simply using two commas after the
required alignment; this can be useful if you want the alignment to be filled with no-op
instructions when appropriate.
The .balignw and .balignl directives are variants of the .balign directive. The .balignw directive
treats the fill pattern as a two byte word value. The .balignl directives treats the fill pattern as a
four byte longword value. For example, .balignw 4,0x368d will align to a multiple of 4. If it skips
two bytes, they will be filled in with the value 0x368d (the exact placement of the bytes depends
upon the endianness of the processor). If it skips 1 or 3 bytes, the fill value is undefined.
7.6
.balign[wl] abs-expr, abs-expr, abs-expr
增加位置计数器(在当前子段)使它指向规定的存储边界。第一个表达式参数(结果必须是纯粹
的数字)是必需参数:边界基准,单位为字节。例如,‘.balign 8’向后移动位置计数器直至计
数器的值等于8的倍数。如果位置计数器已经是8的倍数,则无需移动。
第2个表达式参数(结果必须是纯粹的数字)给出填充字节的值,用这个值填充位置计数器越
过的地方。第2个参数(和逗点)可以省略。如果省略它,填充字节的值通常是0。但在某些
系统上,如果本段标识为包含代码,而填充值被省略,则使用no-op指令填充空白区。
第3个参数的结果也必须是纯粹的数字,这个参数是可选的。如果存在第3个参数,它代表
本对齐命令允许跳过字节数的最大值。如果完成这个对齐需要跳过的字节数比规定的最大值
还多,则根本无法完成对齐。您可以在边界基准参数后简单地使用两个逗号,以省略填充值
参数(第二参数);如果您在想在适当的时候,对齐操作自动使用no-op指令填充,本方法将
非常奏效。
.balignw和.balignl是.balign命令的变化形式。.balignw使用2个字节来填充空白区。.balignl
使用4字节来填充。例如,.balignw 4,0x368d将地址对齐到4的倍数,如果它跳过2个字节,
GAS将使用0x368d填充这2个字节(字节的确切存放位置视处理器的存储方式而定)。如果
它跳过1或3个字节,则填充值不明确。
7.7 .byte expressions
.byte expects zero or more expressions, separated by commas. Each expression is assembled into
the next byte.
expressions
.byte可不带参数或者带多个表达式参数,表达式之间由逗点分隔。每个表达式参数都被汇
编成下一个字节。
7.8 .comm symbol , length
.comm declares a common symbol named symbol. When linking, a common symbol in one object
file may be merged with a defined or common symbol of the same name in another object file. If
ld does not see a definition for the symbol–just one or more common symbols–then it will allocate
length bytes of uninitialized memory. length must be an absolute expression. If ld sees multiple
common symbols with the same name, and they do not all have the same size, it will allocate
space using the largest size.
When using ELF, the .comm directive takes an optional third argument. This is the desired
alignment of the symbol, specified as a byte boundary (for example, an alignment of 16 means
that the least significant 4 bits of the address should be zero). The alignment must be an absolute
expression, and it must be a power of two. If ld allocates uninitialized memory for the common
symbol, it will use the alignment when placing the symbol. If no alignment is specified, as will set
the alignment to the largest power of two less than or equal to the size of the symbol, up to a
maximum of 16.
The syntax for .comm differs slightly on the HPPA. The syntax is ‘symbol .comm, length’;symbol
is optional.
7.8 .comm symbol , length
.comm声明一个符号名为symbol的通用符号(common symbol)。当连接时,目标文件中的通
用符号可能被并入其它目标文件中已定义的符号,或者被并入其他目标文件中同名通用符
号。如果ld无法找到该符号的定义——只有一个或多个通用符号——则分配length个字节
的未初始化内存。Length必须是一个纯粹的表达式。如果ld发现多个同名的通用符号,并
且它们的长度不同,ld将按照它们之中最大的length值为符号分配内存。
当使用ELF格式时,.comm可以使用第3个参数。它代表符号需要对齐的边界基准(例如,
边界基准为16时意味着符号存放地址的最低4位应该是零)。第3个参数表达式结果必须是
纯粹的数字,而且一定是2的幂。当ld为通用符号分配未初始化内存时,在存放符号时要
使用到这个参数。如果没有规定边界基准,as将把边界基准设置成以2为底的该符号长度
的对数,并向下取整。最大值为16。
.comm的语法在HPPA上稍微有些不同。语法是‘symbol .comm, length’;其中参数symbol
是可选的。
7.9 .data subsection
.data tells as to assemble the following statements onto the end of the data subsection numbered
subsection (which is an absolute expression). If subsection is omitted, it defaults to zero.
7.9 .data subsection
.data通知as汇编后续语句,将它们追加在编号为subsection(subsection必须是纯粹的表达式)
数据段末。如果参数subsection省略,则默认是0。
7.10 .def name
Begin defining debugging information for a symbol name; the definition extends until the .endef
directive is encountered. This directive is only observed when as is configured for COFF format
output; when producing , ‘.def’ is recognized, but ignored.
7.10 .def name
开始定义符号'name'的调试信息;定义区延伸至遇到.endef命令。本命令只在as被配置成
COFF格式输出时才使用;当输出为格式时,可以使用‘.def’命令,但被忽略。
7.11 .desc symbol, abs-expression
This directive sets the descriptor of the symbol (see Section 5.5 [Symbol Attributes],page 30) to
the low 16 bits of an absolute expression.
The ‘.desc’ directive is not available when as is configured for COFF output; it is only for or
object format. For the sake of compatibility, as accepts it, but produces no output, when
configured for COFF.
7.11 .desc symbol, abs-expression
本命令用一个纯粹表达式的低16位的值设置符号symbol的描述符(见5.5[符号属性],第30
页)。当as被配置成COFF输出时,‘.desc’命令无效;它只适用于或目标格式。
为兼容起见,当配置为COFF时,as接受此命令,但不产生输出。
7.12 .dim
This directive is generated by compilers to include auxiliary debugging information in the symbol
table. It is only permitted inside .def/.endef pairs.
‘.dim’ is only meaningful when generating COFF format output; when as is generating , it
accepts this directive but ignores it.
7.12 .dim
这条命令由编译器生成的,以便在符号表中加入辅助调试信息。只可以在.def/.endef对之间
使用此命令。
'.dim'仅仅在生成COFF格式输出时是有意义的;当生成时,as接受这条命令,但忽略它。
7.13 .double flonums
.double expects zero or more flonums, separated by commas. It assembles floating point numbers.
The exact kind of floating point numbers emitted depends on how as is configured. See Chapter 8
[Machine Dependencies], page 61.
7.13 .double flonums
.double后跟着零个或由逗点分开多个的浮点数。本指令汇编出浮点数字。生成的浮点数的
确切类型视as的配置而定。见第8章[机器相关性],第61页。
7.14 .eject
Force a page break at this point, when generating assembly listings.
7.14 .eject
当生成汇编清单时,强制清单页在此点中断。
7.15 .else
.else is part of the as support for conditional assembly; see Section 7.35 [.if], page 43. It marks the
beginning of a section of code to be assembled if the condition for the preceding
.if was false.
7.15 .else
.else 是支持as进行的条件汇编指令之一;见7.35[.if],第43页。如果前面.if命令的条件不成
立,则表示需要汇编.else后的一段代码。
7.16 .elseif
.elseif is part of the as support for conditional assembly; see Section 7.35 [.if],page 43. It is
shorthand for beginning a new .if block that would otherwise fill the entire .else section.
7.16 .elseif
.elseif 是支持as进行的条件汇编指令之一。见7.35节 [.if],第43页。它可以在.esle段中快
速产生一个新的.if块。
7.17 .end
.end marks the end of the assembly file. as does not process anything in the file past the .end
directive.
7.17 .end
.end标记着汇编文件的结束。as不处理.end命令后的任何语句。
7.18 .endef
This directive flags the end of a symbol definition begun with .def.
‘.endef’ is only meaningful when generating COFF format output; if as is configured to generate
, it accepts this directive but ignores it.
7.18 .endef
这条命令标志着从.def开始的符号定义结束。
‘.endef’命令仅仅在生成COFF格式的输出有意义;如果as被配置为生成输出,虽然
as接受这条命令,但忽略它。
7.19 .endfunc
.endfunc marks the end of a function specified with .func.
7.19 .endfunc
.endfunc标志着一个由.func命令定义的函数的结束。
7.20 .endif
.endif is part of the as support for conditional assembly; it marks the end of a block of code that is
only assembled conditionally. See Section 7.35 [.if], page 43.
7.20 .endif
.endif是支持as进行的条件汇编的指令之一.它标志着条件汇编代码块的结束。见7.35节[.if],
第43页。
7.21 .equ symbol, expression
This directive sets the value of symbol to expression. It is synonymous with ‘.set’; see Section
7.68 [.set], page 53.
The syntax for equ on the HPPA is ‘symbol .equ expression’.
7.21 .equ symbol, expression
本命令把符号symbol值设置为expression。它等同与'.set'命令。见7.68[.set],第53页。
在HPPA上的equ语法是‘symbol .equ expression’。
7.22 .equiv symbol, expression
The .equiv directive is like .equ and .set, except that the assembler will signal an error if symbol is
already defined.
Except for the contents of the error message, this is roughly equivalent to
.ifdef SYM
.err
.endif
.equ SYM,VAL
7.22 .equiv symbol, expression
.equiv 类似与.equ & .set命令, 不同之处在于,如果符号已经定义过,as会发出错误信号。
除了错误信息的内容之外,它大体上等价与:
.ifdef SYM
.err
.endif
.equ SYM,VAL
7.23 .err
If as assembles a .err directive, it will print an error message and, unless the -Z option was used, it
will not generate an object file. This can be used to signal error an conditionally compiled code.
7.23 .err
如果as汇编一条.err命令, 将打印一条错误信息,除非使用了-Z 选项, as不会生成目标文件。
可以在条件编译代码中使用它来发出错误信息。
7.24 .exitm
Exit early from the current macro definition. See Section 7.50 [Macro], page 47.
7.24 .exitm
从当前宏定义体中提前退出。见7.50 [Macro],第47页。
7.25 .extern
.extern is accepted in the source program—for compatibility with other assemblers—but it is
ignored. as treats all undefined symbols as external.
7.25 .extern
.extern可以在源程序中使用--以便兼容其他的汇编器—但会被忽略。as将所有未定义的符号
都当作外部符号处理。
7.26 .fail expression
Generates an error or a warning. If the value of the expression is 500 or more, as will print a
warning message. If the value is less than 500, as will print an error message. The message will
include the value of expression. This can occasionally be useful inside complex nested macros or
conditional assembly.
7.26 .fail expression
生成一个错误(error)或警告(warning)。如果expression的值大于或等于500,as会打印一条
“警告”消息。如果expression的值小于500,as会打印一条“错误”消息。消息中包含了
expression的值。这在复杂的宏嵌套或条件汇编时偶尔用到。
7.27 .file string
.file tells as that we are about to start a new logical file. string is the new file name.
In general, the filename is recognized whether or not it is surrounded by quotes ‘"’; but if you
wish to specify an empty file name, you must give the quotes–"". This statement may go away in
future: it is only recognized to be compatible with old as programs. In some configurations of
as, .file has already been removed to avoid conflicts with other assemblers. See Chapter 8
[Machine Dependencies], page 61.
7.27 .file string
.file 通告as我们准备开启一个新的逻辑文件。 string 是新文件名。总的来说,文件名是否
使用引号‘"’都可以;但如果您希望规定一个空文件名时,必须使用引号-""。本语句将来
可能不再使用—允许使用它只是为了与旧版本的as程序兼容。在as的一些配置中,已经删
除了.file以避免与其它的汇编器冲突。见第8章 [Machine Dependencies], 第61页。
7.28 .fill repeat , size , value
repeat, size and value are absolute expressions. This emits repeat copies of size bytes. Repeat may
be zero or more. Size may be zero or more, but if it is more than 8, then it is deemed to have the
value 8, compatible with other people’s assemblers. The contents of each repeat bytes are taken
from an 8-byte number. The highest order 4 bytes are zero. The lowest order 4 bytes are value
rendered in the byte-order of an integer on the computer as is assembling for. Each size bytes in a
repetition is taken from the lowest order size bytes of this number. Again, this bizarre behavior is
compatible with other people’s assemblers.
size and value are optional. If the second comma and value are absent, value is assumed zero. If
the first comma and following tokens are absent, size is assumed to be 1.
7.28 .fill repeat , size , value
repeat, size 和value都必须是纯粹的表达式。本命令生成size个字节的repeat个副本。Repeat
可以是0或更大的值。Size 可以是0或更大的值, 但即使size大于8,也被视作8,以兼容其
它的汇编器。各个副本中的内容取自一个8字节长的数。最高4个字节为零,最低的4个字
节是value,它以as正在汇编的目标计算机的整数字节顺序排列。每个副本中的size个字节
都取值于这个数最低的size个字节。再次说明,这个古怪的动作只是为了兼容其他的汇编
器。
size参数和value参数是可选的。如果不存在第2个逗号和value参数,则假定value为零。
如果不存在第1个逗号和其后的参数,则假定size为1。
7.29 .float flonums
This directive assembles zero or more flonums, separated by commas. It has the same effect
as .single. The exact kind of floating point numbers emitted depends on how as is configured. See
Chapter 8 [Machine Dependencies], page 61.
7.29 .float flonums
本命令汇编0个或多个浮点数,浮点数之间由逗号分隔。它和.single的汇编效果相同。生成
的浮点数的确切类型视as的配置而定。见第8章 [Machine Dependencies], 61页。
7.30 .func name[,label]
.func emits debugging information to denote function name, and is ignored unless the file is
assembled with debugging enabled. Only ‘--gstabs’ is currently supported. Label is the entry point
of the function and if omitted name prepended with the ‘leading char’ is used. ‘leading char’ is
usually _ or nothing, depending on the target. All functions are currently defined to have void
return type. The function must be terminated with .endfunc.
7.30 .func name[,label]
.func发出一个调试信息用以指示函数name,这个信息将被忽略,除非文件使用debugging
enabled方式的汇编。目前只支持‘--gstabs’。label是函数的入口点,如果name被省略则使
用预定的‘引导符’。‘引导符’通常可以是 _ 或者什么也没有,视目标机型而定。所有函
数现时被定义为void返回类型,函数体必须使用.endfunc来结束
7.31 .global symbol, .globl symbol
.global makes the symbol visible to ld. If you define symbol in your partial program, its value is
made available to other partial programs that are linked with it. Otherwise, symbol takes its
attributes from a symbol of the same name from another file linked into the same program.
Both spellings (‘.globl’ and ‘.global’) are accepted, for compatibility with other assemblers.
On the HPPA, .global is not always enough to make it accessible to other partial programs. You
may need the HPPA-only .EXPORT directive as well. See Section 8.8.5 [HPPA Assembler
Directives], page 84.
7.31 .global symbol, .globl symbol
.global 使符号symbol对连接器ld可见。如果您在局部过程中定义符号symbol,其它和此
的局部过程都可以访问它的值。另外,symbol从连接到本过程的另一个文件中的同名符号
获取自己的属性。
两种写法都可以(‘.globl’ 和‘.global’),以便兼容多种汇编器。
在HPPA上, .global未必总能够使符号被其它局部过程访问。可能同时需要使用
HPPA-only .EXPORT命令。见8.8.5[HPPA Assembler Directives],84页。
7.32 .hidden names
This one of the ELF visibility directives. The other two are .internal (see Section 7.39 [.internal],
page 44) and .protected (see Section 7.58 [.protected], page 50).
This directive overrides the named symbols default visibility (which is set by their binding: local,
global or weak). The directive sets the visibility to hidden which means that the symbols are not
visible to other components. Such symbols are always considered to be protected as well.
7.32 .hidden names
这是一条关于ELF可见度的命令。其它两条是.internal(见7.39[.internal],44页) 和 .protected
(见7.58 [.protected], 50页)。本命令取消指定符号的缺省可见度(可见度由其他命令捆绑设定:
local,global,weak)。本命令把可见度设置为hidden,这意味着本符号对其他部分不可见。这最
好是一些需要长期保护的符号。
7.33 .hword expressions
This expects zero or more expressions, and emits a 16 bit number for each.
This directive is a synonym for ‘.short’; depending on the target architecture, it may also be a
synonym for ‘.word’.
7.33 .hword expressions
本命令后可以不带或带多个expressions,并且为每个参数生成一个16位数。
本命令等同与'.short'命令。在某些架构上,也可能等同与'.word'。
7.34 .ident
This directive is used by some assemblers to place tags in object files. as simply accepts the
directive for source-file compatibility with such assemblers, but does not actually emit anything
for it.
7.34 .ident
本命令被某些汇编器用来在目标文件中加入标饰。为了使汇编源码文件兼容上述的汇编器,
as简单地接受本命令,但实际上不产生东西。
7.35 .if absolute expression
.if marks the beginning of a section of code which is only considered part of the source program
being assembled if the argument (which must be an absolute expression) is nonzero. The end of
the conditional section of code must be marked by .endif (see Section 7.20 [.endif], page 40);
optionally, you may include code for the alternative condition, flagged by .else (see Section 7.15
[.else], page 40). If you have several conditions to check, .elseif may be used to avoid nesting
blocks if/else within each subsequent .else block.
The following variants of .if are also supported:
.ifdef symbol
Assembles the following section of code if the specified symbol has been defined.
.ifc string1,string2
Assembles the following section of code if the two strings are the same. The strings may be
optionally quoted with single quotes. If they are not quoted, the first string stops at the first
comma, and the second string stops at the end of the line. Strings which contain whitespace should
be quoted. The string comparison is case sensitive.
.ifeq absolute expression
Assembles the following section of code if the argument is zero.
.ifeqs string1,string2
Another form of .ifc. The strings must be quoted using double quotes.
.ifge absolute expression
Assembles the following section of code if the argument is greater than or equal to zero.
.ifgt absolute expression
Assembles the following section of code if the argument is greater than zero.
.ifle absolute expression
Assembles the following section of code if the argument is less than or equal to zero.
.iflt absolute expression
Assembles the following section of code if the argument is less than zero.
.ifnc string1,string2.
Like .ifc, but the sense of the test is reversed: this assembles the following section of code if the
two strings are not the same.
.ifndef symbol
.ifnotdef symbol
Assembles the following section of code if the specified symbol has not been defined. Both
spelling variants are equivalent.
.ifne absolute expression
Assembles the following section of code if the argument is not equal to zero (in other words, this
is equivalent to .if).
.ifnes string1,string2
Like .ifeqs, but the sense of the test is reversed: this assembles the following section of code if the
two strings are not the same.
7.35 .if absolute expression
.if 标志着一段代码的开始,这段代码只有在参数absolute experession(必须是一个独立的表
达式)不为0时才进行汇编。这段条件汇编代码必须使用.endif标志结束。(见7.20[.endif], 40
页);另外,可以使用.esle来标记一个代码块(见7.15 [.else],40页),这个代码块与前面那段代
码只有一个会进行汇编。 如果您需要检查数个汇编条件,可以在使用.elseif命令,以避免
在.else代码块中进行if/else语句块的嵌套。
同样可以使用下面.if的变体:
.ifdef symbol
如果指定的符号symbol已经定义过,汇编下面那段代码。
.ifc string1,string2
如果两个字符串相同的话,汇编下面那段代码。 字符串可以可选地使用单引号。如果不使
用引号则第1个字符串在逗号处结束。第2个字符串在本行末结束。包含空白的字符串应该
使用引号标注。字符串比较时是区分大小写的。
.ifeq absolute expression
如果参数的值为0,汇编下面那段代码。
.ifeqs string1,string2
这是.ifc的另一种形式,字符串必须使用双引号标注。
.ifge absolute expression
如果参数的值大于等于0,汇编下面那段代码。
.ifgt absolute expression
如果参数的值大于0,汇编下面那段代码。
.ifle absolute expression
如果参数的值小于等于0,汇编下面那段代码。
.iflt absolute expression
如果参数的值小于0,汇编下面那段代码。
.ifnc string1,string2.
类似与.ifc,不过使用反向的测试: 如果两个字符串不相等的话,汇编下面那段代码。
.ifndef symbol
.ifnotdef symbol
如果指定的符号symbol不曾被定义过,汇编下面那段代码。 上面两种写法是等效的。
.ifne absolute expression
如果参数的值为不等于0,汇编下面那段代码。 (换句话说, 这是.if的另一种写法).
.ifnes string1,string2
类似与.ifeqs,不过使用反向的测试: 如果两个字符串不相等的话,汇编下面那段代码。
7.36 .incbin "file"[,skip[,count]]
The incbin directive includes file verbatim at the current location. You can control the search paths
used with the ‘-I’ command-line option (see Chapter 2 [Command-Line Options], page 11).
Quotation marks are required around file.
The skip argument skips a number of bytes from the start of the file. The count argument indicates
the maximum number of bytes to read. Note that the data is not aligned in any way, so it is the
user’s responsibility to make sure that proper alignment is provided both before and after the
incbin directive.
7.36 .incbin "file"[,skip[,count]]
这条incbin命令在当前位置逐字地引入file文件的内容。您可以使用命令行选项参数“-I”
来控制搜索路径。(见第2章[Command-Line Options], 11页)。文件名必须使用引号。
参数skip表示需要从文件头跳过的字节数目。参数count表示读入的最大字节数目。注意,
数据没有进行任何方式的对齐操作,所以用户需要在 .incbin命令的前后进行必要的边界对
齐。
7.37 .include "file"
This directive provides a way to include supporting files at specified points in your source
program. The code from file is assembled as if it followed the point of the .include; when the end
of the included file is reached, assembly of the original file continues. You can control the search
paths used with the ‘-I’ command-line option (see Chapter 2 [Command-Line Options], page 11).
Quotation marks are required around file.
7.37 .include "file"
本命令提供在源程序中指定点引入支撑文件的手段。file中的代码如同紧跟.include后一样被
汇编。当引入文件汇编结束,继续汇编原来的文件。您可以使用命令行选项参数“-I”来控
制搜索路径(见第2章[Command-Line Options], 11页)。文件名必须使用引号来标注。
7.38 .int expressions
Expect zero or more expressions, of any section, separated by commas. For each expression, emit
a number that, at run time, is the value of that expression. The byte order and bit size of the
number depends on what kind of target the assembly is for.
7.38 .int expressions
可以不带参数或带多个expressions,参数之间由逗号分隔。每个expressions都生成一个数字,
这个数字等于表达式在目标机器运行时的值。字节顺序和数字的位数视汇编的目标机器而
定。
7.39 .internal names
This one of the ELF visibility directives. The other two are .hidden (see Section 7.32 [.hidden],
page 42) and .protected (see Section 7.58 [.protected], page 50).
This directive overrides the named symbols default visibility (which is set by their binding: local,
global or weak). The directive sets the visibility to internal which means that the symbols are
considered to be hidden (ie not visible to other components), and that some extra, processor
specific processing must also be performed upon the symbols as well.
7.39 .internal names
这是一条与ELF可见度相关的命令。另外的两条是.hidden(见7.32[.hidden],42页)
和 .protected (见7.58 [.protected],50页)。
本命令取消指定符号的缺省可见度(可见度由其他命令捆绑设定:local,global,weak)。本命令
把指定符号可见度设置为internal,这意味着此符号需要被隐藏(即对其他部分不可见),另
外,符号还必须经过处理器的特别的处理。
7.40 .irp symbol,values . . .
加工一个需要用values替代symbol的语句序列。语句序列从.irp命令开始,在.endr命令前
结束。对于每个value都进行如下加工:用value替代Symbol,并对此语句序列进行汇编。
如果没有给出value,则用空字符串(null sting)替代symbol,并将此语句序列汇编一次。使用
symbol, 把参数symbol提交给语句序列。
例如下列代码
.irp param,1,2,3
move dparam,sp@-
.endr
等同与
move d1,sp@-
move d2,sp@-
move d3,sp@-
7.41 .irpc symbol,values . . .
Evaluate a sequence of statements assigning different values to symbol. The sequence of
statements starts at the .irpc directive, and is terminated by an .endr directive. For each character
in value, symbol is set to the character, and the sequence of statements is assembled. If no value is
listed, the sequence of statements is assembled once, with symbol set to the null string. To refer to
symbol within the sequence of statements, use symbol.
For example, assembling
.irpc param,123
move dparam,sp@-
.endr
is equivalent to assembling
move d1,sp@-
move d2,sp@-
move d3,sp@-
7.41 .irpc symbol,values. . .
加工一个需要用values替代symbol的语句序列。语句序列从.irpc命令开始,在.endr命令前
结束。对于value中的每个字符,都进行如下加工;用此字符替代symbol,并对此语句序列
进行汇编。如果没有给出value参数,则用空字符串(null sting)替代symbol,并将此语句序
列汇编一次。使用symbol, 把参数symbol提交给语句序列。
例如下列代码
.irpc param,123
move dparam,sp@-
.endr
等同与
move d1,sp@-
move d2,sp@-
move d3,sp@-
7.42 .lcomm symbol , length
Reserve length (an absolute expression) bytes for a local common denoted by symbol. The section
and value of symbol are those of the new local common. The addresses are allocated in the bss
section, so that at run-time the bytes start off zeroed. Symbol is not declared global (see Section
7.31 [.global], page 42), so is normally not visible to ld.
Some targets permit a third argument to be used with .lcomm. This argument specifies the desired
alignment of the symbol in the bss section.
The syntax for .lcomm differs slightly on the HPPA. The syntax is ‘symbol .lcomm, length’;
symbol is optional.
7.42 .lcomm symbol , length
为一个本地通用符号symbol预留length个字节的内存。symbol 的段(属性)和值(属性)被设
置为一个新的本地通用符号应有的属性:内存是在bss段中分配的,所以在运行时,这些字节
开始都是零。因为symbol没有被声明为全局性的符号,所以symbol对ld通常不可见。
某些目标格式允许在.lcomm命令中使用第3个参数。这个参数指出这个bss段中的符号对
齐操作所需要的边界基准。
.lcomm的语法在HPPA上稍有不同。表示为‘symbol .lcomm, length’; symbol 是可选的。
7.43 .lflags
as accepts this directive, for compatibility with other assemblers, but ignores it.
7.43 .lflags
as接受本命令,以兼容其他的汇编器,但忽略之。
7.44 .line line-number
Change the logical line number. line-number must be an absolute expression. The next line has
that logical line number. Therefore any other statements on the current line (after a statement
separator character) are reported as on logical line number line-number - 1. One day as will no
longer support this directive: it is recognized only for compatibility with existing assembler
programs.
Warning: In the AMD29K configuration of as, this command is not available; use the synonym .ln
in that context.
Even though this is a directive associated with the or object-code formats, as still
recognizes it when producing COFF output, and treats ‘.line’ as though it were the COFF ‘.ln’ if it
is found outside a .def/.endef pair.
Inside a .def, ‘.line’ is, instead, one of the directives used by compilers to generate auxiliary
symbol information for debugging.
7.44 .line line-number
更改逻辑行号,参数line-number必须是个纯粹的表达式。本命令后的下一行将被赋予此逻
辑行号。因此在当前行之前任何其他的语句(在语句分隔符后)的逻辑行号将被视作
line-number - 1。以后 as将不在支持这条命令:只是为了兼容现存的汇编器而接受本命令。
Warning: 在为AMD29K目标机器配置的as中,不能使用本指令。在这种场合可以使用.ln命
令。
尽管这是与a. out或b. out目标代码格式相关的命令,在生成COFF输出时as仍然接受它,
并且如果‘.line’出现在.def/endef之外的话,就把它视为‘.ln’命令。
如果‘.line’在.def语句块中的话,.line命令则是一条编译器使用的命令,用来为调式生成
辅助符号信息。
7.45 .linkonce [type]
Mark the current section so that the linker only includes a single copy of it. This may be used to
include the same section in several different object files, but ensure that the linker will only
include it once in the final output file. The .linkonce pseudo-op must be used for each instance of
the section. Duplicate sections are detected based on the section name, so it should be unique.
This directive is only supported by a few object file formats; as of this writing, the only object file
format that supports it is the Portable Executable format used on Windows NT.
The type argument is optional. If specified, it must be one of the following strings. For example:
.linkonce same_size
Not all types may be supported on all object file formats.
discard Silently discard duplicate sections. This is the default.
one_only Warn if there are duplicate sections, but still keep only one copy.
same_size Warn if any of the duplicates have different sizes.
same_contents
Warn if any of the duplicates do not have exactly the same contents.
7.45 .linkonce [type]
给当前段做一个标志,以便连接器只包含它的一个拷贝。这个命令可以用于几个不同的目标
文件中包含同样的段,但需要连接器在最终的输出文件中只包含一个这样的段。. linkouce
伪操作必须在每个段的实例都中使用。对重复段的探测基于段名来进行,因此这个段将是唯
一的。
本命令只在少数目标格式文件中有效,到写本文为止,只有基于Windows NT的PE (Portable
Executable)格式的目标文件支持本命令,
参数type是可选的,如果指定了此参数,它必须是下列字符串之一。例如
. Linkonce same_size
不是在所有的格式目标文件都可以使用所有类型的参数。
discard 静静地舍弃重复的段,这也是默认值。
one_only 如果存在重复的段则发出警告,但只保存一个拷贝。
same_size 如果重复的段有不同的大小则发出警告。
same_contents 如果重复段的内容不是精确的相符则发出警告。
7.46 .ln line-number
‘.ln’ is a synonym for ‘.line’.
7.46 .ln line-number
‘.ln’命令等同与‘.line’.
7.47 .mri val
If val is non-zero, this tells as to enter MRI mode. If val is zero, this tells as to exit MRI mode.
This change affects code assembled until the next .mri directive, or until the end of the file. See
Section 2.8 [MRI mode], page 13.
7.47 .mri val
如果参数val是非零值,这将通知as进入MRI模式。如果参数val的值是零,这通知as退
出MRI模式。这个变化会影响汇编的结果,直到下个.mri命令,或者直到文件尾。见2.8 [MRI
mode], 13页。
7.48 .list
Control (in conjunction with the .nolist directive) whether or not assembly listings are generated.
These two directives maintain an internal counter (which is zero initially). .list increments the
counter, and .nolist decrements it. Assembly listings are generated whenever the counter is greater
than zero.
By default, listings are disabled. When you enable them (with the ‘-a’ command line option; see
Chapter 2 [Command-Line Options], page 11), the initial value of the listing counter is one.
7.48 .list
控制(和.nolist命令配合)是否生成汇编清单。这两个命令维护一个内部的计数器(计数器
初始值为0).list命令增加计数器的值,.nolist减少计数器的值。当计数器的值大与0时将
汇编列表。
缺省状态汇编列表的生成是关闭的。当您打开它的时候(使用带-a选项的命令行)第2章
[Command-Line Options], 11页), 内部计数器的初始值为1。
7.49 .long expressions
.long is the same as ‘.int’, see Section 7.38 [.int], page 44.
7.49 .long expressions
.long是.int的等价命令,见7.38 [.int], 44页.
7.50 .macro
The commands .macro and .endm allow you to define macros that generate assembly output. For
example, this definition specifies a macro sum that puts a sequence of numbers into memory:
.macro sum from=0, to=5
.long from
.if to-from
sum "(from+1)",to
.endif
.endm
With that definition, ‘SUM 0,5’ is equivalent to this assembly input:
.long 0
.long 1
.long 2
.long 3
.long 4
.long 5
.macro macname
.macro macname macargs ...
Begin the definition of a macro called macname. If your macro definition requires arguments,
specify their names after the macro name, separated by commas or spaces. You can supply a
default value for any macro argument by following the name with ‘=deflt’. For example, these are
all valid .macro statements:
.macro comm
Begin the definition of a macro called comm, which takes no arguments.
.macro plus1 p, p1
.macro plus1 p p1
Either statement begins the definition of a macro called plus1,which takes two arguments; within
the macro definition, write ‘p’ or ‘p1’ to evaluate the arguments.
.macro reserve_str p1=0 p2
Begin the definition of a macro called reserve_str, with two arguments. The first argument has a
default value, but not the second. After the definition is complete, you can call the macro either as
‘reserve_str a, b’ (with ‘p1’ evaluating to a and ‘p2’ evaluating to b), or as ‘reserve_str ,b’ (with
‘p1’ evaluating as the default, in this case ‘0’, and ‘p2’ evaluating to b).
When you call a macro, you can specify the argument values either by position, or by keyword.
For example, ‘sum 9,17’ is equivalent to ‘sum to=17, from=9’.
.endm Mark the end of a macro definition.
.exitm Exit early from the current macro definition.
@ as maintains a counter of how many macros it has executed in this pseudov-ariable; you can
copy that number to your output with ‘@’, but only within a macro definition.
7.50 .macro
本命令.macro和.endm命令允许您定义宏来生成汇编输出。例如,下面的语句定义了一个宏
sum,这个宏把一个数字序列放入内存。
.macro sum from=0, to=5
.long from
.if to-from
sum "(from+1)",to
.endif
.endm
使用上述定义,'SUM 0,5'语句就等于输入下面的汇编语句:
.long 0
.long 1
.long 2
.long 3
.long 4
.long 5
.macro macname
.macro macname macargs ...
开始定义一个名为macname的宏。如果您的宏需要使用参数,则在宏的名字后指定他们的
名字,参数之间用逗号或空格分隔。您可以为任意的参数提供参数的缺省值,只需要在参数
后使用“=deflt”,。例如,下列都是合法的宏定义语句:
.macro comm
定义一个名为comm宏,不使用参数。
.macro plus1 p, p1
.macro plus1 p p1
两个语句都声明要定义一个名为plus1的宏,这个宏需要两个参数,在宏定义体内,使用'p'
或'p1'来引用参数的值。
.macro reserve_str p1=0 p2
声明要定义一个名为reserve_str的宏,使用两个参数。第一个参数有缺省值,第二个没有缺
省值。宏定义完成后,您可以通过‘reserve_str a, b’(宏体中‘p1’引用a的值,‘p2’引
用b值)或通过‘reserve_str ,b’(‘p1’使用缺省值,在此为‘0’,‘p2’引用b的值)来调
用这个宏。
当调用一个宏时,您既可以通过位置指定参数值,也可以通过关键字指定参数值。例如,‘sum
9,17’和‘sum to=17, from=9’是等价的。
.endm 标志宏定义体的结束。
.exitm 提前从当前宏定义体中退出。
@ 这个伪变量其实是as维护的一个计数器,用来统计执行了多少个宏。您可以通过使用@
把这个数字复制到您的输出中,但仅限于在宏定义体中使用。
7.51 .nolist
Control (in conjunction with the .list directive) whether or not assembly listings are generated.
These two directives maintain an internal counter (which is zero initially). .list increments the
counter, and .nolist decrements it. Assembly listings are generated whenever the counter is greater
than zero.
7.51 .nolist
控制(和.list命令配合)是否生成汇编列表。这两个命令维护一个内部的计数器(计数器初
始值为0).list命令增加计数器的值,.nolist减少计数器的值。当计数器的值大与0时将汇
编列表。
7.52 .octa bignums
This directive expects zero or more bignums, separated by commas. For each bignum, it emits a
16-byte integer.
The term “octa” comes from contexts in which a “word” is two bytes; hence octa-word for 16
bytes.
7.52 .octa bignums
本命令可以不带参数或多个由逗号分隔开的巨数bignum,针对每个巨数bignum,它生成一个
16个字节的整数。
术语"octa"来源:word为2个字节,故此octa-word为16个字节。
7.53 .org new-lc , fill
Advance the location counter of the current section to new-lc. new-lc is either an absolute
expression or an expression with the same section as the current subsection. That is, you can’t
use .org to cross sections: if new-lc has the wrong section, the .org directive is ignored. To be
compatible with former assemblers, if the section of new-lc is absolute, as issues a warning, then
pretends the section of new-lc is the same as the current subsection.
.org may only increase the location counter, or leave it unchanged; you cannot use .org to move
the location counter backwards.
Because as tries to assemble programs in one pass, new-lc may not be undefined. If you really
detest this restriction we eagerly await a chance to share your improved assembler.
Beware that the origin is relative to the start of the section, not to the start of the subsection. This
is compatible with other people’s assemblers.
When the location counter (of the current subsection) is advanced, the intervening bytes are filled
with fill which should be an absolute expression. If the comma and fill are omitted, fill defaults to
zero.
7.53 .org new-lc , fill
向后移动当前段的位置计数器至new-lc。new-lc要么是一个纯粹的表达式,要么这个表达式
与当前子段在同一个段中。换句话说,就是您不能使用.org进行段超越。如果new-lc指向错
误的段,则忽略.org命令。为了兼容以前的汇编器,如果new-lc指向一个地址独立的段,as
发出一个警告,并假定new-lc指向当前子段。
.org 仅仅可以增大位置计数器,或者保持位置计数器不变;您不能使用.org命令把位置计数
器向回移动。
因为as尽量一次完成程序汇编,所以不能使用未定义的new-lc。如果您厌恶这个限制,我
们急切期待有机会分享经过您改进的汇编器。
注意起点相对于段的首地址,而不是子段的首地址。这与其他的汇编器相兼容。
当(当前语句块)位置计数器到达指定位置,用fill填充该字节,fill必须是纯粹的表达式。
如果没有给出逗号和fill,fill值缺省为0。
7.54 .p2align[wl] abs-expr, abs-expr, abs-expr
Pad the location counter (in the current subsection) to a particular storage boundary. The first
expression (which must be absolute) is the number of low-order zero bits the location counter
must have after advancement. For example ‘.p2align 3’ advances the location counter until it a
multiple of 8. If the location counter is already a multiple of 8, no change is needed.
The second expression (also absolute) gives the fill value to be stored in the padding bytes. It (and
the comma) may be omitted. If it is omitted, the padding bytes are normally zero. However, on
some systems, if the section is marked as containing code and the fill value is omitted, the space is
filled with no-op instructions.
The third expression is also absolute, and is also optional. If it is present, it is the maximum
number of bytes that should be skipped by this alignment directive. If doing the alignment would
require skipping more bytes than the specified maximum, then the alignment is not done at all.
You can omit the fill value (the second argument) entirely by simply using two commas after the
required alignment; this can be useful if you want the alignment to be filled with no-op
instructions when appropriate.
The .p2alignw and .p2alignl directives are variants of the .p2align directive. The .p2alignw
directive treats the fill pattern as a two byte word value. The .p2alignl directives treats the fill
pattern as a four byte longword value. For example, .p2alignw 2,0x368d will align to a multiple of
4. If it skips two bytes, they will be filled in with the value 0x368d (the exact placement of the
bytes depends upon the endianness of the processor). If it skips 1 or 3 bytes, the fill value is
undefined.
7.54 .p2align[wl] abs-expr, abs-expr, abs-expr
增加位置计数器(在当前的子段)使它指向规定的存储边界。第一个表达式参数(结果必须是纯
粹的数字) 代表位置计数器移动后,计数器中连续为0的低序位数量。例如‘.align 3’向后
移动位置指针直至8的倍数(指针的最低的3位为0)。如果地址已经是8倍数,则无需移
动。
第二个表达式参数(结果必须是纯粹的数字)给出填充字节的值。用这个值填充位置计数器越
过的地方。这个参数(和逗点)可以省略。如果省略它,填充字节的值通常默认为0。但在某
些系统上,如果本段标识为包含代码,而填充值被省略,则使用no-op指令填充填充区。
第3个参数表达式的结果也必须是纯粹的数字,这个参数是可选的。如果存在第3个参数,
它代表本对齐命令允许越过字节数的最大值。如果完成这个对齐需要跳过的字节比指定的最
大值还多,则根本无法完成对齐。您可以在边界基准后简单地使用两个逗号,以省略填充值
参数(第二参数);如果您想在适当的时候,对齐操作自动使用no-op指令填充,这个方法将
非常奏效。
.p2alignw和.p2alignl是.p2align命令的变化形式。.p2alignw 使用2个字节来填充填充
区。.p2alignl使用4字节来填充。例如,. .p2alignw 2,0x368d将地址对齐到4的倍数,如果它
跳过2个字节,GAS将使用0x368d填充这2个字节(字节的准确的位置视处理器的存储方
式而定)。如果它跳过1或3个字节,填充值则不明确。
7.55 .previous
This is one of the ELF section stack manipulation directives. The others are .section (see Section
7.66 [Section], page 52), .subsection (see Section 7.79 [SubSection], page 56), .pushsection (see
Section 7.61 [PushSection], page 50), and .popsection (see Section 7.56 [PopSection], page 50).
This directive swaps the current section (and subsection) with most recently referenced section
(and subsection) prior to this one. Multiple .previous directives in a row will flip between two
sections (and their subsections).
In terms of the section stack, this directive swaps the current section with the top section on the
section stack.
7.55 .previous
这是一个ELF段堆栈操作命令。其他的段堆栈操作命令还有.section (见 7.66 [Section], 52
页), .subsection (见 7.79 [SubSection], 56页),.pushsection (见 7.61 [PushSection], 50页),
和 .popsection (见 7.56 [PopSection], 50页)。
本命令交换当前段(及其子段)和最近访问过的段(及其子段)。多个连续的.previous命令
将使当前位置两个段(及其子段)之间反复切换。
用段堆栈的术语来说,本命令使当前段和堆顶段交换位置。
7.56 .popsection
This is one of the ELF section stack manipulation directives. The others are .section (see Section
7.66 [Section], page 52), .subsection (see Section 7.79 [SubSection], page 56), .pushsection (see
Section 7.61 [PushSection], page 50), and .previous (see Section 7.55 [Previous], page 49).
This directive replaces the current section (and subsection) with the top section (and subsection)
on the section stack. This section is popped off the stack.
7.56 .popsection
这是一个ELF段堆栈操作命令。其他的段堆栈操作命令还有.section(见 7.66 [Section], 52
页), .subsection (见 7.79 [SubSection], 56页),.pushsection (见 7.61 [PushSection], 50页),
和 .previous (见 7.55 [Previous], 49页).
本命令用堆栈顶段(及其子段)替代当前段(及其子段)。堆栈顶段出栈。
7.57 .print string
as will print string on the standard output during assembly. You must put string in double quotes.
7.57 .print string
as会在标准输出上打印string字符串。String必须使用双引号。
7.58 .protected names
This one of the ELF visibility directives. The other two are .hidden (see Section 7.32 [Hidden],
page 42) and .internal (see Section 7.39 [Internal], page 44).
This directive overrides the named symbols default visibility (which is set by their binding: local,
global or weak). The directive sets the visibility to protected which means that any references to
the symbols from within the components that defines them must be resolved to the definition in
that component, even if a definition in another component would normally preempt this.
7.58 .protected names
这是一条ELF可见度的相关命令。其它两条是.hidden (参见 7.32 [Hidden], 42页)和 .internal
(参见 7.39 [Internal], 44页)。
本命令将取消指定符号的可见度缺省值(可见度由其他命令捆绑设定:local, global, weak)
本命令将可见度设置为protected,这个可见度意味着:在定义此符号的部件内对此符号的任
何访问,都必须解析到这个部件内的定义体。即使其他部件中存在一个正常情况下比此优先
的定义体。
7.59 .psize lines, columns
Use this directive to declare the number of lines—and, optionally, the number of columns—to use
for each page, when generating listings.
If you do not use .psize, listings use a default line-count of 60. You may omit the comma and
columns specification; the default width is 200 columns.
as generates formfeeds whenever the specified number of lines is exceeded (or whenever you
explicitly request one, using .eject).
If you specify lines as 0, no formfeeds are generated save those explicitly specified with .eject.
7.59 .psize lines , columns
当生成清单列表时,使用本命令声明每页的行数—还可以可选地声明列数。
如果您不使用本命令,清单列表的行数为默认的60行。可以省略逗号和列参数:默认值为
200列。
当指定的行数过多的话,as会产生进纸操作。(如果您确实需要一个进纸动作,可以使用.eject
命令)
如果您指定行数为0,则不产生进纸操作,除非您明确地使用了.eject命令。
7.60 .purgem name
Undefine the macro name, so that later uses of the string will not be expanded. See Section 7.50
[Macro], page 47.
7.60 .purgem name
取消name的宏定义,后面使用字符串name不会被宏扩展。参见 7.50 [Macro], 47页。
7.61 .pushsection name , subsection
This is one of the ELF section stack manipulation directives. The others are .section (see Section
7.66 [Section], page 52), .subsection (see Section 7.79 [SubSection], page 56), .popsection (see
Section 7.56 [PopSection], page 50), and .previous (see Section 7.55 [Previous], page 49).
This directive is a synonym for .section. It pushes the current section (and subsection) onto the top
of the section stack, and then replaces the current section and subsection with name and subsection.
7.61 .pushsection name , subsection
本命令是一个ELF段堆栈操作命令。其余的几个是.section (参见 7.66 [Section], 52
页) , .subsection (参见7.79 [SubSection], 56页),.popsection (参见 7.56 [PopSection], 50页),
和 .previous (参见 7.55 [Previous], 49页)。
本命令与.section命令是等价的。它将当前段(及子段)推入段堆栈的顶部。并使用name
和subsection来替代当前段和子段。
7.62 .quad bignums
.quad expects zero or more bignums, separated by commas. For each bignum, it emits an 8-byte
integer. If the bignum won’t fit in 8 bytes, it prints a warning message; and just takes the lowest
order 8 bytes of the bignum.
The term “quad” comes from contexts in which a “word” is two bytes; hence quad-word for 8
bytes.
7.62 .quad bignums
.quad 可带0或多个bignum参数,每个参数由逗号分隔。对于每个bignum都汇编成一个8
字节的整数。如果某个bignum用8字节无法表示,则给出警告信息;只汇编这个bignum
的最低8字节。
术语“quad”源于一个“word”代表2个字节,所以quad-word代表8个字节。
7.63 .rept count
Repeat the sequence of lines between the .rept directive and the next .endr directive count times.
For example, assembling
.rept 3
.long 0
.endr
is equivalent to assembling
.long 0
.long 0
.long 0
7.63 .rept count
汇编.rept和.endr之间的语句count次。
如, 汇编下列语句:
.rept 3
.long 0
.endr
与下列语句是等价的:
.long 0
.long 0
.long 0
7.64 sbttl "subheading"
Use subheading as the title (third line, immediately after the title line) when generating assembly
listings.
This directive affects subsequent pages, as well as the current page if it appears within ten lines of
the top of a page.
7.64 sbttl "subheading"
当生成汇编清单时,使用subheading作为标题(第3行,紧跟在标题行之后)。
本命令对清单的后续页起作用,如果它位于当前页的前10行内,则对当前页也起作用。
7.65 .scl class
Set the storage-class value for a symbol. This directive may only be used inside a .def/.endef pair.
Storage class may flag whether a symbol is static or external, or it may record further symbolic
debugging information.
The ‘.scl’ directive is primarily associated with COFF output; when configured to generate
output format, as accepts this directive but ignores it.
7.65 .scl class
设置一个符号的存储类型值(storage-class value)。本命令只能在.def/.endef之间使用。符号
的存储类型可以表明符号是static类型或是external类型,或者进一步记录符号的调试信息。
‘.scl’命令主要与在COFF输出有关,当生成输出格式时,as接受本命令,但忽略本
命令。
7.66 .section name (COFF version)
Use the .section directive to assemble the following code into a section named name.
This directive is only supported for targets that actually support arbitrarily named sections; on
targets, for example, it is not accepted, even with a standard section name.
For COFF targets, the .section directive is used in one of the following ways:
.section name [, "flags"]
.section name [, subsegment]
If the optional argument is quoted, it is taken as flags to use for the section. Each flag is a single
character. The following flags are recognized:
b bss section (uninitialized data)
n section is not loaded
w writable section
d data section
r read-only section
x executable section
s shared section (meaningful for PE targets)
If no flags are specified, the default flags depend upon the section name. If the section name is not
recognized, the default will be for the section to be loaded and writable. Note the n and w flags
remove attributes from the section, rather than adding them, so if they are used on their own it will
be as if no flags had been specified at all.
If the optional argument to the .section directive is not quoted, it is taken as a subsegment number
(see Section 4.4 [Sub-Sections], page 25).
7.66 .section name (COFF 版本)
使用.section命令将后续的代码汇编进一个定名为name的段。
本命令只能在目标格式真正支持任意命名段时使用;例如,汇编一个目标格式时,即
使name是一个标准的段名,本命令也不被接受。
当目标格式为COFF时,.section命令的使用为下面某一种格式:
.section name[, "flags"]
.section name[, subsegment]
如可选参数使用了引号,它将被视为该段的标志(flags)。每个标记是单个的字符。下列是认
可的标志。
b bss 段 (未初始化的数据)
n 未装入内存的段
w 可写的段
d 数据段
r 只读段
x 代码段 (executable section)
s 共享段 (目标为PE格式有意义)
如果本命令没有指定标志,则依靠段名来确定标志缺省值。如果该段名没有使用标准段名,
则默认该段已装入内存并且可写。注意在使用n和w标志组合时,不是增加这组属性,而
是删除该段的属性。所以如果只存在这两个标志,就代表该段没有指定任何标志。
如果本命令的可选参数没有使用引号,参数将被视为子段的编号。(参见 4.4 [Sub-Sections],
25页)。
7.67 .section name (ELF 版本)
This is one of the ELF section stack manipulation directives. The others are .subsection (see
Section 7.79 [SubSection], page 56), .pushsection (see Section 7.61 [PushSection], page
50), .popsection (see Section 7.56 [PopSection], page 50), and .previous (see Section 7.55
[Previous], page 49).
For ELF targets, the .section directive is used like this:
.section name [, "flags"[, @type]]
The optional flags argument is a quoted string which may contain any combination of the
following characters:
a section is allocatable
w section is writable
x section is executable
The optional type argument may contain one of the following constants:
@progbits section contains data
@nobits section does not contain data (i.e., section only occupies space)
If no flags are specified, the default flags depend upon the section name. If the section name is not
recognized, the default will be for the section to have none of the above flags: it will not be
allocated in memory, nor writable, nor executable. The section will contain data.
For ELF targets, the assembler supports another type of .section directive for compatibility with
the Solaris assembler:
.section "name"[, ]
Note that the section name is quoted. There may be a sequence of comma separated flags:
#alloc section is allocatable
#write section is writable
#execinstr section is executable
This directive replaces the current section and subsection. The replaced section and subsection are
pushed onto the section stack. See the contents of the gas testsuite directory gas/testsuite/gas/elf
for some examples of how this directive and the other section stack directives work.
7.67 .section name (ELF 版本)
本命令是ELF的段堆栈操作命令之一,其他的段堆栈命令为.subsection (见 Section 7.79
[SubSection], page 56), .pushsection (见Section 7.61 [PushSection], page 50), .popsection (见
Section 7.56 [PopSection], page 50), and .previous (见 Section 7.55 [Previous], page 49).
当目标格式为ELF时,.section命令应如下使用:
.section name [, "flags"[, @type]]
可选参数flags是被引号包围的字符串,可以由下列字符的任意组合:
a 可分配的段(allocatable)
w 可写段
x 代码段
可选的参数type可以包含下列的任一常量:
@progbits 包含数据的段
@nobits 不包含数据的段(只占用空间的段)
如果本命令没有指定标志,则依靠段名来确定标志缺省值。如果段名不是标准的段名,则默
认的该段不包含上述标志:该段不可分配内存,不可写,不可执行。该段是包含数据的段。
当目标格式为ELF时,as还支持另一种形式的.section命令,以便兼容Solaris的汇编器:
.section "name"[, ]
注意段名是使用引号包围的,可能存在一系列由逗号分隔分隔的标志:
#alloc 可分配的段(section is allocatable)
#write 可写的段
#execinstr 可执行的段
本命令将(用段名为name的段)替代当前段和子段。被替换的段将被推入段堆栈。参见gas
的测试套件目录gas/testsuite/gas/elf,可以找到一些本命令和其他段堆栈操作命令的例子。
7.68 .set symbol, expression
Set the value of symbol to expression. This changes symbol’s value and type to conform to
expression. If symbol was flagged as external, it remains flagged (see Section 5.5 [Symbol
Attributes], page 30).
You may .set a symbol many times in the same assembly.
If you .set a global symbol, the value stored in the object file is the last value stored into it.
The syntax for set on the HPPA is ‘symbol .set expression’.
7.68 .set symbol, expression
设置symbol为expression。这将改变symbol的值域和类型领域以符合expression参数。如
果symbol已被标志为external,则symbol保持它的标志。(见 5.5 [Symbol Attributes], 30页)。
您可以在同一个汇编程序中多次使用.set命令来设置同一个符号。
如果设置一个全局符号,该符号在目标文件中值为最后设定的值。
在HPPA上的语法是‘symbol .set expression’。
7.69 .short expressions
.short is normally the same as ‘.word’. See Section 7.92 [.word], page 59.
In some configurations, however, .short and .word generate numbers of different lengths; see
Chapter 8 [Machine Dependencies], page 61.
7.69 .short expressions
本命令通常和’.word’命令一样,见7.92 [.word], 59页.
然而在某些配置中,.short和.word命令生成的数字长度却不相同;见第8章 [Machine
Dependencies], 61页.
7.70 .single flonums
This directive assembles zero or more flonums, separated by commas. It has the same effect
as .float. The exact kind of floating point numbers emitted depends on how as is configured. See
Chapter 8 [Machine Dependencies], page 61.
7.70 .single flonums
本命令可以汇编0个或多个浮点参数,各个参数之间使用逗号分隔。它的作用和.float相同。
生成浮点数的具体类型视as的配置而定。见第8章 [Machine Dependencies], 61页。