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
cc command in Linux with Examples
'cc' command stands for C Compiler, usually an alias command to 'gcc' or 'clang'. As the name suggests, executing the 'cc' command will usually call the 'gcc' on Linux systems. It is used to compile the C language codes and create executables. The number of options available for the cc command is ve
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
adduser command in Linux with Examples
adduser command in Linux is used to add a new user to your current Linux machine. This command allows you to modify the configurations of the user which is to be created. It is similar to the useradd command in Linux. The adduser command is much interactive as compared to useradd command. Installing
4 min read
apropos command in Linux with Examples
Linux/Unix comes with a huge number of commands and thus it become quite difficult sometimes to remember each and every command. apropos command becomes useful in such cases. apropos command helps the user when they don't remember the exact command but knows a few keywords related to the command tha
3 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
gs command in Linux with Examples
gs command invokes Ghostscript, which is an interpreter of Adobe Systems PostScript and Portable Document Format(PDF) languages. After executing Ghostscript it reads further input from the standard input stream until it encounters 'quit' command. Syntax: gs [ options ] [ files ] ... Options: Below a
2 min read
df command in Linux with Examples
Ever felt the chilling fear of a "disk full" error message on your Linux machine? Fear not, for the mighty df command stands ready to guide you through the treacherous terrain of disk space management! This article delves deep into the df command, equipping you with the knowledge and skills to navig
5 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