linux - 汇编:为什么跳转到通过 ret 返回的标签会导致段错误?

标签 linux assembly nasm yasm

Linux Assembly Tutorial状态:

there is one very important thing to remember: If you are planning to return from a procedure (with the RET instruction), don't jump to it! As in "never!" Doing that will cause a segmentation fault on Linux (which is OK – all your program does is terminate), but in DOS it may blow up in your face with various degrees of terribleness.

但我不明白为什么会导致段错误。听起来就像从函数返回一样。

我有一种情况需要实现逻辑“如果 X 发生,调用过程 A。否则,调用过程 B。”除了像袋鼠一样跳来跳去编意大利面代码,还有什么办法吗?

最佳答案

因为 CALL 将当前指令地址压入堆栈,而 RET 将其拉出以返回调用点。 JMP(及相关指令)不会将任何内容压入堆栈。

关于linux - 汇编:为什么跳转到通过 ret 返回的标签会导致段错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9847706/

相关文章:

php - 对某些 CMS 或框架的多个实例使用符号链接(symbolic link)

python - Python中如何根据占用的端口获取一个socket fd?

java - 如何将 javas "out.println"转换为汇编?不使用 printf

linux - 无法运行与 libc 链接的可执行文件

c 套接字文件传输,服务器不打开现有文件

assembly - ARM cortex m4 DSP 代码上的快速 1 位透明 blit

c++ - 为什么 GCC 聚合初始化数组首先用零填充整个事物,包括非零元素?

c - 在 ASM 函数中访问在堆栈上传递的参数

linux - 如何在 nasm 中包含调试信息?

linux - 复制相同的 BeagleBone Black 设置