This question very famous ,The same answer i found everywhere that no of instruction is different
But i am unable to proof it ...can any one help ....if i am missing some thing ...
i generated assembly of a c program by disabling optimization and tried to compare it but found for both it is generating same instruction.
small test code name test.c
int main (){
int a = 0;
int x = 0;
int i = 0;
i = ++x;
i = x + 1; }
then generated assembly instruction and compared for both
by using this command
gcc -O0 -c -g -Wa,-a,-ad test.c > test.asm
O0 i added to disable optimization
and i got assembly output in test.asm please see the code part for x++ and x+1
2:test.c **** int main ()
3:test.c **** {
9 .loc 1 3 0
10 .cfi_startproc
11 0000 55 pushl %ebp
12 .LCFI0:
13 .cfi_def_cfa_offset 8
14 .cfi_offset 5, -8
15 0001 89E5 movl %esp, %ebp
16 .LCFI1:
17 .cfi_def_cfa_register 5
18 0003 83EC10 subl $16, %esp
4:test.c **** int a = 0;
19 .loc 1 4 0
20 0006 C745F400 movl $0, -12(%ebp)
20 000000
5:test.c **** int x = 0;
21 .loc 1 5 0
22 000d C745F800 movl $0, -8(%ebp)
22 000000
6:test.c **** int i = 0;
23 .loc 1 6 0
24 0014 C745FC00 movl $0, -4(%ebp)
24 000000
7:test.c ****
8:test.c **** i = ++x;
25 .loc 1 8 0
26 001b 8345F801 addl $1, -8(%ebp) /* observe here */
27 001f 8B45F8 movl -8(%ebp), %eax
28 0022 8945FC movl %eax, -4(%ebp)
9:test.c ****
10:test.c **** i = x + 1;
29 .loc 1 10 0
30 0025 8B45F8 movl -8(%ebp), %eax /* observe here */
31 0028 83C001 addl $1, %eax
32 002b 8945FC movl %eax, -4(%ebp)
11:test.c ****
12:test.c **** }
can you find any difference in these block of instructions
Only 1 difference i found is no of times it access the different register is different.
% ebp and %aeax registers
please help to wheater i left any option with gcc