schéma d’appel Linux 32 bits | schéma d’appel Linux 64 bits, paramètres entiers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
version 32 bits | version 64 bits | |
$ gcc -Wall -fno-asynchronous-unwind-tables -S prog.c -o prog.s $ cat prog.s .file "prog.c" .section .rodata .LC0: .string "%d\n" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp andl $-16, %esp # $-16 -> $0xfffffff0 subl $32, %esp movl $0, 28(%esp) movl $1, 28(%esp) jmp .L2 .L3: movl $.LC0, %eax movl 28(%esp), %edx movl %edx, 4(%esp) movl %eax, (%esp) call printf addl $1, 28(%esp) .L2: cmpl $10, 28(%esp) jle .L3 movl $0, %eax leave ret | $ gcc -Wall -fno-asynchronous-unwind-tables -S prog.c -o prog.s64 $ cat prog.s64 .file "prog.c" .section .rodata .LC0: .string "%d\n" .text .globl main .type main, @function main: pushq %rbp movq %rsp, %rbp subq $16, %rsp movl $0, -4(%rbp) movl $1, -4(%rbp) jmp .L2 .L3: movl -4(%rbp), %eax movl %eax, %esi movl $.LC0, %edi movl $0, %eax call printf addl $1, -4(%rbp) .L2: cmpl $10, -4(%rbp) jle .L3 movl $0, %eax leave ret |
version 32 bits | version 64 bits | |
.file "prog2.c" .section .rodata .LC0: .string "%d\n" .text .globl ecrire_entier .type ecrire_entier, @function ecrire_entier: pushl %ebp movl %esp, %ebp subl $40, %esp movl $.LC0, %eax movl 8(%ebp), %edx movl %edx, 4(%esp) movl %eax, (%esp) call printf movl %eax, -12(%ebp) movl -12(%ebp), %eax leave ret .globl main .type main, @function main: pushl %ebp movl %esp, %ebp andl $-16, %esp subl $32, %esp movl $0, 28(%esp) movl $1, 28(%esp) jmp .L3 .L4: movl 28(%esp), %eax movl %eax, (%esp) call ecrire_entier addl $1, 28(%esp) .L3: cmpl $10, 28(%esp) jle .L4 movl $0, %eax leave ret | .file "prog2.c" .section .rodata .LC0: .string "%d\n" .text .globl ecrire_entier .type ecrire_entier, @function ecrire_entier: pushq %rbp movq %rsp, %rbp subq $32, %rsp movl %edi, -20(%rbp) movl -20(%rbp), %eax movl %eax, %esi movl $.LC0, %edi movl $0, %eax call printf movl %eax, -4(%rbp) movl -4(%rbp), %eax leave ret .size ecrire_entier, .-ecrire_entier .globl main .type main, @function main: pushq %rbp movq %rsp, %rbp subq $16, %rsp movl $0, -4(%rbp) movl $1, -4(%rbp) jmp .L4 .L5: movl -4(%rbp), %eax movl %eax, %edi movl $0, %eax call ecrire_entier addl $1, -4(%rbp) .L4: cmpl $10, -4(%rbp) jle .L5 movl $0, %eax leave ret |
#include <stdio.h> void addition(int a,int b){ int c=a+b; printf("a+b=%d\n",c); } int main(void){ addition(1,1); return 0; }
#include <stdio.h> unsigned int multiplier(unsigned int a,unsigned int b){ unsigned int resultat; if(a==0) resultat=0; else if(a==1) resultat=b; else resultat=b+multiplier(a-1,b); return resultat; } int main(void){ unsigned int nombre; unsigned int a=10,b=20; nombre=multiplier(a,b); printf("resultat=%u\n",nombre); return 0; }
.section .rodata # ... .text .globl multiplier .type multiplier, @function multiplier: # ... .globl main .type main, @function main: # ...