Last active
September 6, 2016 14:56
-
-
Save ApoorvaJ/7942dde540712eebb6ad76d7cf251957 to your computer and use it in GitHub Desktop.
This file contains 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
Program | |
======= | |
int __attribute__((cdecl / stdcall / fastcall)) foo(int a, int b) { | |
return (a < b) ? a : b; | |
} | |
int main() { | |
int i = foo(88, 99); | |
return i; | |
} | |
-------------------------------------------------------------------------------------------- | |
Command | |
======= | |
gcc -S -m32 main.c && cat main.s | |
-------------------------------------------------------------------------------------------- | |
// cdecl | |
// ===== | |
.file "main.c" | |
.text | |
.globl foo | |
.type foo, @function | |
foo: | |
pushl %ebp | |
movl %esp, %ebp | |
movl 8(%ebp), %eax | |
cmpl %eax, 12(%ebp) | |
cmovle 12(%ebp), %eax | |
popl %ebp | |
ret | |
.size foo, .-foo | |
.globl main | |
.type main, @function | |
main: | |
pushl %ebp | |
movl %esp, %ebp | |
subl $16, %esp | |
pushl $99 | |
pushl $88 | |
call foo | |
addl $8, %esp | |
movl %eax, -4(%ebp) | |
movl -4(%ebp), %eax | |
leave | |
ret | |
.size main, .-main | |
.ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609" | |
.section .note.GNU-stack,"",@progbits | |
-------------------------------------------------------------------------------------------- | |
// stdcall | |
// ======= | |
.file "main.c" | |
.text | |
.globl foo | |
.type foo, @function | |
foo: | |
pushl %ebp | |
movl %esp, %ebp | |
movl 8(%ebp), %eax | |
cmpl %eax, 12(%ebp) | |
cmovle 12(%ebp), %eax | |
popl %ebp | |
ret $8 | |
.size foo, .-foo | |
.globl main | |
.type main, @function | |
main: | |
pushl %ebp | |
movl %esp, %ebp | |
subl $16, %esp | |
pushl $99 | |
pushl $88 | |
call foo | |
movl %eax, -4(%ebp) | |
movl -4(%ebp), %eax | |
leave | |
ret | |
.size main, .-main | |
.ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609" | |
.section .note.GNU-stack,"",@progbits | |
-------------------------------------------------------------------------------------------- | |
// fastcall | |
// ======== | |
.file "main.c" | |
.text | |
.globl foo | |
.type foo, @function | |
foo: | |
pushl %ebp | |
movl %esp, %ebp | |
subl $8, %esp | |
movl %ecx, -4(%ebp) | |
movl %edx, -8(%ebp) | |
movl -4(%ebp), %eax | |
cmpl %eax, -8(%ebp) | |
cmovle -8(%ebp), %eax | |
leave | |
ret | |
.size foo, .-foo | |
.globl main | |
.type main, @function | |
main: | |
pushl %ebp | |
movl %esp, %ebp | |
subl $16, %esp | |
movl $99, %edx | |
movl $88, %ecx | |
call foo | |
movl %eax, -4(%ebp) | |
movl -4(%ebp), %eax | |
leave | |
ret | |
.size main, .-main | |
.ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609" | |
.section .note.GNU-stack,"",@progbits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment