我试图把汇编代码放到我的C函数中。 该功能的目的是存储在SRC地址值复制到DST地址:汇编代码C
void copy(int *dst, int *src);
我的实际问题的代码:
void copy(int *dst, int *src)
{
asm("mov %1, %2"
: /* no output */
: "i" (dst),
"i" (src)
: ""
);
}
给我的错误:
test.c: In function ‘copy’:
test.c:29: error: unknown register name ‘’ in ‘asm’
test.c:29: warning: asm operand 0 probably doesn’t match constraints
test.c:29: warning: asm operand 1 probably doesn’t match constraints
第29行是这一行:
asm("mov %1, %2"
编辑:
asm("mov %0, %1"
: "=m" (dst)
: "m" (dst),
"m" (src)
: ""
);
现在给我:
error: unknown register name ‘’ in ‘asm’
我不知道做什么用的最后一节做。
EDIT2
我读过,我不能MOV内存 - >内存,我需要使用的寄存器。而且我还需要使用AT & T语法,以便像“mov src,dest”一样。下面的代码编译,但不幸的是,由dst指向的地址中的值是0,而不是我放入由src指向的地址中的值。
asm("movl %1, %%eax \n\t"
"movl %%eax, %0 \n\t"
: "=m" (dst)
: "m" (dst),
"m" (src)
);
EDIT3
我就是这么做的(改变参数),它现在的作品:
void copy(int *dst, int *src, int n)
{
int a = *src;
int b = *dst;
asm("movl %1, %%eax\n"
"movl %%eax, %0\n"
: "=m" (b)
: "m" (a)
);
*src = a;
*dst = b;
}
,你有一个输入和一个输出。而且他们都不是我的中间值。一个''m''emory对象应该适用于两者。 – glglgl
这是什么架构? –
你使用什么编译器? – geoffspear