Sunteți pe pagina 1din 12

Exemple de compilation

Merci à Laurent JEANPIERRE

ref :http://asm.sourceforge.net/resources.html#tutorials
Objectifs

Les buts de ce cours sont :


Etudier l’architecture x86
Comprendre le fonctionnement du mP
Écrire des applications plus performantes
Un long fleuve tranquille

Compilateur C
C
fichier

Code
assembleur

Assembleur

Code
objet
Linker
Code
executable
Chaîne de compilation

Compiler un langage de haut niveau (C)

gcc
gcc -S gcc -c gcc

Programme
Source C Assembleur Fichier Objet
Exécutable

as
gcc -c ld

gcc
Fichiers assembleurs de plusieurs processeurs différents

Un même exemple
coucou

Pour plusieurs compilateurs/processeurs


x86, Norme AT&T
x86, Norme Intel
Alpha
Solaris
Coucou Langage C

coucou.c :
#include <stdio.h>

int main(int argc, char** argv)


{
printf("Coucou\n");
}
gcc -S

Compilation : Source C Assembleur


gcc –b<machine> -S coucou.c
coucoux86, Norme AT&T

1 .file "coucou.c" 13 movl $0, %eax


2 .section .rodata 14 subl %eax, %esp
3 .LC0 : 15 subl $12, %esp
4 .string "Coucou\n" 16 pushl $.LC0
5 .text 17 call printf
6 .global main 18 addl $16, %esp
7 .type main, @function 19 leave
8 main : 20 ret
9 pushl %ebp 21 .size main, .-main
10 movl %esp, %ebp 22 .section .note .GNU-
11 subl $8, %esp stack, "", @progbits
12 andl $-16, %esp 23 .ident "GCC: (GNU)
3.3.2 20031022"
coucou x86, Norme Intel

1 .file " coucou.c " 13 and %esp, -16


2 .intel_syntax 14 mov %eax, 0
3 .section .rodata 15 sub %esp, %eax
4 .LC0 : 16 sub %esp, 12
5 .string "Coucou\n" 17 push OFFSET FLAT :
6 .text .LC0
7 .global main 18 call printf
8 .type main, @function 19 add %esp, 16
9 main : 20 leave
10 push %ebp 21 ret
11 mov %ebp, %esp 22 .size main, .-main
12 sub %esp, 8 23 .section .note .GNU-
stack, "", @progbits
24 .ident "GCC: (GNU)
3.3.2 20031022"
coucou Solaris

1 .file "hello.c" 14 save %sp,¡112,%sp


2 gcc2_compiled.: 15 !#PROLOGUE# 1
3 .section ".rodata" 16 sethi %hi (.LLC0),
4 .align 8 %o1
5 .LLC0 : 17 or %o1,%lo (.LLC0),
6 .asciz "coucou" %o0
7 .section ".text" 18 call printf, 0
8 .align 4 19 nop
9 .global main 20 .LL1 :
10 .type main, #function 21 ret
11 .proc 020 22 restore
12 main : 23 .LLfe1 :
13 !#PROLOGUE# 0 24 .size main, .LLfe1-
main
25 .ident "GCC: (GNU)
2.7.2.1.f.1"
Coucou Langage C avec DEVC++

dans Options du projet/Fichiers/Surcharge :


$(CPP) -c main.c -o main.o $(CXXFLAGS) -Wa,-al,-ah,-as,-L >$@.lst

info : http://sourceforge.net/forum/message.php?msg_id=3414372
editer main.o.lst


14 0000 55 push ebp
15 0001 89E5 mov ebp, esp
16 0003 83EC08 sub esp, 8
17 0006 83E4F0 and esp, -16
18 0009 B8000000 mov eax, 0
18 00
19 000e 83C00F add eax, 15
20 0011 83C00F add eax, 15
21 0014 C1E804 shr eax, 4
22 0017 C1E004 sal eax, 4
23 001a 8945FC mov DWORD PTR
[ebp-4], eax
24 001d 8B45FC mov eax, DWORD
PTR [ebp-4]
25 0020 E8000000 call __alloca

DDD

l'utilisation de DDD est très utile.

http://www.ibisc.fr/%7Edupont/SUPPORTS/DupontCours/SiteProg/ddd/ddd.
pdf
http://www.dil.univ-mrs.fr/~garreta/generique/autres/UtiliserDDD.html

S-ar putea să vă placă și