How to install GNU Assembler

5,017

Solution 1

GNU assembler, AKA as, is installed by default on Ubuntu. It is in the package binutils.

Solution 2

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

GitHub upstream.

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.

Share:
5,017

Related videos on Youtube

user3699039
Author by

user3699039

Working as Team Member and experienced backend resource. All the time, busy writing clean code, have adopted TDD since start of the career. And translating business requirements to technical solutions. An experienced web, distributed and enterprise application developer with more than 3 years of experience. Primary skills are Java, Spring Framework, SQL, CSS HTML. On the journey to adopt tools like ELK, Prometheus, Kubernetes and Grafana in daily work routine.

Updated on September 18, 2022

Comments

  • user3699039
    user3699039 over 1 year

    I am trying to write a boot-loader, so I need GNU Assembler. I googled it but didn't find any helpful material. How can I install GNU Assembler (and not GNU Compiler)?

  • user3699039
    user3699039 about 7 years
    can you tell me how i can use it?
  • muru
    muru about 7 years
    Teaching you assembly language is well beyond the scope of a post here.
  • user3699039
    user3699039 about 7 years
    any useful link or other material
  • Jean-Marie
    Jean-Marie about 7 years
    man as maybe?