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.
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.
apt-get or similar tools, it should be already in your system PATH. So simply try as or gas on the terminal and see what it says. If as was not installed and you typed out as on the terminal, Ubuntu systems normally show the package in which the command is bundled. So you can simply go ahead and sudo apt-get install <missing package name> on the terminal.It's in the binutils package.
Fire up Synaptic and enter "gnu assembler" into the quick search bar. It's immediately obvious that binutils is the required package.
And you may well find it's already installed. My binutils 2.20.1-3ubuntu7 is already installed and I have a fairly vanilla set-up.
Entering as --version from a terminal window will let you know:
GNU assembler (GNU Binutils for Ubuntu) 2.20.1-system.20100303 Copyright 2009 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or later. This program has absolutely no warranty. This assembler was configured for a target of `i486-linux-gnu'. Have you read http://www.faqs.org/docs/Linux-HOWTO/Assembly-HOWTO.html? on Debian GAS is contained in the package
binutils
so
sudo apt-get install binutils dpkg -L binutils $man as
Build from source and use it
#!/usr/bin/env bash set -eux # Build. sudo apt-get build-dep binutils git clone git://sourceware.org/git/binutils-gdb.git cd binutils-gdb git checkout binutils-2_31 ./configure --target x86_64-elf --prefix "$(pwd)/install" make -j `nproc` make install # Test it out. cat <<'EOF' > hello.S .data s: .ascii "hello world\n" len = . - s .text .global _start _start: mov $4, %eax mov $1, %ebx mov $s, %ecx mov $len, %edx int $0x80 mov $1, %eax mov $0, %ebx int $0x80 EOF ./install/bin/x86_64-elf-as -o hello.o hello.S ./install/bin/x86_64-elf-ld -o hello hello.o ./hello TODO: how to configure as specific options? We have used the ./configure from the binutils-gdb top-level, but that contains options from multiple projects such as gdb I believe, and not as specific ones?
Tested on Ubuntu 18.04.