TP Chaîne Construction Partie 2
Création du ficher operateurs.cpp
Question 1
/* Ce programme réalise diverses opérations manipulant
* 3 entiers prealablement initialises */
#include <iostream>
int main() {
//Déclaration et initialisation des variables
int a = 7, b = 1, c = 42;
//1er calcul
a = 2 * (1 + b * a) * b + 5 - c / 2;
cout << "valeur de 'a' apres calcul :" << a << endl;
//2eme serie d'operations
a++;
c--;
b += 332;
b *= 16;
b /=8;
b -= 12;
cout << "Valeur de a :" << a;
cout << "Valeur de b :" << b;
cout << "Valeur de c :" << c;
return 9;
}
Question 2 :
-
a ++
: Il faut additionner deux fois a -
c --
: Il faut soustraire deux fois c -
b +
: Il faut additionner b -
b *
: Il faut multiplier b -
b /
: Il faut diviser b -
b -
: Il faut soustraire b
Question 3 :
- Pour construire le fichier objet j'utilise les commandes :
g++ -g -E operateurs.cpp -o operateurs.ii
g++ -g -S operateurs.ii -o operateurs.s
g++ -g -c operateurs.s -o operateurs.o
g++ -g -o operateurs operateurs.o
Ou alors tout d'un coup
g++ -o bin/operateurs src/operateurs.cpp
Question 4 :
Execution du programme et visualisation Commande : ./operateurs
Question 5 :
Commande : objdump --disassemble --source ./obj/operateurs.o
a) Initialisation des variables
// Declaration et initialisation des variables
int a,b,c;
a = 7;
8: c7 45 fc 07 00 00 00 movl $0x7,-0x4(%rbp)
b = 1;
f: c7 45 f8 01 00 00 00 movl $0x1,-0x8(%rbp)
c = 42;
16: c7 45 f4 2a 00 00 00 movl $0x2a,-0xc(%rbp)
b) Instruction a++
a++;
6f: 83 45 fc 01 addl $0x1,-0x4(%rbp)
c) Instruction c--
c--;
73: 83 6d f4 01 subl $0x1,-0xc(%rbp)
d) Instruction b +=332
b += 332;
77: 81 45 f8 4c 01 00 00 addl $0x14c,-0x8(%rbp)
e) Instruction b -=12
b -= 12;
93: 83 6d f8 0c subl $0xc,-0x8(%rbp)
f) 3 Instructions cout
cout << "\nValeur de a : " << a << endl;
97: be 00 00 00 00 mov $0x0,%esi
9c: bf 00 00 00 00 mov $0x0,%edi
a1: e8 00 00 00 00 callq a6 <main+0xa6>
a6: 48 89 c2 mov %rax,%rdx
a9: 8b 45 fc mov -0x4(%rbp),%eax
ac: 89 c6 mov %eax,%esi
ae: 48 89 d7 mov %rdx,%rdi
b1: e8 00 00 00 00 callq b6 <main+0xb6>
b6: be 00 00 00 00 mov $0x0,%esi
bb: 48 89 c7 mov %rax,%rdi
be: e8 00 00 00 00 callq c3 <main+0xc3>
cout << "\nValeur de b : " << b << endl;
c3: be 00 00 00 00 mov $0x0,%esi
c8: bf 00 00 00 00 mov $0x0,%edi
cd: e8 00 00 00 00 callq d2 <main+0xd2>
d2: 48 89 c2 mov %rax,%rdx
d5: 8b 45 f8 mov -0x8(%rbp),%eax
d8: 89 c6 mov %eax,%esi
da: 48 89 d7 mov %rdx,%rdi
dd: e8 00 00 00 00 callq e2 <main+0xe2>
e2: be 00 00 00 00 mov $0x0,%esi
e7: 48 89 c7 mov %rax,%rdi
ea: e8 00 00 00 00 callq ef <main+0xef>
cout << "\nValeur de c : " << c << endl;
ef: be 00 00 00 00 mov $0x0,%esi
f4: bf 00 00 00 00 mov $0x0,%edi
f9: e8 00 00 00 00 callq fe <main+0xfe>
fe: 48 89 c2 mov %rax,%rdx
101: 8b 45 f4 mov -0xc(%rbp),%eax
104: 89 c6 mov %eax,%esi
106: 48 89 d7 mov %rdx,%rdi
109: e8 00 00 00 00 callq 10e <main+0x10e>
10e: be 00 00 00 00 mov $0x0,%esi
113: 48 89 c7 mov %rax,%rdi
116: e8 00 00 00 00 callq 11b <main+0x11b>
g) Instruction return9
return 9;
11b: b8 09 00 00 00 mov $0x9,%eax
}
120: c9 leaveq
121: c3 retq
h)
i)