简体   繁体   English

Visual C ++内联汇编器编译不正确

[英]Visual-C++ inline assembler compiled incorrectly

Recently I've asked the Community about difference of two offsets Visual-C++ inline assembler difference of two offsets and got reply quickly, thanks a lot. 最近,我向社区询问了两个偏移量的差异Visual-C ++内联汇编程序两个偏移量的差异,并很快得到了答复,非常感谢。 Now I've came into other problem, which is worse. 现在我遇到了另一个问题,那就是更糟。

I have an instruction like 我有一条指令

    ..naked...
    __asm{
    ...
    mov eax, dword ptr [ebx + offset data1]
    ...
    }

The real problem is that it gets compiled as 真正的问题是它被编译为

    mov eax, [offset data1]

No compiler warnings (/WAll mode) on this line, but code is changed and changed a lot - imagine, it got thrown ebx + part at all! 此行上没有编译器警告(/ WAll模式),但是代码已更改并且更改了很多-想象一下,它完全抛出了ebx +部分! Silently. 默默。 Is it a compiler bug or a feature? 是编译器错误还是功能? Maybe I have to specify some additional flag? 也许我必须指定一些其他标志?

Problem is with offset only, since 问题仅在于偏移量,因为

    mov eax, dword ptr [ebx + 0xconst]

is compiled correctly. 正确编译。

Yes, I can get around with code 是的,我可以解决代码

    mov eax, offset data1
    add eax, ebx
    mov eax, [eax]

But there's a lot of code to be changed then. 但是那时有很多代码需要更改。 What bothers me is absence of any warnings; 困扰我的是没有任何警告。

Finally, I have found an answer on MSDN forum. 最后,我在MSDN论坛上找到了答案。 If you use simply mov eax, [ebx + data1location], not mov eax, [ebx + offset data1location], it is compiled correctly. 如果仅使用mov eax [ebx + data1location],而不是mov eax [ebx + offset data1location],则会正确编译它。 However, 'offset' is a legal keyword for MASM syntax that ought to be accepted by MS C++ compiler. 但是,“偏移”是MASM语法的合法关键字,MS C ++编译器应接受。 But then "ebx +" is silently thrown away. 但是随后“ ebx +”被无声地丢弃了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM