2

I'm writing a C project in Xcode and I'd like to link a separate assembly file to be compiled along with the project. But I need the assembly to be written in Intel syntax since I find AT&T syntax absolutely grotesque.

Unfortunately, Apple's default Clang compiler doesn't like me writing my assembly code in Intel and prefers AT&T. Is there a setting I can change to allow my separate assembly file to be written in Intel syntax?

As an example, this assembles:

.text  
.global _func  
func:  
mov %rdx,%rax  
ret

But this doesn't assemble

.text  
.global _func  
_func:  
mov rax,rdx  
ret

The compiler throws errors with the latter example.

_func Is being called from the C code.

#include <stdio.h>
void func(void);
int main(int argc, const char * argv[]) {
    func();
    return 0;
}

To clarify, I am not writing inline assembly.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Irelia
  • 3,407
  • 2
  • 10
  • 31

1 Answers1

3

If you want to use asm intel syntax. Just add .intel_syntax noprefix to begin of asm file.

.intel_syntax noprefix
.text  
.global _func  
_func:  
mov rax,rdx  
ret
Thanh Vu
  • 1,599
  • 10
  • 14