int func1(int a, int b) { int x, y; x = a + b; y = 2*x - b; return x*y; } func1: pushl %ebp # setup stack movl %esp,%ebp movl 12(%ebp),%eax # get b => eax movl 8(%ebp),%ecx # get a => ecx addl %eax,%ecx # a + b => ecx (value of x) leal (%ecx,%ecx),%edx # 2*x => edx subl %eax,%edx # 2*x - b => edx (value of y) movl %ecx,%eax # move a+b (value of x) to eax imull %edx,%eax # x*y, store result in return register movl %ebp,%esp # cleanup stuck popl %ebp ret # return Dump of assembler code for function func1: 0x8048420 : push %ebp 0x8048421 : mov %esp,%ebp 0x8048423 : mov 0xc(%ebp),%eax 0x8048426 : mov 0x8(%ebp),%ecx 0x8048429 : add %eax,%ecx 0x804842b : lea (%ecx,%ecx,1),%edx 0x804842e : sub %eax,%edx 0x8048430 : mov %ecx,%eax 0x8048432 : imul %edx,%eax 0x8048435 : mov %ebp,%esp 0x8048437 : pop %ebp 0x8048438 : ret 0x8048439 : lea 0x0(%esi),%esi End of assembler dump. _______________________________________________________________________________ int func2(int a, int b) { if ( (a - b) > 0 ) return a; else return b; } func2: pushl %ebp # setup stack movl %esp,%ebp movl 8(%ebp),%ecx # read a movl 12(%ebp),%edx # read b movl %ecx,%eax # move a to eax subl %edx,%eax # a - b => eax testl %eax,%eax # test value of eax (a-b) jg .L19 # if a-b > 0 jump to L19 movl %edx,%eax # No. move b to return register jmp .L21 # jump to the end .p2align 4,,7 .L19: # Yes a-b > 0 movl %ecx,%eax # move a to return register .L21: movl %ebp,%esp # cleanup stack popl %ebp ret # return Dump of assembler code for function func2: 0x804843c : push %ebp 0x804843d : mov %esp,%ebp 0x804843f : mov 0x8(%ebp),%ecx 0x8048442 : mov 0xc(%ebp),%edx 0x8048445 : mov %ecx,%eax 0x8048447 : sub %edx,%eax 0x8048449 : test %eax,%eax 0x804844b : jg 0x8048451 0x804844d : mov %edx,%eax 0x804844f : jmp 0x8048453 0x8048451 : mov %ecx,%eax 0x8048453 : mov %ebp,%esp 0x8048455 : pop %ebp 0x8048456 : ret 0x8048457 : nop End of assembler dump. _______________________________________________________________________________ int func3(int a, int b) { int r; switch(a) { case 0: r = a; break; case 1: r = b; break; case 2: r = a+b; break; case 3: r = a-b; break; case 4: r = a*b; break; default: r = strlen(MY_STRING); break; } return r; } func3: pushl %ebp # setup stack stuff movl %esp,%ebp movl 8(%ebp),%eax # get a movl 12(%ebp),%edx # get b cmpl $4,%eax # compare value of a with 4 ja .L29 # jump to default if a > 4 jmp *.L30(,%eax,4) # go to jump table .p2align 4,,7 .section .rodata .align 4 .align 4 .L30: # jump table .long .L23 # case 0, return a directly .long .L25 .long .L26 .long .L27 .long .L28 .text .p2align 4,,7 .L25: # case 1 movl %edx,%eax # return b => edx jmp .L23 .p2align 4,,7 .L26: # case 2 addl %edx,%eax # return a+b => eax jmp .L23 .p2align 4,,7 .L27: # case 3 subl %edx,%eax # return a-b => eax jmp .L23 .p2align 4,,7 .L28: # case 4 imull %edx,%eax # return a*b => eax jmp .L23 .p2align 4,,7 .L29: # default: movl $13,%eax # return 13, strlen of MY_STRING .L23: movl %ebp,%esp popl %ebp ret Dump of assembler code for function func3: 0x8048458 : push %ebp 0x8048459 : mov %esp,%ebp 0x804845b : mov 0x8(%ebp),%eax 0x804845e : mov 0xc(%ebp),%edx 0x8048461 : cmp $0x4,%eax 0x8048464 : ja 0x8048485 0x8048466 : jmp *0x8048578(,%eax,4) 0x804846d : lea 0x0(%esi),%esi 0x8048470 : mov %edx,%eax 0x8048472 : jmp 0x804848a 0x8048474 : add %edx,%eax 0x8048476 : jmp 0x804848a 0x8048478 : sub %edx,%eax 0x804847a : jmp 0x804848a 0x804847c : lea 0x0(%esi,1),%esi 0x8048480 : imul %edx,%eax 0x8048483 : jmp 0x804848a 0x8048485 : mov $0xd,%eax 0x804848a : mov %ebp,%esp 0x804848c : pop %ebp 0x804848d : ret 0x804848e : mov %esi,%esi End of assembler dump.