函数调用和撤消功能

问题描述

我知道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 (将#修改为@)