12

我正在使用 Ubuntu,我正在寻找适用于 Linux 的汇编编译器,然后我找到了 GAS。

我正在尝试安装并运行它,但我不能。

4

5 回答 5

21

asGNU 汇编器。它位于binutils但如果你这样做:

sudo apt-get install build-essential

你会相处得gas很好gcc(默认gas用于在后端组装)。

有关 using 的“教程” gas,您可能想阅读Programming From the Ground Up,它使用它。


要从文件构建静态可执行.s文件,

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

如果您想与库链接,通常最简单的方法是让 gcc 在从 asm 源文件构建可执行文件时as使用正确的命令行选项。如果您定义了一个函数,它将起作用。ld
gcc foo.s -o foofoo.smain

还相关:如果您在 x86-64 系统上编写 32 位程序,则在64 位系统(GNU 工具链)上组装 32 位二进制文​​件。

于 2010-11-23T01:57:11.713 回答
4

它在binutils包里。

于 2010-11-23T01:53:50.017 回答
4

启动 Synaptic 并在快速搜索栏中输入“gnu assembler”。很明显,这binutils是必需的包。

你可能会发现它已经安装好了。我binutils 2.20.1-3ubuntu7的已经安装了,我有一个相当普通的设置。

从终端窗口输入as --version会让你知道:

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'.
于 2010-11-23T01:56:46.540 回答
0

你读过http://www.faqs.org/docs/Linux-HOWTO/Assembly-HOWTO.html吗?关于 Debian GAS 包含在包中

二进制工具

所以

sudo apt-get install binutils
dpkg -L binutils

$man 作为

于 2010-11-23T01:58:40.710 回答
0

从源代码构建并使用它

#!/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 上游.

TODO:如何配置as特定选项?我们使用./configurebinutils-gdb顶层的,但它包含来自多个项目的选项,例如gdb我相信的,而不是as特定的?

在 Ubuntu 18.04 上测试。

于 2018-10-22T11:42:41.097 回答