0

In one of my class examples, a function that takes in int parameter integer begins like:

recursive_sum:
    push    ebp
    mov     ebp, esp     ;set EBP=ESP
    pusha                ;save all registers(probably overkill)
    mov     ebx, [ebp+8] ;ebx=integer(parameter #1)

But in a different class example, a function that takes in int parameter num begins like:

f:
    enter 8,0    ;num in [ebp+8] ,local var x, sum in [ebp-4],[ebp-8]
    push  ebx
    push  ecx
    push  edx
    mov   eax, [ebp+8]    ;eax=num

In what case would one need the mov ebp, esp instruction? Please explain in terms of C, java, or through an example. And I am not looking for a basic definition of the ESP register

Fatcow808
  • 11
  • 2
  • You'll need to post whole functions. We can't tell if that's important in the part of them that you cut off. – Joseph Sible-Reinstate Monica Apr 25 '20 at 05:39
  • 3
    C compilers set up a stack frame for you; this is not explainable in terms of C. You have to understand what a frame pointer is, and that `enter` sets one up the same way that `push ebp` / `mov ebp, esp` does. https://www.felixcloutier.com/x86/enter – Peter Cordes Apr 25 '20 at 05:44
  • @PeterCordes Now it all makes more sense to me! I understood how the stack works, it turns out I just had the wrong idea about the `enter` instruction. Thank you! – Fatcow808 Apr 25 '20 at 09:16

0 Answers0