[cfe-dev] assembly syntax

Thiago Farina tfransosi at gmail.com
Sun Aug 10 06:46:35 PDT 2014


On Sun, Aug 10, 2014 at 9:21 AM, Anton Korobeynikov
<anton at korobeynikov.info> wrote:
>> How can I change the syntax used by clang, so yasm accepts it without
>> having to pass -p gas?
> No way. yasm uses nasm syntax by default.
>
So the solution seems to be use 'as'.

This worked for me:

$ clang -S -O0 -masm=intel add.c -o add-intel.s
$ cat add-intel.s
.globl add
add:
push rbp
mov rbp, rsp
mov dword ptr [rbp - 4], edi
mov dword ptr [rbp - 8], esi
mov esi, dword ptr [rbp - 4]
add esi, dword ptr [rbp - 8]
mov eax, esi
pop rbp
ret

$ as -mnaked-reg -msyntax=intel add-intel.s -o add_def.o

Simpler, this also worked:

$ clang -S -O0 add.c -o add-att.s
$ cat add-att.s
.globl add
add:
pushq %rbp
movq %rsp, %rbp
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
movl -4(%rbp), %esi
addl -8(%rbp), %esi
movl %esi, %eax
popq %rbp
retq
$ as add-att.s -o add_def.o

--
Thiago



More information about the cfe-dev mailing list