title: What is the memory address of my code?
body: <p>Hi I am trying to find the memory address of where my data gets stored.</p>
  
  <p>This is the assembly code of the function.</p>
  
  <pre><code>   0x08048b20 &lt;+0&gt;:     push   %ebp
     0x08048b21 &lt;+1&gt;:     mov    %esp,%ebp
     0x08048b23 &lt;+3&gt;:     sub    $0x28,%esp
     0x08048b26 &lt;+6&gt;:     lea    -0x14(%ebp),%eax
     0x08048b29 &lt;+9&gt;:     mov    %eax,(%esp)
     0x08048b2c &lt;+12&gt;:    call   0x8048990 &lt;Gets&gt;
     0x08048b31 &lt;+17&gt;:    mov    $0x1,%eax
     0x08048b36 &lt;+22&gt;:    leave  
     0x08048b37 &lt;+23&gt;:    ret   
  </code></pre>
  
  <p>My data which is a string gets stored at -0x14(%ebp) - (pretty positive). And I know the return address should be at 4(%ebp). What I am trying to do is set the return address to point at my code. And I can't use assembly to do this. I need to know the exact memory location of my where my function starts (which I know it stored at -0x14(%ebp)). Can anyone help me on how to get the memory location of that position?</p>
  
  <p>The address on this line </p>
  
  <pre><code>0x08048b20 &lt;+0&gt;:     push   %ebp
  </code></pre>
  
  <p>The 0x08048b20 is the memory location for the function I am in, not %ebp right? My thinking is that if I get the memory location for %ebp, I can calculate the memory location of where my function starts.</p>
  
  <p>I am using gdb, and I don't know how to get the memory address of it?
  Please, any help would be appreciated.
  Thank you.</p>
  
  <p><strong>EDIT:</strong>
  When I am standing at line &lt;+6> in the assembly code, I print the values of %ebp and %esp, and they have an exact difference of 0x28 like they should. So I assumed that the address of %ebp is the value I get when I print it in gdb.</p>
  
  <p>However, when I subtract 0x14 from this value (0xbfffb5d8) to give 0xbfffb5c4; it doesn't know where to jump to. If I have stored my string (which is actually byte code of disassembled code) at -0x14(%ebp), and I want to run that code; shouldn't I be putting the return address to -0x14(%ebp) or am I thinking completely wrongly?</p>