Originally Posted by
Sipher
Not incorrect code, just the wrong type. And yes, it's true!
'gcc -masm=intel -save-temps test.c'
test.c
Code:
#include <stdio.h>
unsigned int i = 0;
int main()
{
printf("%d\n", i);
asm(".intel_syntax noprefix\n");
asm("mov dword ptr [i], 1\n");
printf("%d\n", i);
return 0;
}
test.s
Code:
.file "test.c"
.intel_syntax noprefix
.globl i
.bss
.align 4
.type i, @object
.size i, 4
i:
.zero 4
.section .rodata
.LC0:
.string "%d\n"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
push rbp
.cfi_def_cfa_offset 16
mov rbp, rsp
.cfi_offset 6, -16
.cfi_def_cfa_register 6
mov edx, DWORD PTR i[rip]
mov eax, OFFSET FLAT:.LC0
mov esi, edx
mov rdi, rax
mov eax, 0
call printf
#APP
# 8 "test.c" 1
.intel_syntax noprefix
# 0 "" 2
# 9 "test.c" 1
mov dword ptr [i], 1
# 0 "" 2
#NO_APP
mov edx, DWORD PTR i[rip]
mov eax, OFFSET FLAT:.LC0
mov esi, edx
mov rdi, rax
mov eax, 0
call printf
mov eax, 0
leave
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (GNU) 4.4.3"
Compiles and runs just fine. Notice the lack of AT&T assembly.
Btw, apparently the '-masm=intel' switch makes '.intel_syntax noprefix' implicitly specified. I didn't know that until now