Skip to content

Instantly share code, notes, and snippets.

@ApoorvaJ
Last active September 6, 2016 14:56
Show Gist options
  • Save ApoorvaJ/7942dde540712eebb6ad76d7cf251957 to your computer and use it in GitHub Desktop.
Save ApoorvaJ/7942dde540712eebb6ad76d7cf251957 to your computer and use it in GitHub Desktop.
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