1 Replies - 317 Views - Last Post: 22 November 2018 - 12:04 AM Rate Topic: -----

#1 georgekar   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 21-November 18

stack memory

Posted 21 November 2018 - 02:16 PM

hello,
while compiling the next c code:
int rem(int a, int B)/> {
return a % b;
}

to assembly:
rem(int, int):
        push    ebp
        mov     ebp, esp
        mov     eax, DWORD PTR [ebp+8]
        cdq
        idiv    DWORD PTR [ebp+12]
        mov     eax, edx
        pop     ebp
        ret

I understand that one int of size 4 bytes address is from ebp+8 to ebp+12 and the other is from ebp+12 to ebp+16
but I don't understand what there is from ebp to ebp+8? maybe the physical location of ebp?
I would like to hear from you.
Thanks

Is This A Good Question/Topic? 1
  • +

Replies To: stack memory

#2 Salem_c   User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 2360
  • View blog
  • Posts: 4,483
  • Joined: 30-May 10

Re: stack memory

Posted 22 November 2018 - 12:04 AM

https://en.wikipedia...stack#Structure
DWORD PTR [ebp] is the previous ebp (this creates what amounts to a linked list of frames up the stack).

DWORD PTR [ebp+4] is the return address back to the calling function.
Think of ret as being pop eip (the instruction pointer).
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1