{"id":5550,"date":"2014-03-31T01:23:56","date_gmt":"2014-03-31T01:23:56","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/31\/cross-platform-architecture-assembly-language-collection-of-common-programming-errors\/"},"modified":"2014-03-31T01:23:56","modified_gmt":"2014-03-31T01:23:56","slug":"cross-platform-architecture-assembly-language-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/31\/cross-platform-architecture-assembly-language-collection-of-common-programming-errors\/","title":{"rendered":"Cross Platform\/Architecture Assembly Language-Collection of common programming errors"},"content":{"rendered":"<p>LLVM is a low-level language (whose purpose is a compiler nbackend) that looks a lot like AT&amp;T assembly, if not 10x worse. Here&#8217;s an example:<\/p>\n<pre><code>define i32 @mul_add(i32 %x, i32 %y, i32 %z) {\nentry:\n  %tmp = add i32 %x, %y\n  %tmp2 = sub i32 %tmp, %z\n  ret i32 %tmp2\n}\n<\/code><\/pre>\n<p>This is <em>roughly<\/em> equilavent with the code generated by this AsmJit code:<\/p>\n<pre><code>#include \n#include \n\nusing namespace AsmJit;\n\ntypedef int (*FuncType)(int, int, int);\n\nFuncType build_func(X86Compiler&amp; c)\n{\n    FileLogger logger(stderr);\n    c.setLogger(&amp;logger);\n    c.newFunc(kX86FuncConvDefault, FuncBuilder3());\n    GpVar x = c.getGpArg(0);\n    GpVar y = c.getGpArg(1);\n    GpVar z = c.getGpArg(2);\n    GpVar tmp = c.newGpVar(kX86VarTypeGpd);\n    GpVar tmp2 = c.newGpVar(kX86VarTypeGpd);\n    c.mov(tmp, x);\n    c.add(tmp, y);\n    c.mov(tmp2, tmp);\n    c.sub(tmp2, z);\n    c.ret(tmp2);\n    c.endFunc();\n    return asmjit_cast(c.make());\n}\n<\/code><\/pre>\n<p>This is the output:<\/p>\n<pre><code>; Function Prototype:\n;\n; IDX| Type     | Sz | Home           |\n; ---+----------+----+----------------+\n; 0  | Gpd      | 4  | rdi            |\n; 1  | Gpd      | 4  | rsi            |\n; 2  | Gpd      | 4  | rdx            |\n;\n; Variables:\n;\n; ID | Type     | Sz | Home           | Register Access   | Memory Access     |\n; ---+----------+----+----------------+-------------------+-------------------+\n; 0  | Gpd      | 4  | [None]         | r=1   w=0   x=0   | r=0   w=0   x=0   |\n; 1  | Gpd      | 4  | [None]         | r=1   w=0   x=0   | r=0   w=0   x=0   |\n; 2  | Gpd      | 4  | [None]         | r=1   w=0   x=0   | r=0   w=0   x=0   |\n; 3  | Gpd      | 4  | [None]         | r=1   w=1   x=1   | r=0   w=0   x=0   |\n; 4  | Gpd      | 4  | [None]         | r=1   w=1   x=1   | r=0   w=0   x=0   |\n;\n; Modified registers (5):\n; GP : rax, rcx, rdx, rsi, rdi\n; MM : \n; XMM: \n\nL.0:\n; Prolog\npush rbp\nmov rbp, rsp\n; Body\nmov ecx, edi\nadd ecx, esi\nmov eax, ecx\nsub eax, edx\nL.1:\n; Epilog\nmov rsp, rbp\npop rbp\nret\n<\/code><\/pre>\n<p>LLVM is probably the closest that you&#8217;re going to get.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LLVM is a low-level language (whose purpose is a compiler nbackend) that looks a lot like AT&amp;T assembly, if not 10x worse. Here&#8217;s an example: define i32 @mul_add(i32 %x, i32 %y, i32 %z) { entry: %tmp = add i32 %x, %y %tmp2 = sub i32 %tmp, %z ret i32 %tmp2 } This is roughly equilavent [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5550","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5550","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5550"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5550\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}