Errors on assembling ARM asm on an x86 PC with GCC or `as`

心不动则不痛 提交于 2020-04-05 06:12:12

问题


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

Project name: asmtut.s

The Code:

.text

.global _start

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

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?


回答1:


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

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.


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.

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.

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.



来源:https://stackoverflow.com/questions/49275523/errors-on-assembling-arm-asm-on-an-x86-pc-with-gcc-or-as

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!