如果汇编程序中的CALLed代码块中没有return语句怎么办 [英] What if there is no return statement in a CALLed block of code in assembly programs

查看:76
本文介绍了如果汇编程序中的CALLed代码块中没有return语句怎么办的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我说"call"而不是跳转怎么办?由于未编写任何return语句,因此控制权只是传递到下面的下一行,还是在调用后仍返回到该行?

start:
     mov $0, %eax
     jmp two
one:
     mov $1, %eax
two:
     cmp %eax, $1
     call one
     mov $10, %eax

解决方案

您的直觉是正确的:函数返回后,控件仅传递到下一行.

在您的情况下,在call one之后,您的函数将跳到mov $1, %eax,然后继续下降到cmp %eax, $1,并像再次在call one那样以无限循环结束.

由于无限循环,您的函数最终将超出其内存限制,因为call命令将当前rip(指令指针)写入堆栈.最终,您将使堆栈溢出.

What happens if i say 'call ' instead of jump? Since there is no return statement written, does control just pass over to the next line below, or is it still returned to the line after the call?

start:
     mov $0, %eax
     jmp two
one:
     mov $1, %eax
two:
     cmp %eax, $1
     call one
     mov $10, %eax

解决方案

Your intuition is correct: the control just passes to the next line below after the function returns.

In your case, after call one, your function will jump to mov $1, %eax and then continue down to cmp %eax, $1 and end up in an infinite loop as you will call one again.

Beyond just an infinite loop, your function will eventually go beyond its memory constraints since a call command writes the current rip (instruction pointer) to the stack. Eventually, you'll overflow the stack.

这篇关于如果汇编程序中的CALLed代码块中没有return语句怎么办的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆