如何解决函数调用和撤消功能
我知道call
/ ret
是在内部完成的,但是我想了解更多有关如何在汇编代码中进行翻译的知识。这是我到目前为止为call
准备的东西:
# Verbose way of doing `call func`
lea (%rip),%rax # get the current %rip. It cannot be directly accessed,so need to do a roundabout way
add $14,%rax # now that we have the previous %rip address in a register,add the offset to after the jmp
sub $8,%rsp # do pop %rax to move the value in the register onto the stack
mov %rax,(%rsp) # ... (doing it verbosely)
jmp func # jump to the function label
对于ret
:
func:
nop # pretend we did something in the function
# Verbose way of returning from a function,`ret`
mov (%rsp),%r11 # move the memory address stored at the top of the stack into %r11
add $8,%rsp # move the stack pointer back to where we started from
jmp %r11 # jump to the return address,now held in %r11
call
/ ret
的作用差不多吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。