{"id":840,"date":"2014-10-25T09:33:25","date_gmt":"2014-10-25T07:33:25","guid":{"rendered":"http:\/\/blog.the-leviathan.ch\/?p=840"},"modified":"2014-10-25T09:40:37","modified_gmt":"2014-10-25T07:40:37","slug":"printfs-syscall-in-arm-assembly","status":"publish","type":"post","link":"https:\/\/blog.the-leviathan.ch\/?p=840","title":{"rendered":"printfs syscall in ARM assembly"},"content":{"rendered":"<p>You can assemble and link it with <\/p>\n<pre>arm-linux-gnueabi-gcc --static hello.S -o hello<\/pre>\n<pre lang=\"asm\">\r\n.data\r\nLC0:\r\n\t.ascii  \"%d\\n\"\r\n.text\r\n.align  2\r\n\r\n.globl main\r\nmain:\r\n\tstmfd\tsp!, {r0, r1, r2, r3, r4, r5, r6, lr}\t@ save the registers we use to the stack\r\n\tmovs\tr4, $0\r\nloop:\r\n\tldr     r3, L3\r\n\tmovs\tr0, r3\r\n\tmovs\tr1, r4\r\n\tbl\tprintf\r\n\r\n\tadds\tr4, r4,$1\r\n\tcmp\tr4, $100\r\n\tbne\tloop\r\n\r\nexit:\r\n\tldmfd\tsp!, {r0, r1, r2, r3, r4, r5, r6, pc}\t@ restore registers before exit\r\n\tmovs\tr7, $1                  @ set r7 to 1 - the syscall for exit\r\n\tswi\t0                       @ then invoke the syscall from linux\r\n\r\nL3:\r\n\t.word\tLC0\r\n\t.size\tmain, .-main\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You can assemble and link it with arm-linux-gnueabi-gcc &#8211;static hello.S -o hello .data LC0: .ascii &#8220;%d\\n&#8221; .text .align 2 .globl main main: stmfd sp!, {r0, r1, r2, r3, r4, r5, r6, lr} @ save the registers we use to the stack movs r4, $0 loop: ldr r3, L3 movs r0, r3 movs r1, r4 bl &hellip; <a href=\"https:\/\/blog.the-leviathan.ch\/?p=840\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">printfs syscall in ARM assembly<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,6],"tags":[],"class_list":["post-840","post","type-post","status-publish","format-standard","hentry","category-daily","category-tech"],"_links":{"self":[{"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=\/wp\/v2\/posts\/840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=840"}],"version-history":[{"count":7,"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=\/wp\/v2\/posts\/840\/revisions"}],"predecessor-version":[{"id":848,"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=\/wp\/v2\/posts\/840\/revisions\/848"}],"wp:attachment":[{"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}