3

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)?

wjandrea
  • 14,109
  • 4
  • 48
  • 98
user3699039
  • 39
  • 1
  • 4

2 Answers2

5

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

muru
  • 193,181
  • 53
  • 473
  • 722
1

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.

Ciro Santilli OurBigBook.com
  • 26,663
  • 14
  • 108
  • 107