ENTER and LEAVE in Assembly?

前端 未结 3 1666
既然无缘
既然无缘 2020-12-28 14:37

I was reading The Art of Assembly Language (Randall Hyde, link to Amazon) and I tried out a console application in that book. It was a program that created a new co

3条回答
  •  旧时难觅i
    2020-12-28 15:33

    This is the setup for the stack frame (activation record) for the function. Internally it normally looks something like this:

    push( ebp );         // Save a copy of the old EBP value
    
    mov( esp, ebp );     // Get ptr to base of activation record into EBP
    
    sub( NumVars, esp ); // Allocate storage for local variables.
    

    Then when the stack frame is to be destroyed again, you have to do something along the following lines:

       mov( ebp, esp );    // Deallocate locals and clean up stack.
    
       pop( ebp );         // Restore pointer to caller's activation record.
    
       ret();              // Return to the caller.
    

    Here is a better explanation of it using HLA. Though it is well explained in the book you're reading, as I have that book too, and I've read the section explaining it.

提交回复
热议问题