I am trying to learn more about x86 build. I have a secret function assembly code. All I know about this function is that it should return an integer and has an integer as an argument:
int mystery(int n){}
Assembly for this function
0000000000400526 <mystery_util>:
400526: 89 f8 mov %edi,%eax
400528: d1 e8 shr %eax
40052a: 83 e7 01 and $0x1,%edi
40052d: 01 f8 add %edi,%eax
40052f: c3 retq
0000000000400530 <mystery>:
400530: 89 f8 mov %edi,%eax
400532: 8d 3c fd 00 00 00 00 lea 0x0(,%rdi,8),%edi
400539: 29 c7 sub %eax,%edi
40053b: 83 c7 04 add $0x4,%edi
40053e: e8 e3 ff ff ff callq 400526 <mystery_util>
400543: f3 c3 repz retq
I don’t understand how to write this as a function of C. If there is callq, does this mean that there are two different functions?
I am trying to write this in a single function that returns an integer. I see how it can return a boolean, but can there be a way to return an integer?
source
share