Last active
December 27, 2015 13:59
-
-
Save theonewolf/7336756 to your computer and use it in GitHub Desktop.
SOSP'13 Question from Presenter (Xi Wang)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| disassemble mul |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ➜ sosp_question>make | |
| gcc question.c -o question -Wall -Werror -O0 -fno-inline -g | |
| gdb -x dis -batch ./question | |
| Dump of assembler code for function mul: | |
| 0x0000000000400544 <+0>: push %rbp | |
| 0x0000000000400545 <+1>: mov %rsp,%rbp | |
| 0x0000000000400548 <+4>: mov %edi,%edx | |
| 0x000000000040054a <+6>: mov %esi,%eax | |
| 0x000000000040054c <+8>: mov %dx,-0x14(%rbp) | |
| 0x0000000000400550 <+12>: mov %ax,-0x18(%rbp) | |
| 0x0000000000400554 <+16>: movzwl -0x14(%rbp),%edx | |
| 0x0000000000400558 <+20>: movzwl -0x18(%rbp),%eax | |
| 0x000000000040055c <+24>: imul %edx,%eax | |
| 0x000000000040055f <+27>: mov %eax,-0x4(%rbp) | |
| 0x0000000000400562 <+30>: mov -0x4(%rbp),%eax | |
| 0x0000000000400565 <+33>: pop %rbp | |
| 0x0000000000400566 <+34>: retq | |
| End of assembler dump. | |
| ./question | |
| Testing arguments: 0xffff 0xffff | |
| result (function return): 0xfffe0001 | |
| result (variable): 0xfffe0001 | |
| gcc question.c -o question -Wall -Werror -O1 -fno-inline -g | |
| gdb -x dis -batch ./question | |
| Dump of assembler code for function mul: | |
| 0x0000000000400564 <+0>: movzwl %di,%edi | |
| 0x0000000000400567 <+3>: movzwl %si,%esi | |
| 0x000000000040056a <+6>: mov %edi,%eax | |
| 0x000000000040056c <+8>: imul %esi,%eax | |
| 0x000000000040056f <+11>: retq | |
| End of assembler dump. | |
| ./question | |
| Testing arguments: 0xffff 0xffff | |
| result (function return): 0xfffe0001 | |
| result (variable): 0xfffe0001 | |
| gcc question.c -o question -Wall -Werror -O2 -fno-inline -g | |
| gdb -x dis -batch ./question | |
| Dump of assembler code for function mul: | |
| 0x00000000004005e0 <+0>: movzwl %di,%edi | |
| 0x00000000004005e3 <+3>: movzwl %si,%esi | |
| 0x00000000004005e6 <+6>: mov %edi,%eax | |
| 0x00000000004005e8 <+8>: imul %esi,%eax | |
| 0x00000000004005eb <+11>: retq | |
| End of assembler dump. | |
| ./question | |
| Testing arguments: 0xffff 0xffff | |
| result (function return): 0xfffe0001 | |
| result (variable): 0xfffe0001 | |
| gcc question.c -o question -Wall -Werror -O3 -fno-inline -g | |
| gdb -x dis -batch ./question | |
| Dump of assembler code for function mul: | |
| 0x00000000004005e0 <+0>: movzwl %di,%edi | |
| 0x00000000004005e3 <+3>: movzwl %si,%esi | |
| 0x00000000004005e6 <+6>: mov %edi,%eax | |
| 0x00000000004005e8 <+8>: imul %esi,%eax | |
| 0x00000000004005eb <+11>: retq | |
| End of assembler dump. | |
| ./question | |
| Testing arguments: 0xffff 0xffff | |
| result (function return): 0xfffe0001 | |
| result (variable): 0xfffe0001 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| default: | |
| gcc question.c -o question -Wall -Werror | |
| ./question |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdint.h> | |
| #include <stdlib.h> | |
| uint64_t mul(uint16_t a, uint16_t b) | |
| { | |
| uint32_t ret = a * b; | |
| return ret; | |
| } | |
| int main(int argc, char* argv[]) | |
| { | |
| uint64_t result = 0; | |
| fprintf(stdout, "Testing arguments: 0x%x 0x%x\n", 0xffff, 0xffff); | |
| result = mul(0xffff, 0xffff); | |
| fprintf(stdout, "result (function return): 0x%lx\n", mul(0xffff, 0xffff)); | |
| fprintf(stdout, "result (variable): 0x%lx\n", result); | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment