0

I'm looking at some assembly stuff. So, pushl bar is the same as subl $4, %esp movl bar, ($esp).

Few questions:

1) What is special about the %esp register?

2) What does the parenthesis around the register mean?

3) pushl bar would meaning having bar on top of the stack, right? So what is happening when I do subl $4? Does that mean I am creating am empty space on top of the stack for me to move bar into?

Strawberry
  • 66,024
  • 56
  • 149
  • 197

1 Answers1

1
  1. ESP is the stack pointer - it always points to the "top" of the stack

  2. The brackets mean "the memory pointed at by" ESP rather than the ESP register itself

  3. You are moving the stack pointer down by four bytes (the stack grows downwards in most implementations - pushing something onto the "top" of the stack means storing it at a lower memory address)
Matt
  • 569
  • 1
  • 4
  • 16
  • I imagine a stack where the bottom is the first item to be pushed. You said, "You are moving the stack pointer down by four bytes", shouldn't I be moving up 4 bytes so then I can add another element to the top of the stack? Or am I imagining this wrong? – Strawberry May 23 '11 at 08:52
  • The way the C call stack works is that the _top_ is the first item to be pushed, and the stack grows downwards as you put more items onto it. See for instance http://stackoverflow.com/questions/1677415/does-stack-grow-upward-or-downward – Matt May 23 '11 at 09:12
  • %esp points to the newest item pushed in the stack at all times correcT? – Strawberry May 23 '11 at 09:34