You are viewing a single comment's thread. Return to all comments →
To show how compiler view things:
void printMax(int a, int b, int c, int d){ int max = a; if(b > max){ max = b; } if(c > max){ max = c; } if(d > max){ max = d; } printf("%d\n", max); } void printMaxTwo(int a, int b, int c, int d){ printf("%d\n", ((a>= b && a >= c && a >= d)?a:(b > a && b > c && b > d)?b:(c > a && c > b && c > d)?c:d)); } void printMaxThree(int a, int b, int c, int d){ if(a >= b && a >= c && a >= d){ printf("%d\n", a); }else if(b > a && b > c && b > d){ printf("%d\n, b"); }else if(c > a && c > b && c > d){ printf("%d\n", c); }else{ printf("%d\n", d); } }
Here is the assembly generated by the compiler for the first one:
0x401460 push %ebp 0x401461 mov %esp,%ebp 0x401463 sub $0x28,%esp 0x401466 mov 0x8(%ebp),%eax 0x401469 mov %eax,-0xc(%ebp) 0x40146c mov 0xc(%ebp),%eax 0x40146f cmp -0xc(%ebp),%eax 0x401472 jle 0x40147a <printMax+26> 0x401474 mov 0xc(%ebp),%eax 0x401477 mov %eax,-0xc(%ebp) 0x40147a mov 0x10(%ebp),%eax 0x40147d cmp -0xc(%ebp),%eax 0x401480 jle 0x401488 <printMax+40> 0x401482 mov 0x10(%ebp),%eax 0x401485 mov %eax,-0xc(%ebp) 0x401488 mov 0x14(%ebp),%eax 0x40148b cmp -0xc(%ebp),%eax 0x40148e jle 0x401496 <printMax+54> 0x401490 mov 0x14(%ebp),%eax 0x401493 mov %eax,-0xc(%ebp) 0x401496 mov -0xc(%ebp),%eax 0x401499 mov %eax,0x4(%esp) 0x40149d movl $0x405064,(%esp) 0x4014a4 call 0x403bf0 <printf> 0x4014a9 nop 0x4014aa leave 0x4014ab ret
For the second one:
0x4014ac push %ebp 0x4014ad mov %esp,%ebp 0x4014af sub $0x18,%esp 0x4014b2 mov 0x8(%ebp),%eax 0x4014b5 cmp 0xc(%ebp),%eax 0x4014b8 jl 0x4014ca <printMaxTwo+30> 0x4014ba mov 0x8(%ebp),%eax 0x4014bd cmp 0x10(%ebp),%eax 0x4014c0 jl 0x4014ca <printMaxTwo+30> 0x4014c2 mov 0x8(%ebp),%eax 0x4014c5 cmp 0x14(%ebp),%eax 0x4014c8 jge 0x40150b <printMaxTwo+95> 0x4014ca mov 0xc(%ebp),%eax 0x4014cd cmp 0x8(%ebp),%eax 0x4014d0 jle 0x4014e2 <printMaxTwo+54> 0x4014d2 mov 0xc(%ebp),%eax 0x4014d5 cmp 0x10(%ebp),%eax 0x4014d8 jle 0x4014e2 <printMaxTwo+54> 0x4014da mov 0xc(%ebp),%eax 0x4014dd cmp 0x14(%ebp),%eax 0x4014e0 jg 0x401504 <printMaxTwo+88> 0x4014e2 mov 0x10(%ebp),%eax 0x4014e5 cmp 0x8(%ebp),%eax 0x4014e8 jle 0x4014ff <printMaxTwo+83> 0x4014ea mov 0x10(%ebp),%eax 0x4014ed cmp 0xc(%ebp),%eax 0x4014f0 jle 0x4014ff <printMaxTwo+83> 0x4014f2 mov 0x10(%ebp),%eax 0x4014f5 cmp 0x14(%ebp),%eax 0x4014f8 jle 0x4014ff <printMaxTwo+83> 0x4014fa mov 0x10(%ebp),%eax 0x4014fd jmp 0x401509 <printMaxTwo+93> 0x4014ff mov 0x14(%ebp),%eax 0x401502 jmp 0x401509 <printMaxTwo+93> 0x401504 mov 0xc(%ebp),%eax 0x401507 jmp 0x40150e <printMaxTwo+98> 0x401509 jmp 0x40150e <printMaxTwo+98> 0x40150b mov 0x8(%ebp),%eax 0x40150e mov %eax,0x4(%esp) 0x401512 movl $0x405064,(%esp) 0x401519 call 0x403bf0 <printf> 0x40151e nop 0x40151f leave 0x401520 ret
For the third one:
0x401521 push %ebp 0x401522 mov %esp,%ebp 0x401524 sub $0x18,%esp 0x401527 mov 0x8(%ebp),%eax 0x40152a cmp 0xc(%ebp),%eax 0x40152d jl 0x401554 <printMaxThree+51> 0x40152f mov 0x8(%ebp),%eax 0x401532 cmp 0x10(%ebp),%eax 0x401535 jl 0x401554 <printMaxThree+51> 0x401537 mov 0x8(%ebp),%eax 0x40153a cmp 0x14(%ebp),%eax 0x40153d jl 0x401554 <printMaxThree+51> 0x40153f mov 0x8(%ebp),%eax 0x401542 mov %eax,0x4(%esp) 0x401546 movl $0x405064,(%esp) 0x40154d call 0x403bf0 <printf> 0x401552 jmp 0x4015ba <printMaxThree+153> 0x401554 mov 0xc(%ebp),%eax 0x401557 cmp 0x8(%ebp),%eax 0x40155a jle 0x40157a <printMaxThree+89> 0x40155c mov 0xc(%ebp),%eax 0x40155f cmp 0x10(%ebp),%eax 0x401562 jle 0x40157a <printMaxThree+89> 0x401564 mov 0xc(%ebp),%eax 0x401567 cmp 0x14(%ebp),%eax 0x40156a jle 0x40157a <printMaxThree+89> 0x40156c movl $0x405068,(%esp) 0x401573 call 0x403bf0 <printf> 0x401578 jmp 0x4015ba <printMaxThree+153> 0x40157a mov 0x10(%ebp),%eax 0x40157d cmp 0x8(%ebp),%eax 0x401580 jle 0x4015a7 <printMaxThree+134> 0x401582 mov 0x10(%ebp),%eax 0x401585 cmp 0xc(%ebp),%eax 0x401588 jle 0x4015a7 <printMaxThree+134> 0x40158a mov 0x10(%ebp),%eax 0x40158d cmp 0x14(%ebp),%eax 0x401590 jle 0x4015a7 <printMaxThree+134> 0x401592 mov 0x10(%ebp),%eax 0x401595 mov %eax,0x4(%esp) 0x401599 movl $0x405064,(%esp) 0x4015a0 call 0x403bf0 <printf> 0x4015a5 jmp 0x4015ba <printMaxThree+153> 0x4015a7 mov 0x14(%ebp),%eax 0x4015aa mov %eax,0x4(%esp) 0x4015ae movl $0x405064,(%esp) 0x4015b5 call 0x403bf0 <printf> 0x4015ba nop 0x4015bb leave 0x4015bc ret
Seems like cookies are disabled on this browser, please enable them to open this website
Functions
You are viewing a single comment's thread. Return to all comments →
To show how compiler view things:
Here is the assembly generated by the compiler for the first one:
For the second one:
For the third one: