gcd.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 <gcd>: 0: 55 push %rbp 1: 48 89 e5 mov %rsp,%rbp 4: 48 83 ec 10 sub $0x10,%rsp 8: 89 7d fc mov %edi,-0x4(%rbp) b: 89 75 f8 mov %esi,-0x8(%rbp) e: 83 7d f8 00 cmpl $0x0,-0x8(%rbp) 12: 75 05 jne 1914: 8b 45 fc mov -0x4(%rbp),%eax 17: eb 13 jmp 2c 19: 8b 45 fc mov -0x4(%rbp),%eax 1c: 99 cltd 1d: f7 7d f8 idivl -0x8(%rbp) 20: 8b 45 f8 mov -0x8(%rbp),%eax 23: 89 d6 mov %edx,%esi 25: 89 c7 mov %eax,%edi 27: e8 00 00 00 00 call 2c 2c: c9 leave 2d: c3 ret
gcd.c: int gcd(int a, int b) { if (b == 0) { return a; } else { gcd(b, a%b); } }
01-04 sets the stack and allocates space. 08-0b stores the arguements int a, int b on the stack.
0e-12 is where the first computation takes place. %rbp-8 has our `int b` arguement, and the cmpl instruction compares 0x0 with whatever long is on address %rbp-8
0e: 83 7d f8 00 cmpl $0x0,-0x8(%rbp) 12: 75 05 jne 19 14: 8b 45 fc mov -0x4(%rbp),%eax 17: eb 13 jmp 2c
1d: f7 7d f8 idivl -0x8(%rbp) 20: 8b 45 f8 mov -0x8(%rbp),%eax 23: 89 d6 mov %edx,%esi 25: 89 c7 mov %eax,%edi1d performs the `idivl` instruction, but before that it should be noted instructions 19-1c set the long to a double type with the `cltd` instruction. idivl instruction computes the quotient and remainder, the values are stored in %eax and %edx. since we only need remainder for the next iteration we set %esi to the value of %edx. the mov -0x8(%rbp),%eax is done to discard the quotient and get the value of `int b` from the %rbp we set in 0b, and with the parameters set for the gcd() function we call <gcd> again, and this is done until the program reaches instruction 14 and then leaves and returns from the function.