Open In App

as command in linux with examples

Improve
Improve
Like Article
Like
Save
Share
Report

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


Last Updated : 14 Sep, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads