简体   繁体   中英

Assembly - Why this CALL function doesn't work?

I don't understand why CALL function in this code doesn't work:

#include<stdio.h>

void main() {

    __asm {

        jmp L1

        L2:
        mov eax, 8
        ret

        L1:
        call L2
    }
}

If i debug the code step by step, the line 'call L1' is not processed, and program directly skips to the end. What is wrong? I'm working on VisualStudio2015 with Intel 32-bit registers.

The problem
You've stumbled on the difference between step over F10 and step into F11 .

When you use (the default) step over , call appears to be ignored.
You need to step into the code and then the debugger will behave as you'd expect.

Step over
The way this works with step over is that the debugger sets a breakpoint on the next instruction, halts there and moves the breakpoint to the next instruction again.
Step over knows about (conditional) jumps and accounts for that, but disregards (steps over) call statements; it interprets a call as a jump to another subroutine and 'assumes' you want to stay within the current context.
These automatic breakpoints are ephemeral, unlike manual breakpoints which persist until you cancel them.

Step into
Step into does the same, but also sets a breakpoint at every call destination; in effect leading you deep into the woods traversing every subroutine.

Step out
If you've stepped too deep 'into' a subroutine Visual Studio allows you to step out using Shift F11 ; this will take you back to the next instruction after the originating call.
Some other debuggers name this feature "run until return".

Debugging high level code
When the debugger is handling higher language source code (eg C) it keeps a list of target addresses for every line of source code. It will plan its breakpoints per line of source code.
Other than the fact that every line of high level code translates to zero or more lines of assembly it works the same as stepping through raw assembly code.

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