#include <stdio.h>
#include <string.h>
/*
函数名: att_asm_p();
功能:类似于Intel汇编功能:mov ebx, [OSTCBCur]
mov esp, [ebx]
返回值: 无
传入值: 无
*/
void att_asm_p(void)
{
int b = 11;
int d = 599;
int *p = &d;
asm("movl %0, %%ecx \n\t"::"r"(p));
asm("movl (%ecx),%eax \n\t");
asm("movl %%eax,%0 \n\t":"=r"(b));
printf("b: %d\n", b);
}
/*
函数名: att_asm_mov();
功能:类似于Intel汇编功能:mov
说明: "movl %1, %%esi \n\t" //%1对应第二出现的c语言变量(__in1)
"movl %2, %%edi \n\t" //%2对应第三出现的c变量(__in2)
"movl %%edi, %0 \n\t" //%0对应第一出现的C变量(__out)
: "=a"(__out)
: "r" (__in1), "r" (__in2));
返回值: 无
传入值: 无
*/
void att_asm_mov()
{
int __out = 1, __in1 = 2, __in2 = 3;
__asm__ (
"movl %1, %%esi \n\t"
"movl %2, %%edi \n\t"
"movl %%edi, %0 \n\t"
: "=a"(__out)
: "r" (__in1), "r" (__in2));
printf("cr0: %d\n", __out);
}
int main(int argc, char *argv[])
{
att_asm_p();
att_asm_mov();
return 0;
}