使用GCC英特尔程序集时出错:+的操作数(.text和UND部分)无效



我正在编写内联程序集,遇到了一个不知道如何修复的错误。这部分代码会引发一个错误。它应该加上";i〃;至";源";以及";阵列";地址,并将字节的内容复制到"0";源";至";阵列";。

int main()
{
char* _source = new char [1];
_source[0] = 1;
char* array = new char[1];
unsigned int i = 0;
__asm volatile (
"mov eax, $[source] nt"
"add eax, $[i] nt"
"mov bh, [eax] nt"
"mov ecx, $[array] nt"
"add ecx, $[i] nt"
"mov [ecx], bh nt"
:
: "r" "source" (_source), "r" "array" (array), "r" "i" (i)
: "eax", "bh", "ecx", "memory"
);
}

此代码使用gcc执行。

gcc -m32 -masm=intel -o test.cpp 

显示的错误

C:UsersgeishAppDataLocalTempccMCDck3.s:34: Error: invalid operands (.text and *UND* sections) for `+'
C:UsersgeishAppDataLocalTempccMCDck3.s:35: Error: invalid operands (.text and *UND* sections) for `+'
C:UsersgeishAppDataLocalTempccMCDck3.s:37: Error: invalid operands (.text and *UND* sections) for `+'
C:UsersuserAppDataLocalTempccMCDck3.s:38: Error: invalid operands (.text and *UND* sections) for `+'
C:UsersuserAppDataLocalTempccMCDck3.s:56: Error: invalid operands (.text and *UND* sections) for `+'
C:UsersuserAppDataLocalTempccMCDck3.s:57: Error: invalid operands (.text and *UND* sections) for `+'
C:UsersuserAppDataLocalTempccMCDck3.s:59: Error: invalid operands (.text and *UND* sections) for `+'
C:UsersuserAppDataLocalTempccMCDck3.s:60: Error: invalid operands (.text and *UND* sections) for `+'

您对命名操作数的使用在某些方面是错误的。应该将操作数指定为:[source] "r" (_source),而不是"r" "source" (_source),其中[source]指定其名称,_source是C变量,"r"是要使用的常量。您应该使用%[source]而不是$[source]访问操作数。

最新更新