Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install and use GAS (GNU Compiler) on Linux?

I'm using Ubuntu, and I was looking for an assembler compiler for Linux, and I found GAS.

I'm trying to install it and run it, but I can't.

like image 862
rogcg Avatar asked Nov 23 '10 01:11

rogcg


People also ask

What does GNU assembler do?

The GNU Assembler, commonly known as gas or as, is the assembler developed by the GNU Project. It is the default back-end of GCC. It is used to assemble the GNU operating system and the Linux kernel, and various other software. It is a part of the GNU Binutils package.

What is GCC make?

GNU Compiler Collection (GCC): a compiler suite that supports many languages, such as C/C++ and Objective-C/C++. GNU Make: an automation tool for compiling and building applications. GNU Binutils: a suite of binary utility tools, including linker and assembler. GNU Debugger (GDB).


2 Answers

as is the GNU Assembler. It's found in binutils but if you do:

sudo apt-get install build-essential

You will get gas along with gcc (which default uses gas for assembling on the back end).

For a 'tutorial' about using gas, you probably want to read Programming From the Ground Up, which uses it.


To build a static executable from a .s file,

#!/bin/bash
f="${1:-}"
as "${f}" -o "${f%%.s}.o" && ld "${f%%.s}.0" -o "${f%%.s}"
gcc -nostdlib -static "${f}" -o "${f%%.s}"

If you want to link with libraries, it's normally easiest to let gcc use the right command line options for as and ld when building an executable from an asm source file.
gcc foo.s -o foo will work if your foo.s defines a main function.

Also related: Assembling 32-bit binaries on a 64-bit system (GNU toolchain) if you're writing 32-bit programs on an x86-64 system.

like image 86
逆さま Avatar answered Oct 05 '22 12:10

逆さま


It's in the binutils package.

like image 45
Ignacio Vazquez-Abrams Avatar answered Oct 05 '22 12:10

Ignacio Vazquez-Abrams