What is the difference between retq and ret?

Consider the following program, which calculates the unsigned square of an argument:

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

This is compiled correctly as , but disassembled in

 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 ?

+5
source share
1 answer

In long (64-bit) mode, you return ( ret ) by selecting the fourth address from the stack in %rip .

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

Some tools, such as objdump -d , will call the first retq . This is just a name, the encoding of the commands is the same anyway ( C3 ).

+7
source

Source: https://habr.com/ru/post/1265142/


All Articles