Note that there are some explanatory texts on larger screens.

plurals
  1. POUnderstand the assembly code generated by a simple C program
    primarykey
    data
    text
    <p>I am trying to understand the assembly level code for a simple C program by inspecting it with gdb's disassembler.</p> <p>Following is the C code:</p> <pre><code>#include &lt;stdio.h&gt; void function(int a, int b, int c) { char buffer1[5]; char buffer2[10]; } void main() { function(1,2,3); } </code></pre> <p>Following is the disassembly code for both <code>main</code> and <code>function</code></p> <pre><code>gdb) disass main Dump of assembler code for function main: 0x08048428 &lt;main+0&gt;: push %ebp 0x08048429 &lt;main+1&gt;: mov %esp,%ebp 0x0804842b &lt;main+3&gt;: and $0xfffffff0,%esp 0x0804842e &lt;main+6&gt;: sub $0x10,%esp 0x08048431 &lt;main+9&gt;: movl $0x3,0x8(%esp) 0x08048439 &lt;main+17&gt;: movl $0x2,0x4(%esp) 0x08048441 &lt;main+25&gt;: movl $0x1,(%esp) 0x08048448 &lt;main+32&gt;: call 0x8048404 &lt;function&gt; 0x0804844d &lt;main+37&gt;: leave 0x0804844e &lt;main+38&gt;: ret End of assembler dump. (gdb) disass function Dump of assembler code for function function: 0x08048404 &lt;function+0&gt;: push %ebp 0x08048405 &lt;function+1&gt;: mov %esp,%ebp 0x08048407 &lt;function+3&gt;: sub $0x28,%esp 0x0804840a &lt;function+6&gt;: mov %gs:0x14,%eax 0x08048410 &lt;function+12&gt;: mov %eax,-0xc(%ebp) 0x08048413 &lt;function+15&gt;: xor %eax,%eax 0x08048415 &lt;function+17&gt;: mov -0xc(%ebp),%eax 0x08048418 &lt;function+20&gt;: xor %gs:0x14,%eax 0x0804841f &lt;function+27&gt;: je 0x8048426 &lt;function+34&gt; 0x08048421 &lt;function+29&gt;: call 0x8048340 &lt;__stack_chk_fail@plt&gt; 0x08048426 &lt;function+34&gt;: leave 0x08048427 &lt;function+35&gt;: ret End of assembler dump. </code></pre> <p>I am seeking answers for following things :</p> <ol> <li>how the addressing is working , I mean (main+0) , (main+1), (main+3)</li> <li>In the main, why is $0xfffffff0,%esp being used</li> <li>In the function, why is %gs:0x14,%eax , %eax,-0xc(%ebp) being used.</li> <li>If someone can explain , step by step happening, that will be greatly appreciated.</li> </ol>
    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