What is the difference between retq and ret?

房东的猫 提交于 2019-12-21 03:26:17

问题


Let's consider the following program, which computes an unsigned square of the argument:

.global foo
.text
foo:
    mov %rdi, %rax
    mul %rdi
    ret

This is properly compiled by as, but disassembles to

0000000000000000 <foo>:
   0:   48 89 f8                mov    %rdi,%rax
   3:   48 f7 e7                mul    %rdi
   6:   c3                      retq   

Is there any difference between ret and retq?


回答1:


In long (64-bit) mode, you return (ret) by popping a quadword address from the stack to %rip.

In 32-bit mode, you return (ret) by popping a dword address from the stack to %eip.

Some tools like objdump -d call the first one retq. It's just a name, the instruction encoding is the same either way (C3).



来源:https://stackoverflow.com/questions/42653095/what-is-the-difference-between-retq-and-ret

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!