Created
October 9, 2014 00:44
-
-
Save bcho/4cbf474e6a925f65274c to your computer and use it in GitHub Desktop.
trick
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
| vimshell% ./sf | |
| !!!vimshell: exit 1 "./sf"!!! | |
| vimshell% |
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
| section .text | |
| global _start | |
| global foo | |
| global bar | |
| _start: | |
| call foo | |
| mov edx, eax | |
| mov eax, 1 | |
| mov ebx, edx | |
| int 80h | |
| foo: | |
| push rbp | |
| mov rbp, rsp | |
| mov edi, 1 | |
| call bar | |
| pop rbp | |
| ret | |
| bar: | |
| push rbp | |
| mov rbp, rsp | |
| mov eax, edi | |
| pop rbp | |
| ret |
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
| .file "stack_frame.c" | |
| .text | |
| .globl foo | |
| .type foo, @function | |
| foo: | |
| .LFB0: | |
| .cfi_startproc | |
| pushq %rbp | |
| .cfi_def_cfa_offset 16 | |
| .cfi_offset 6, -16 | |
| movq %rsp, %rbp | |
| .cfi_def_cfa_register 6 | |
| subq $16, %rsp | |
| movl %edi, -4(%rbp) | |
| movl %esi, -8(%rbp) | |
| cmpl $0, -8(%rbp) | |
| jne .L2 | |
| movl -4(%rbp), %eax | |
| jmp .L3 | |
| .L2: | |
| movl -8(%rbp), %eax | |
| leal -1(%rax), %edx | |
| movl -4(%rbp), %eax | |
| addl $1, %eax | |
| movl %edx, %esi | |
| movl %eax, %edi | |
| call bar | |
| .L3: | |
| leave | |
| .cfi_def_cfa 7, 8 | |
| ret | |
| .cfi_endproc | |
| .LFE0: | |
| .size foo, .-foo | |
| .globl bar | |
| .type bar, @function | |
| bar: | |
| .LFB1: | |
| .cfi_startproc | |
| pushq %rbp | |
| .cfi_def_cfa_offset 16 | |
| .cfi_offset 6, -16 | |
| movq %rsp, %rbp | |
| .cfi_def_cfa_register 6 | |
| subq $16, %rsp | |
| movl %edi, -4(%rbp) | |
| movl %esi, -8(%rbp) | |
| cmpl $0, -8(%rbp) | |
| jne .L5 | |
| movl -4(%rbp), %eax | |
| jmp .L6 | |
| .L5: | |
| movl -8(%rbp), %eax | |
| leal -1(%rax), %edx | |
| movl -4(%rbp), %eax | |
| addl $1, %eax | |
| movl %edx, %esi | |
| movl %eax, %edi | |
| call foo | |
| .L6: | |
| leave | |
| .cfi_def_cfa 7, 8 | |
| ret | |
| .cfi_endproc | |
| .LFE1: | |
| .size bar, .-bar | |
| .globl run | |
| .type run, @function | |
| run: | |
| .LFB2: | |
| .cfi_startproc | |
| pushq %rbp | |
| .cfi_def_cfa_offset 16 | |
| .cfi_offset 6, -16 | |
| movq %rsp, %rbp | |
| .cfi_def_cfa_register 6 | |
| subq $16, %rsp | |
| movl %edi, -4(%rbp) | |
| movl -4(%rbp), %eax | |
| movl %eax, %esi | |
| movl $0, %edi | |
| call foo | |
| leave | |
| .cfi_def_cfa 7, 8 | |
| ret | |
| .cfi_endproc | |
| .LFE2: | |
| .size run, .-run | |
| .ident "GCC: (GNU) 4.9.1 20140903 (prerelease)" | |
| .section .note.GNU-stack,"",@progbits |
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
| .file "test.c" | |
| .text | |
| .globl foo | |
| .type foo, @function | |
| foo: | |
| .LFB0: | |
| .cfi_startproc | |
| pushq %rbp | |
| .cfi_def_cfa_offset 16 | |
| .cfi_offset 6, -16 | |
| movq %rsp, %rbp | |
| .cfi_def_cfa_register 6 | |
| movl %edi, -4(%rbp) | |
| movl -4(%rbp), %eax | |
| popq %rbp | |
| .cfi_def_cfa 7, 8 | |
| ret | |
| .cfi_endproc | |
| .LFE0: | |
| .size foo, .-foo | |
| .globl main | |
| .type main, @function | |
| main: | |
| .LFB1: | |
| .cfi_startproc | |
| pushq %rbp | |
| .cfi_def_cfa_offset 16 | |
| .cfi_offset 6, -16 | |
| movq %rsp, %rbp | |
| .cfi_def_cfa_register 6 | |
| movl $1, %edi | |
| call foo | |
| popq %rbp | |
| .cfi_def_cfa 7, 8 | |
| ret | |
| .cfi_endproc | |
| .LFE1: | |
| .size main, .-main | |
| .ident "GCC: (GNU) 4.9.1 20140903 (prerelease)" | |
| .section .note.GNU-stack,"",@progbits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment