错误C2432在__asm的'第二个操作数'中非法引用16位数据 [英] Error C2432 illegal reference to 16-bit data in 'second operand' of __asm

查看:429
本文介绍了错误C2432在__asm的'第二个操作数'中非法引用16位数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio中,用C编译__asm时出现此错误。有人知道此代码有什么问题吗?我尝试了一切,但没有任何效果。我正在尝试在汇编中实现冒泡排序。

In Visual Studio, I get this error when I compile my __asm in C. Does anybody know what is wrong with this code? I tried everything, but nothing works. I am trying to implement the bubble sort in assembly.

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错误消息。答案是就在MS文档中(第一次出现在Google网站上)。

Google the error message. The answer is right there in MS's documentation (the first google hit).


非法引用标识符中的16位数据

illegal reference to 16-bit data in 'identifier'

A 16位寄存器用作索引或基址寄存器。编译器
不支持引用16位数据。在编译32位代码时,不能将16位寄存器用作
的索引或基址寄存器。

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位地址大小。但是第二段很清楚:它拒绝使用地址大小前缀来组装诸如 mov ax,[si] 之类的东西,因为忽略地址的upper16并不是

The first paragraph is a bit confusing, because it sounds like the problem is a 16bit operand size, rather than the 16bit address size. But the second paragraph makes it clear: it refuses to use the address-size prefix to assemble something like mov ax, [si], because ignoring the upper16 of an address is not a useful thing to ever do in inline asm.

他们认为,在编译时捕获此类输入错误/错误比发出崩溃代码要好。

They've decided it's better to catch typos / errors like that at compile time than to emit code that crashes.

可能只是将行更改为 movax,[tab] 。将地址存储在 esi 中不会获得任何收益,因为您没有对其进行修改。

Probably just change the line to mov ax, [tab]. You're not gaining anything from storing the address in esi, since you don't modify it.

这篇关于错误C2432在__asm的'第二个操作数'中非法引用16位数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆