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)?
Asked
Active
Viewed 6,613 times
2 Answers
5
GNU assembler, AKA as, is installed by default on Ubuntu. It is in the package binutils.
muru
- 193,181
- 53
- 473
- 722
-
can you tell me how i can use it? – user3699039 Feb 09 '17 at 17:35
-
2Teaching you assembly language is well beyond the scope of a post here. – muru Feb 09 '17 at 17:35
-
any useful link or other material – user3699039 Feb 09 '17 at 17:59
-
`man as` maybe? – Jean-Marie Feb 09 '17 at 18:32
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
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