as command in linux with examples
Last Updated :
18 Jun, 2024
as command is the portable GNU assembler in Linux. Using as command, we can read and assemble a source file.
- The main purpose of 'as' is to assemble the output of the GNU compiler of the C language.
- as command reads and assembles the .s File. Also, whenever you do not specify the file, it normally reads, assembles the STDIN.
- Output is stored in a file named a.out and the format of the file is XCOFF.
Note: Source file i.e .s file is an extension for source files that are written in assembly languages.
Syntax:
as [ -a Mode ] [ -o ObjectFile ] [ -n Name ] [ -u ] [ -l [ ListFile ] ] [ -W | -w ] [ -x [ XCrossFile ] ] [ -s [ ListFile ]] [ -m ModeName ][-M][-Eoff|on ] [ -p off|on ] [ -i ] [ -v ] [ File ]
Note:
- Location of command in Linux Directory: /usr/ccs/bin/as
- Output : a.out
Options:
To display all options use the command help:
Syntax:
as --help


Options for as command with examples
1. creating .s files
.s source files are associated with the GNU Assembler.
Input:

Output:

.s file :

2. as: gives out files as output after applying the command
Consider the sample .s file which we have generated using the above example, So now applying as command to the sample.s file, we will be generating an a.out file.
Syntax:
as sample.s
Output :

Note: The following options are optional
3. -a: In General, as command will be operating in 32-bit mode. Using the -a command, we can know in which mode as command is operating. This mode can also be set by using -a32 if we need a 32-bit operation / -a64 if we need a 64-bit operation.
Consider the above sample.s file which we have generated using sample.c program. Applying -a to the file will list the understanding of the .s code that has been generated.
Syntax:
as sample.s -a
Output:

4. -v: This option can be used to display the version number.
Consider the sample.s file which we have generated using the above example, So now applying the -v option to the sample.s file, we will know the version.
Syntax:
as sample.s -v
Output:

5. -D: This has no effect. It is accepted to make it more likely that the scripts that are written for other assemblers will also work with the as command.
Example: consider the option with the sample. s program
Syntax:
as sample.s -D

6. --MD: Using this option, as can make a dependency file for the file it creates. The file contains dependencies of the main source file.
Example: We need to use a filename in an argument. Consider the sample.s file
Main Use: This feature is used in the automatic updating of makefiles.
Syntax:
as sample.s --MD two

7. --statistics: This will be displaying the statistics of resources used by the as command.
Note: The result will be in the format, the maximum amount of space allocated during the assembly, total execution time taken for the assembly.
In bytes and CPU Seconds respectively.
Syntax:
as sample.s --statistics
Similar Reads
aspell command in Linux with examples aspell command is used as a spell checker in Linux. Generally, it will scan the given files or anything from standard input then it check for misspellings. Finally, it allows the user to correct the words interactively. Spell checking is crucial when working with large documents, coding, or writing
3 min read
bison command in Linux with Examples bison command is a replacement for the yacc. It is basically a parser generator similar to yacc. Input files should follow the yacc convention of ending in .y format. Similar to yacc, the generated files do not have fixed names, but instead use the prefix of the input file. Moreover, if you need to
4 min read
autoscan command in Linux with Examples autoscan command in Linux is used to generate a preliminary configure.in file. Basically, this command will check the source file in the directory tree rooted at SRCDIR, or the current directory if none is given. It also searches the source files for common portability problems, check for the incomp
2 min read
ex command in Linux with examples ex (stands for extended) is a text editor in Linux which is also termed as the line editor mode of the vi editor. This editor simply provided some editing commands which has greater mobility. With the help of this editor, a user can easily move between files. Also, he/she has a lot of ways to transf
4 min read
apt-get command in Linux with Examples The command-line tool `apt-get` is the most popular package management tool used in our Debian-based Linux operating system. This article provides an overview of `apt-get` and its basic syntax. It will include the most commonly used commands, their syntax, description, and examples. It also gives an
15+ min read
gcc command in Linux with examples GCC stands for GNU Compiler Collections which is used to compile mainly C and C++ language. It can also be used to compile Objective C and Objective C++. The most important option required while compiling a source code file is the name of the source program, rest every argument is optional like a wa
2 min read
automake command in Linux with Examples automake is a tool used for automatically generating Makefile.in files compliant with the set GNU Coding Standards. autoconf is required for the use of automake. automake manual can either be read on-line or downloaded in the PDF format. More formats are also offered for download or on-line reading.
1 min read
sync command in Linux with Examples sync command in Linux is used to synchronize cached writes to persistent storage. If one or more files are specified, sync only them, or their containing file systems. Syntax: sync [OPTION] [FILE]... Note: Nothing is being shown in the screenshots just because sync command makes the cache in the bac
1 min read
help Command in Linux with examples If youâre new to the Linux operating system and struggling with command-line utilities, the help command is one of the first tools you should learn. As its name suggests, the 'help' command provides detailed information about built-in shell commands, making it an essential resource for beginners and
5 min read
emacs command in Linux with examples Introduction to Emacs Editor in Linux/Unix Systems: The Emacs is referred to a family of editors, which means it has many versions or flavors or iterations. The most commonly used version of Emacs editor is GNU Emacs and was created by Richard Stallman. The main difference between text editors like
5 min read