/*
* An example of using C global variables.
*
* 记住,数据变量必须被声明为全局的。不能在asm段中使用局部变量
*/
#include
int a = 10;
int b = 20;
int result = 0;
int main()
{
__asm("nop\n\t"
"pusha\n\t"
"movl a, %eax\n\t"
"movl b, %ebx\n\t"
"imull %ebx, %eax\n\t"
"movl %eax, result\n\t"
"popa");
printf("The answer is %d\n", result);
__asm__("movl $1, %eax\n\t"
"movl $0, %ebx\n\t"
"int $0x80");
}
/* gcc -o 02 02-global-variables.c -m32 */