简体   繁体   English

装配 - 为什么这个CALL功能不起作用?

[英]Assembly - Why this CALL function doesn't work?

I don't understand why CALL function in this code doesn't work: 我不明白为什么这段代码中的CALL函数不起作用:

#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. 如果我逐步调试代码,则不会处理“调用L1”行,程序会直接跳到最后。 What is wrong? 怎么了? I'm working on VisualStudio2015 with Intel 32-bit registers. 我正在使用带有Intel 32位寄存器的VisualStudio2015。

The problem 问题
You've stumbled on the difference between step over F10 and step into F11 . 你偶然发现了step over F10step into F11之间的区别

When you use (the default) step over , call appears to be ignored. 当您使用(默认) step overcall似乎被忽略。
You need to step into the code and then the debugger will behave as you'd expect. 您需要step into代码,然后调试器将按照您的预期运行。

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工作方式是调试器在下一条指令上设置一个断点,在那里停止并再次将断点移动到下一条指令。
Step over knows about (conditional) jumps and accounts for that, but disregards (steps over) call statements; Step over了解(条件)跳转和帐户,但忽略(步骤)调用语句; it interprets a call as a jump to another subroutine and 'assumes' you want to stay within the current context. 它将一个call解释为跳转到另一个子例程,并“假定”您希望保持在当前上下文中。
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; Step into也是如此,但也在每个呼叫目的地设置一个断点; 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 ; 如果你已经深入'进入'一个子程序, Visual Studio允许你使用Shift F11 步进 ; this will take you back to the next instruction after the originating call. 这将带您回到始发呼叫后的下一条指令。
Some other debuggers name this feature "run until return". 其他一些调试器将此功能命名为“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. 当调试器处理更高级的语言源代码(例如C)时,它会为每行源代码保留一个目标地址列表。 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. 除了每行高级代码转换为零行或多行汇编之外,它的工作原理与逐步执行原始汇编代码相同。

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

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