Inline Assembly Jump Error

后端 未结 3 421
渐次进展
渐次进展 2021-01-17 06:38

Why does this fail, once Masm reaches jmp?

struct gdt_entry
{
    unsigned short limit_low;
    unsigned short base_low;
    unsigned char base_middle;
    u         


        
3条回答
  •  醉梦人生
    2021-01-17 07:25

    You shifted the stack right out from under it - the ip used by ret is now pointing somewhere really wild

    [edit]

    You still clobber the stack - the same one used by VC. VC pushes more stuff onto the stack than just the return IP. Do a assembler-listing of the source & you'll see.

    A possibility is to copy the return-address off the stack before you make the changes, and at end to just jump to where it points.

    create a labeled dw to store the address:

    _asm {
        oldip dd ?      ;this is in cs
        pop eax         ;eip into eax
        push eax        ;leave stack as found
        mov oldip,eax    
        .
        ..your stuff
        .
        jmp far cs:[oldip]     
    }
    

    I may be missing something here, but by the looks of your code you are clobbering all the segment values except cs, thereby destroying all access to previously declared variables everywhere, as well as any return address etc placed on the stack by your program ... maybe that's what you want to do, jumping off to code somewhere else, orphaning your current program ...

    The above fragment should put you back at the instruction following the call to the function with the _asm stuff, but lord knows what's going to happen then.

提交回复
热议问题