错误 C2432 非法引用 __asm 的 'second operand' 中的 16 位数据
Error C2432 illegal reference to 16-bit data in 'second operand' of __asm
在 Visual Studio 中,当我在 C 中编译 __asm 时出现此错误。有人知道这段代码有什么问题吗?我尝试了一切,但没有任何效果。我正在尝试在程序集中实现冒泡排序。
unsigned short i = 0;
unsigned short j = 0;
unsigned short max = short(N-2);
unsigned short tab[5];
tab[0] = 54;
tab[1] = 123;
tab[2] = 342;
tab[3] = 5436;
tab[4] = 1234;
unsigned short a = 0;
__asm {
loop1:
inc i
mov j, 0
mov si, tab
loop2:
mov ax, [si] // <- Error C2432 on this line
mov a, ax
inc j
mov ax, j
mov bx, max
cmp ax, bx
jz cdnloop2
loop loop2
cdnloop2:
mov ax, i
mov bx, max
cmp ax, bx
jz endof
loop loop1
endof :
}
Google 错误信息。答案是right there in MS's documentation(第一个google命中)。
illegal reference to 16-bit data in 'identifier'
A 16-bit register is used as an index or base register. The compiler
does not support referencing 16-bit data. 16-bit registers cannot be
used as index or base registers when compiling for 32-bit code.
第一段有点混乱,因为听起来问题是 16 位操作数大小,而不是 16 位地址大小。但是第二段说得很清楚:它拒绝使用 assemble 的地址大小前缀,例如 mov ax, [si]
,因为忽略地址的 upper16 在内联 asm 中从来没有用过。
他们决定在编译时捕获这样的拼写错误/错误比发出崩溃的代码更好。
可能只需将行更改为 mov ax, [tab]
。将地址存储在 esi
中不会有任何好处,因为您没有修改它。
在 Visual Studio 中,当我在 C 中编译 __asm 时出现此错误。有人知道这段代码有什么问题吗?我尝试了一切,但没有任何效果。我正在尝试在程序集中实现冒泡排序。
unsigned short i = 0;
unsigned short j = 0;
unsigned short max = short(N-2);
unsigned short tab[5];
tab[0] = 54;
tab[1] = 123;
tab[2] = 342;
tab[3] = 5436;
tab[4] = 1234;
unsigned short a = 0;
__asm {
loop1:
inc i
mov j, 0
mov si, tab
loop2:
mov ax, [si] // <- Error C2432 on this line
mov a, ax
inc j
mov ax, j
mov bx, max
cmp ax, bx
jz cdnloop2
loop loop2
cdnloop2:
mov ax, i
mov bx, max
cmp ax, bx
jz endof
loop loop1
endof :
}
Google 错误信息。答案是right there in MS's documentation(第一个google命中)。
illegal reference to 16-bit data in 'identifier'
A 16-bit register is used as an index or base register. The compiler does not support referencing 16-bit data. 16-bit registers cannot be used as index or base registers when compiling for 32-bit code.
第一段有点混乱,因为听起来问题是 16 位操作数大小,而不是 16 位地址大小。但是第二段说得很清楚:它拒绝使用 assemble 的地址大小前缀,例如 mov ax, [si]
,因为忽略地址的 upper16 在内联 asm 中从来没有用过。
他们决定在编译时捕获这样的拼写错误/错误比发出崩溃的代码更好。
可能只需将行更改为 mov ax, [tab]
。将地址存储在 esi
中不会有任何好处,因为您没有修改它。