1 / 12

Exemple de compilation

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 m P Écrire des applications plus performantes. Un long fleuve tranquille.

chelsa
Télécharger la présentation

Exemple de compilation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Exemple de compilation Merci à Laurent JEANPIERRE ref :http://asm.sourceforge.net/resources.html#tutorials

  2. Objectifs • Les buts de ce cours sont : • Etudier l’architecture x86 • Comprendre le fonctionnement du mP • Écrire des applications plus performantes

  3. Un long fleuve tranquille Compilateur C C fichier Code assembleur Assembleur Code objet Linker Code executable

  4. Chaîne de compilation gcc gcc -S gcc -c gcc as ld gcc -c gcc • Compiler un langage de haut niveau (C) Source C Assembleur Fichier Objet Programme Exécutable

  5. 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

  6. Coucou Langage C gcc -S • coucou.c : #include <stdio.h> int main(int argc, char** argv) { printf("Coucou\n"); } • Compilation : • gcc –b<machine> -S coucou.c Source C Assembleur

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

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

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

  10. 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

  11. 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 …

  12. 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

More Related