{"id":635,"date":"2010-11-24T08:20:52","date_gmt":"2010-11-23T22:20:52","guid":{"rendered":"http:\/\/brnz.org\/hbr\/?p=635"},"modified":"2010-11-23T21:08:22","modified_gmt":"2010-11-23T11:08:22","slug":"assembly-primer-part-4-hello-world-ppc","status":"publish","type":"post","link":"https:\/\/brnz.org\/hbr\/?p=635","title":{"rendered":"Assembly Primer Part 4 &#8212; Hello World &#8212; PPC"},"content":{"rendered":"<h2><span style=\"font-weight: normal; font-size: 13px;\">These are my notes for where I can see PPC varying from ia32, as presented in the video <a href=\"http:\/\/www.securitytube.net\/Assembly-Primer-for-Hackers-(Part-4)-Hello-World-video.aspx\">Part 4 \u2014 Hello World<\/a>. \u00a0Let me know if I\u2019ve missed something important, obvious or got something wrong.<\/span><\/h2>\n<h2><span style=\"font-weight: normal; font-size: 13px;\"><a href=\"http:\/\/www.ibm.com\/developerworks\/library\/l-ppc\/\">http:\/\/www.ibm.com\/developerworks\/library\/l-ppc\/<\/a> gives a good starting overview of PPC asm, including syscalls. \u00a0The syscall number goes into gpr0 and the args in gpr3 and following, so <a href=\"http:\/\/code.securitytube.net\/JustExit.s\">JustExit.s<\/a> becomes:<\/span><\/h2>\n<pre style=\"padding-left: 30px;\">.text\r\n.globl _start\r\n\r\n_start:\r\n    li 0,1 # load 1 into reg 0\r\n    li 3,0 # load 0 into reg 3\r\n    sc     # system call<\/pre>\n<p>Simple enough.<\/p>\n<p>Modifying the provided <a href=\"http:\/\/code.securitytube.net\/HelloWorldProgram.s\">HelloWorldProgram.s<\/a> example (and using the example from the above link) yields<\/p>\n<pre style=\"padding-left: 30px;\">.data\r\n\r\nHelloWorldString:\r\n    .ascii \"Hello World\\n\"\r\n\r\n.text\r\n\r\n.globl _start\r\n\r\n_start:\r\n    # Load all the arguments for write ()\r\n\r\n    li   0, 4  # syscall number of 4 (write)\r\n    li   3, 1  # filenumber 1 (stdout)\r\n    lis  4, HelloWorldString@ha   # load upper 16 bits of addr\r\n    addi 4, 4, HelloWorldString@l # add lower 16 bits of addr\r\n    li   5, 12 # length of string\r\n    sc\r\n\r\n    # exit the program\r\n    li 0,1\r\n    li 3,0\r\n    sc<\/pre>\n<p>There&#8217;s some subtlety in the @ha and @l high and low parts of addresses that I don&#8217;t yet have my head around fully, but I&#8217;ll be coming back to this in a later part.<\/p>\n<h3>Previous assembly primer notes\u2026<\/h3>\n<p>Part 1 \u2014 System Organization \u2014\u00a0<a href=\"https:\/\/brnz.org\/hbr\/?p=631\">PPC<\/a> \u2014\u00a0<a href=\"https:\/\/brnz.org\/hbr\/?p=632\">SPU<\/a><br \/>\nPart 2 \u2014 Memory Organisation \u2014 <a href=\"https:\/\/brnz.org\/hbr\/?p=633\">SPU<\/a><br \/>\nPart 3 &#8212; GDB Usage Primer &#8212; <a href=\"https:\/\/brnz.org\/hbr\/?p=634\">PPC &amp; SPU <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>These are my notes for where I can see PPC varying from ia32, as presented in the video Part 4 \u2014 Hello World. \u00a0Let me know if I\u2019ve missed something important, obvious or got something wrong. http:\/\/www.ibm.com\/developerworks\/library\/l-ppc\/ gives a good starting overview of PPC asm, including syscalls. \u00a0The syscall number goes into gpr0 and the &hellip; <a href=\"https:\/\/brnz.org\/hbr\/?p=635\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Assembly Primer Part 4 &#8212; Hello World &#8212; PPC&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,26],"tags":[38,39],"_links":{"self":[{"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/posts\/635"}],"collection":[{"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=635"}],"version-history":[{"count":8,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/posts\/635\/revisions"}],"predecessor-version":[{"id":697,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/posts\/635\/revisions\/697"}],"wp:attachment":[{"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}