Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to figure out what this function, func_4, does, could someone help me wit

ID: 3595288 • Letter: I

Question

I need to figure out what this function, func_4, does, could someone help me with interpreting the assembly code?

0x0000000000401117 <+0>:   push %rbx

   0x0000000000401118 <+1>:   mov %edx,%eax

   0x000000000040111a <+3>:   sub %esi,%eax

   0x000000000040111c <+5>:   mov %eax,%ebx

   0x000000000040111e <+7>:   shr $0x1f,%ebx

   0x0000000000401121 <+10>:   add %ebx,%eax

   0x0000000000401123 <+12>:   sar %eax

   0x0000000000401125 <+14>:   lea (%rax,%rsi,1),%ebx

   0x0000000000401128 <+17>:   cmp %edi,%ebx

   0x000000000040112a <+19>:   jle 0x401138 <func4+33>

   0x000000000040112c <+21>:   lea -0x1(%rbx),%edx

   0x000000000040112f <+24>:   callq 0x401117 <func4>

   0x0000000000401134 <+29>:   add %ebx,%eax

   0x0000000000401136 <+31>:   jmp 0x401148 <func4+49>

   0x0000000000401138 <+33>:   mov %ebx,%eax

   0x000000000040113a <+35>:   cmp %edi,%ebx

   0x000000000040113c <+37>:   jge 0x401148 <func4+49>

   0x000000000040113e <+39>:   lea 0x1(%rbx),%esi

   0x0000000000401141 <+42>:   callq 0x401117 <func4>

   0x0000000000401146 <+47>:   add %ebx,%eax

=> 0x0000000000401148 <+49>:   pop %rbx

   0x0000000000401149 <+50>:   retq

Explanation / Answer

0x0000000000401128 <+17>:   cmp %edi,%ebx

0x000000000040112a <+19>:   jle 0x401138 <func4+33>

This means we jump to func4+33 if ebx <= edi (if 7 <= x) Since I have no idea what x is, let's assume it's greater than 7 and not jump.