{"id":2175,"date":"2018-12-22T23:07:46","date_gmt":"2018-12-22T23:07:46","guid":{"rendered":"http:\/\/www.max-sperling.bplaced.net\/?p=2175"},"modified":"2024-02-16T10:16:41","modified_gmt":"2024-02-16T10:16:41","slug":"assembly-of-compiled-c-code-example","status":"publish","type":"post","link":"http:\/\/www.max-sperling.bplaced.net\/?p=2175","title":{"rendered":"Assembly of compiled C-Code (Example)"},"content":{"rendered":"<pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">\r\n(gdb) list\r\n1       #include &lt;stdio.h&gt;\r\n2\r\n3       int main()\r\n4       {\r\n5               int i;\r\n6               for (i=0; i&lt;10; i++)\r\n7               {\r\n8                       puts(&quot;Hello World&quot;);\r\n9               }\r\n10              return 0;\r\n(gdb) set disassembly-flavor intel\r\n(gdb) disas main\r\nDump of assembler code for function main:\r\n   0x00401460 &lt;+0&gt;:     push   ebp                       \/\/ setting up the stack frame\r\n   0x00401461 &lt;+1&gt;:     mov    ebp,esp                   \/\/ ...\r\n   0x00401463 &lt;+3&gt;:     and    esp,0xfffffff0            \/\/ ...\r\n   0x00401466 &lt;+6&gt;:     sub    esp,0x20                  \/\/ ... done\r\n   0x00401469 &lt;+9&gt;:     call   0x4019d0 &lt;__main&gt;         \/\/ fill the stack frame\r\n   0x0040146e &lt;+14&gt;:    mov    DWORD PTR [esp+0x1c],0x0  \/\/ i=0\r\n   0x00401476 &lt;+22&gt;:    jmp    0x401489 &lt;main+41&gt;        \/\/ goto loop_head \r\n   0x00401478 &lt;+24&gt;:    mov    DWORD PTR [esp],0x405064  \/\/ loop_body: \r\n   0x0040147f &lt;+31&gt;:    call   0x403a70 &lt;puts&gt;           \/\/ puts(&quot;Hello World&quot;)\r\n   0x00401484 &lt;+36&gt;:    add    DWORD PTR [esp+0x1c],0x1  \/\/ i++\r\n   0x00401489 &lt;+41&gt;:    cmp    DWORD PTR [esp+0x1c],0x9  \/\/ loop_head: Compare i with 9\r\n   0x0040148e &lt;+46&gt;:    jle    0x401478 &lt;main+24&gt;        \/\/ If (&lt;=) goto loop_body\r\n   0x00401490 &lt;+48&gt;:    mov    eax,0x0                   \/\/ cleaning up the stack frame\r\n   0x00401495 &lt;+53&gt;:    leave                            \/\/ ... done\r\n   0x00401496 &lt;+54&gt;:    ret                              \/\/ return\r\nEnd of assembler dump.\r\n<\/pre>\n<p>DWORD &#8230; 4 Byte (on x86)<\/p>\n<p>For a basic assembly instruction: <a href=\"http:\/\/www.max-sperling.bplaced.net\/?p=2019\">Link<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>DWORD &#8230; 4 Byte (on x86) For a basic assembly instruction: Link<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[39],"tags":[],"_links":{"self":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/2175"}],"collection":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2175"}],"version-history":[{"count":1,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/2175\/revisions"}],"predecessor-version":[{"id":16715,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/2175\/revisions\/16715"}],"wp:attachment":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2175"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}