extern int input ,result;
2
3 void test_at_t()
4 {
5 result = 0;
6 input = 1;
7 __asm__
8 __volatile__("addl%1, %0":"=r"(result):"r"(input));
9 }
~
~
~ test.c
~
2 .text
3 .globl test_at_t
4 .type test_at_t, @function
5 test_at_t:
6 pushl %ebp
7 movl %esp, %ebp
8 movl $0, result
9 movl $1, input
10 movl input, %eax
11 #APP
12 # 7 "test_at_t.c" 1
13 addl%eax, %eax
14 # 0 "" 2
15 #NO_APP
16 movl %eax, result
17 popl %ebp
18 ret
19 .size test_at_t, .-test_at_t
20 .ident "GCC: (Debian 4.4.5-8) 4.4.5"
21 .section .note.GNU-stack,"",@progbits
~
~/test_at_t.s[1] [asm] unix utf-8 2:1/21
2
3 void test_at_t()
4 {
5 result = 0;
6 input = 1;
7 __asm__
8 __volatile__("addl%1, %0":"=r"(result):"r"(input));
9 }
~
~
~ test.c
~
$gcc -S test.c
编译后产生test.s
2 .text
3 .globl test_at_t
4 .type test_at_t, @function
5 test_at_t:
6 pushl %ebp
7 movl %esp, %ebp
8 movl $0, result
9 movl $1, input
10 movl input, %eax
11 #APP
12 # 7 "test_at_t.c" 1
13 addl%eax, %eax
14 # 0 "" 2
15 #NO_APP
16 movl %eax, result
17 popl %ebp
18 ret
19 .size test_at_t, .-test_at_t
20 .ident "GCC: (Debian 4.4.5-8) 4.4.5"
21 .section .note.GNU-stack,"",@progbits
~
~/test_at_t.s[1] [asm] unix utf-8 2:1/21
本文介绍了一个使用GCC内联汇编的例子,具体展示了如何在C语言中直接插入AT&T语法的汇编指令来修改变量值。通过具体的代码示例和编译后的汇编代码对比,读者可以深入了解GCC内联汇编的工作原理。
1925

被折叠的 条评论
为什么被折叠?



