简体   繁体   中英

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. 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! 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. If you use simply mov eax, [ebx + data1location], not mov eax, [ebx + offset data1location], it is compiled correctly. However, 'offset' is a legal keyword for MASM syntax that ought to be accepted by MS C++ compiler. But then "ebx +" is silently thrown away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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