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

查看:34
本文介绍了错误 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 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'

一个 16 位寄存器用作索引或基址寄存器.编译器不支持引用 16 位数据.16 位寄存器不能编译 32 位代码时用作索引或基址寄存器.

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.

可能只是将行更改为 mov ax, [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天全站免登陆