Kulacs
Kulacs

Reputation: 51

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

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?

Upvotes: 2

Views: 1739

Answers (1)

Zeta
Zeta

Reputation: 105885

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.

Upvotes: 3

Related Questions