Note that there are some explanatory texts on larger screens.

plurals
  1. POAssembly operator AND
    primarykey
    data
    text
    <p>In order to continue this: <a href="https://stackoverflow.com/questions/19210032/debugging-c-program-int-declaration">Debugging C program (int declaration)</a> I decided to test more code and see how compiler reacts to it. So I decided to try this one to test local variables:</p> <pre><code>#include &lt;stdio.h&gt; main() { int a,b,c,d,e,f,g; a=0xbeef; b=0xdead; c=0x12; d=0x65; e=0xfed; f=0xaa; g=0xfaceb00c; a=a+b; printf("%d",a); } </code></pre> <p>Ok I did that int a,b,c... just to test the main's frame size and see the sub $0x10,%esp growing up, (I'm under linux so that is why maybe is sub), now to sub $0x30,%esp so here is the the gdb output with "disas main" command:</p> <pre><code> 0x0804841c &lt;+0&gt;: push %ebp 0x0804841d &lt;+1&gt;: mov %esp,%ebp 0x0804841f &lt;+3&gt;: and $0xfffffff0,%esp 0x08048422 &lt;+6&gt;: sub $0x30,%esp ;7 int vars 4-byte is 7*4=28. 30 is enough 0x08048425 &lt;+9&gt;: movl $0xbeef,0x14(%esp) 0x0804842d &lt;+17&gt;: movl $0xdead,0x18(%esp) 0x08048435 &lt;+25&gt;: movl $0x12,0x1c(%esp) 0x0804843d &lt;+33&gt;: movl $0x65,0x20(%esp) 0x08048445 &lt;+41&gt;: movl $0xfed,0x24(%esp) 0x0804844d &lt;+49&gt;: movl $0xaa,0x28(%esp) 0x08048455 &lt;+57&gt;: movl $0xfaceb00c,0x2c(%esp) 0x0804845d &lt;+65&gt;: mov 0x18(%esp),%eax 0x08048461 &lt;+69&gt;: add %eax,0x14(%esp) 0x08048465 &lt;+73&gt;: mov 0x14(%esp),%eax 0x08048469 &lt;+77&gt;: mov %eax,0x4(%esp) 0x0804846d &lt;+81&gt;: movl $0x8048510,(%esp) 0x08048474 &lt;+88&gt;: call 0x80482f0 &lt;printf@plt&gt; 0x08048479 &lt;+93&gt;: leave 0x0804847a &lt;+94&gt;: ret </code></pre> <p>This line: <code>0x0804841f &lt;+3&gt;:and $0xfffffff0,%esp</code> what is and operator and why is there a large number?</p> <p>And why the offset in movl commands isn't negative like: <code>movl $0xa,-0x4(%ebp)</code> So far I know is the AND is a logical operator like 1 and 1 is 1, 0 and 0 is 0, 1 and 0 is 0 etc... If it is the case, %esp has the ebp value that was the base frame address of who called the main function.</p> <p>can any of you explain why this is compiled like this?</p> <p>I think I'm missing something. Edit: I saw some "topics" on stackoverflow talking about this. Going to share: <a href="https://stackoverflow.com/questions/4175281/what-does-it-mean-to-align-the-stack">link1</a> <a href="https://stackoverflow.com/questions/4228261/understanding-the-purpose-of-some-assembly-statements">link2</a> <a href="https://stackoverflow.com/questions/4817473/understanding-stack-allocation-and-alignment">link3</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload