[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Assembler Language Reference

Assembling and Linking a Program

Assembly language programs can be assembled with the as command or the cc command. The ld command or the cc command can be used to link assembled programs. This section discusses the following:

Assembling with the as Command

The as command invokes the assembler. The syntax for the as command is as follows:

as [ -a Mode ] [ -oObjectFile ] [ -n Name ] [ -u ] [ -l[ListFile] ]
	[ -W | -w ] [ -x[XCrossFile] ] [ -s [ListFile] ] [ -m ModeName ]
	[ -Eoff|on ] [ -poff|on ] [-i] [-v] [ File ]

The as command reads and assembles the file specified by the File parameter. By convention, this file has a suffix of .s. If no file is specified, the as command reads and assembles standard input. By default, the as command stores its output in a file named a.out. The output is stored in the XCOFF file format.

All flags for the as command are optional.

The ld command is used to link object files. See the ld command for more information.

The assembler respects the setting of the OBJECT_MODE environment variable. If neither -a32 or -a64 is used, the environment is examined for this variable. If the value of the variable is anything other than the values listed in the following table, an error message is generated and the assembler exits with a non-zero return code. The implied behavior corresponding to the valid settings are as follows:

OBJECT_MODE=32 Produce 32-bit object code. The default machine setting is com.
OBJECT_MODE=64 Produce 64-bit object code (XCOFF64 files). The default machine setting is ppc64.
OBJECT_MODE=32_64 Invalid.
OBJECT_MODE=anything else Invalid.

as Command Flags

The following flags are recognized by the as command:

-a Mode Specifies the mode in which the as command operates. By default, the as command operates in 32-bit mode, but the mode can be explicitly set by using the flag -a32 for 32-bit mode operation or -a64 for 64-bit mode operation.
-E[off|on] Specifies whether to report errors due to the v2.00 syntax (-Eon), or to ignore them (-Eoff). By default, v2.00 errors are ignored.
File Specifies the source file. If no file is specified, the source code is taken from standard input.
-i Specifies that branch prediction suffixes are to be encoded. By default, this option is not set. This option is ignored if the -p option is specified.
-l[ListFile] Produces an assembler listing. If you do not specify a file name, a default name is produced by replacing the suffix extension of the source file name with a .lst extension. (By convention, the source file suffix is a .s.) For example:
sourcefile.xyz

produces a default name of:

sourcefile.lst

If the source code is from standard input and the -l flag is used without specifying an assembler-listing file name, the listing file name is a.lst.

-m ModeName Indicates the assembly mode. This flag has lower priority than the .machine pseudo-op.

If this flag is not used and no .machine pseudo-op is present in the source program, the default assembly mode is used. The default assembly mode has the POWER family/PowerPC intersection as the target environment, but treats all POWER family/PowerPC incompatibility errors (including instructions outside the POWER family/PowerPC intersection and invalid form errors) as instructional warnings.

If an assembly mode that is not valid is specified and no .machine pseudo-op is present in the source program, an error is reported and the default assembly mode is used for instruction validation in pass 1 of the assembler.

If the -m flag is used, the ModeName variable can specify one of the following values:

""
Explicitly specifies the default assembly mode which has the POWER family/PowerPC intersection as the target environment, but treats instructions outside the POWER family/PowerPC intersection and invalid form errors as instructional warnings. A space is required between -m and the null string argument (two double quotation marks).
com
Specifies the POWER family/PowerPC intersection mode. A source program can contain only instructions that are common to both POWER family and PowerPC; any other instruction causes an error. Any instruction with an invalid form causes errors, terminates the assembly process, and results in no object code being generated.

Note:Certain POWER family instructions are supported by the PowerPC 601 RISC Microprocessor, but do not conform to the PowerPC architecture. These instructions cause errors when using the com assembly mode.
any
Specifies the indiscriminate mode. The assembler generates object code for any recognized instruction, regardless of architecture. This mode is used primarily for operating system development and for testing and debugging purposes.
Note
All POWER family/PowerPC incompatibility errors are ignored when using the any assembly mode, and no warnings are generated.
-m ModeName continued
ppc
Specifies the PowerPC mode. A source program can contain only PowerPC instructions. Any other instruction causes an error.
Notes:
  1. The PowerPC optional instructions are not implemented in every PowerPC processor and do not belong to the ppc mode. These instructions generate an error if they appear in a source program which is assembled using the ppc assembly mode.
  2. Certain instructions conform to the PowerPC architecture, but are not supported by the PowerPC 601 RISC Microprocessor.
ppc64
Specifies the PowerPC 64-bit mode. A source program can contain 64-bit PowerPC instructions.
pwr
Specifies the POWER family mode. A source program can contain only instructions for the POWER family implementation of the POWER family architecture.
pwr2(pwrx)
Specifies the POWER2 mode. A source program can contain only instructions for the POWER2 implementation of the POWER family architecture. pwr2 is the preferred value. The alternate assembly mode value pwrx means the same thing as pwr2.
Note
The POWER family implementation instruction set is a subset of the POWER2 implementation instruction set.
601
Specifies the PowerPC 601 RISC Microprocessor mode. A source program can contain only instructions for the PowerPC 601 RISC Microprocessor.
Note
The PowerPC 601 RISC Microprocessor design was completed before the PowerPC architecture. Therefore, some PowerPC instructions may not be supported by the PowerPC 601 RISC Microprocessor.
Attention: It is recommended that the 601 assembly mode not be used for applications that are intended to be portable to future PowerPC systems. The com or ppc assembly mode should be used for such applications.

The PowerPC 601 RISC Microprocessor implements the PowerPC architecture plus some POWER family instructions which are not included in the PowerPC architecture. This allows existing POWER family applications to run with acceptable performance on PowerPC systems. Future PowerPC systems will not have this feature. The 601 assembly mode may result in applications that will not run on existing POWER family systems and that may not have acceptable performance on future PowerPC systems, because the 601 assembly mode permits the use of all the instructions provided by the PowerPC 601 RISC Microprocessor.

603
Specifies the PowerPC 603 RISC Microprocessor mode. A source program can contain only instructions for the PowerPC 603 RISC Microprocessor.
604
Specifies the PowerPC 604 RISC Microprocessor mode. A source program can contain only instructions for the PowerPC 604 RISC Microprocessor.
A35
Specifies the A35 mode. A source program can contain only instructions for the A35.
-n Name Specifies the name that appears in the header of the assembler listing. By default, the header contains the name of the assembler source file.
-o ObjectFile Writes the output of the assembly process to the specified file instead of to the a.out file.
-p[off|on] Specifies whether to use the v2.00 branch prediction (-pon) or pre-v2.00 branch prediction (-poff). By default, pre-v2.00 branch prediction is used.
-s[ListFile] Indicates whether or not a mnemonics cross-reference for POWER family and PowerPC is included in the assembler listing. If this flag is omitted, no mnemonics cross-reference is produced. If this flag is used, the assembler listing will have POWER family mnemonics if the source contains PowerPC mnemonics, and will have PowerPC mnemonics if the source contains POWER family mnemonics.

The mnemonics cross-reference is restricted to instructions that have different mnemonics in POWER family and PowerPC, but that have the same op code, function, and input operand format.

Because the -s flag is used to change the assembler-listing format, it implies the -l flag. If both option flags are used and different assembler-listing file names (specified by the ListFile variable) are given, the listing file name specified by the ListFile variable used with the -l flag is used. If an assembler-listing file name is not specified with either the -l or -s flag, a default assembler listing file name is produced by replacing the suffix extension of the source file name with a .lst extension.

-u Accepts an undefined symbol as an extern so that an error message is not displayed. Otherwise, undefined symbols are flagged with error messages.
-v Displays the version number of this command.
-W Turns off all warning message reporting, including the instructional warning messages (the POWER family and PowerPC incompatibility warnings).
-w Turns on warning message reporting, including reporting of instructional warning messages (the POWER family and PowerPC incompatibility warnings).
Note
When neither -W nor -w is specified, the instructional warnings are reported, but other warnings are suppressed.
-x[XCrossFile] Produces cross-reference output. If you do not specify a file name, a default name is produced by replacing the suffix extension of the source file name with an .xref extension. By convention, the suffix is a .s. For example:
sourcefile.xyz

produces a default name of:

sourcefile.xref
Note
The assembler does not generate an object file when the -x flag is used.

Assembling and Linking with the cc Command

The cc command can be used to assemble and link an assembly source program. The following example links object files compiled or assembled with the cc command:

cc pgm.o subs1.o subs2.o

When the cc command is used to link object files, the object files should have the suffix of .o as in the previous example.

When the cc command is used to assemble and link source files, any assembler source files must have the suffix of .s. The cc command invokes the assembler for any files having this suffix. Option flags for the as command can be directed to the assembler through the cc command. The syntax is:

-Wa,Option1,Option2,...

The following example invokes the assembler to assemble the source program using the com assembly mode, and produces an assembler listing and an object file:

cc -c -Wa,-mcom,-l file.s

The cc command invokes the assembler and then continues processing normally. Therefore:

cc -Wa,-l,-oXfile.o file.s

will fail because the object file produced by the assembler is named Xfile.o, but the linkage editor (ld command) invoked by the cc command searches for file.o.

If no option flag is specified on the command line, the cc command uses the compiler, assembler, and link options, as well as the necessary support libraries defined in the xlc.cfg configuration file.

Note
Some option flags defined in the assembler and the linkage editor use the same letters. Therefore, if the xlc.cfg configuration file is used to define the assembler options (asopt) and the link-editor options (ldopt), duplicate letters should not occur in asopt and ldopt because the cc command is unable to distinguish the duplicate letters.

For more information on the option flags passed to the cc command, see the cc command.

Related Information

Understanding Assembler Passes.

Interpreting an Assembler Listing.

Interpreting a Symbol Cross-Reference.

Subroutine Linkage Convention.

Understanding and Programming the TOC.

Running a Program.

The as command, and the ld command.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]