系统相关
首页 > 系统相关> > linux – 汇编:为什么跳转到通过ret返回的标签会导致分段错误?

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

作者:互联网

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,assembly,nasm,yasm
来源: https://codeday.me/bug/20190613/1233803.html