如果汇编程序的 CALLed 代码块中没有 return 语句怎么办 [英] What if there is no return statement in a CALLed block of code in assembly programs
问题描述
如果我说呼叫"而不是跳转会发生什么?既然没有写return语句,是直接把控制权交给下面的下一行,还是调用后还是返回到该行?
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.
在你的情况下,在 call one
之后,你的函数将跳转到 mov $1, %eax
然后继续向下到 cmp %eax, $1
并以无限循环结束,因为您将再次调用一个
.
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.
除了无限循环之外,您的函数最终将超出其内存限制,因为 call
命令将当前的 rip
(指令指针)写入堆栈.最终,您将溢出堆栈.
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屋!