使用 GCC 或 `as` 在 x86 PC 上组装 ARM asm 时出错 [英] Errors on assembling ARM asm on an x86 PC with GCC or `as`

查看:15
本文介绍了使用 GCC 或 `as` 在 x86 PC 上组装 ARM asm 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在做一个组装教程,一开始就卡住了.

So I have been doing an assembly tutorial, and I got stuck in the very beginning.

项目名称:asmtut.s

Project name: asmtut.s

代码:

.text

.global _start

start:
  MOV R0, #65
  MOV R7, #1

SWI 0

一开始,我在尝试此行后收到 3 条错误消息:

as -o asmtut.o asmtut.s

asmtut.s:6:错误:在,"之后需要操作数;一无所有
asmtut.s:7:错误:在,"之后需要操作数;一无所有
asmtut.s:9:错误:没有这样的指令:'swi 0'

Right off the beginning I'm welcomed by 3 error messages after I try this line:

as -o asmtut.o asmtut.s

asmtut.s:6: Error: expecting operand after ','; got nothing
asmtut.s:7: Error: expecting operand after ','; got nothing
asmtut.s:9: Error: no such instruction: 'swi 0'

我很困惑,因为这是教程中的确切代码,并且完全可以正常工作.

I'm confused, because this is the exact code in the tutorial, and there it works completely fine.

谁能帮帮我这是什么原因造成的?

Can anyone help me what could cause this?

推荐答案

您正在尝试使用 x86 汇编器来汇编 ARM 代码.它们使用不同的指令集和语法.

You're trying to use an x86 assembler to assemble ARM code. They use different instruction sets and syntax.

x86 Linux 系统上的原生 gccas 工具会阻塞,就像您尝试使用 Java 编译器编译 C++ 一样,反之亦然.例如,# 是 GAS x86 语法中的注释字符,因此 mov r0, 甚至在注意到 r0 不是有效的 x86 寄存器名称.

The native gcc and as tools on your x86 Linux system will choke, just like if you tried to compile C++ with a Java compiler or vice versa. For example, # is the comment character in GAS x86 syntax, so mov r0, is a syntax error before it even gets to the point of noticing that r0 isn't a valid x86 register name.

您正在学习在基于 x86 的 PC 上在 Raspberry Pi(一种 ARM 架构)上进行组装的教程.在 Raspberry Pi 上运行 as,或为 Rasperry Pi/ARM 安装交叉编译工具链.

You're following a tutorial for Assembly on Raspberry Pi (an ARM architecture) on a x86-based PC. Either run as on the Raspberry Pi, or install a cross-compile toolchain for Rasperry Pi/ARM.

一些 Linux 发行版具有提供 arm-linux-gnueabi-as...-gcc 的软件包.例如,https://www.acmesystems.it/arm9_toolchain 有 Ubuntu 的详细信息.

Some Linux distros have packages that provide arm-linux-gnueabi-as and ...-gcc. For example, https://www.acmesystems.it/arm9_toolchain has details for Ubuntu.

要实际运行生成的二进制文件,您可以在 ARM 系统上运行它们,或者需要像 qemu-arm 这样的 ARM 模拟器.如何在 QEMU 上的 GDB 中进行单步 ARM 组装?如何运行单行汇编,然后查看 [R1] 和条件标志 有这样做的演练.

To actually run the resulting binaries, you'd either run them on your ARM system, or you'd need an ARM emulator like qemu-arm. How to single step ARM assembly in GDB on QEMU? and How to run a single line of assembly, then see [R1] and condition flags have walkthroughs of doing that.

这篇关于使用 GCC 或 `as` 在 x86 PC 上组装 ARM asm 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆