{"id":1249,"date":"2023-03-11T13:15:00","date_gmt":"2023-03-11T13:15:00","guid":{"rendered":"https:\/\/262235.xyz\/?p=1249"},"modified":"2023-03-11T13:15:00","modified_gmt":"2023-03-11T13:15:00","slug":"1249","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2023\/03\/11\/1249\/","title":{"rendered":"RARS_RISC-V\u6c47\u7f16\u5668\u548c\u8fd0\u884c\u65f6\u6a21\u62df\u5668,\u7f16\u5199Hello World\u6e90\u7801"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2023\/03\/3055539610.webp\" alt=\"RiscV.RARS.webp\" title=\"RiscV.RARS.webp\"><\/p>\n<p>RARS\uff0c\u5373 RISC-V \u6c47\u7f16\u7a0b\u5e8f\u3001\u6a21\u62df\u5668\u548c\u8fd0\u884c\u65f6\uff0c\u5c06\u6c47\u7f16\u548c\u6a21\u62df RISC-V \u6c47\u7f16\u8bed\u8a00\u7a0b\u5e8f\u7684\u6267\u884c\u3002 \u5b83\u7684\u4e3b\u8981\u76ee\u6807\u662f\u4e3a\u5f00\u59cb\u4f7f\u7528 RISC-V \u7684\u4eba\u4eec\u63d0\u4f9b\u4e00\u4e2a\u6709\u6548\u7684\u5f00\u53d1\u73af\u5883\u3002<\/p>\n<h2>B\u7ad9\u89c6\u9891 <a href=\"https:\/\/www.bilibili.com\/video\/BV1bv4y187zf\">RARS RISC-V \u6c47\u7f16\u5668\u548c\u8fd0\u884c\u65f6\u6a21\u62df\u5668, \u7f16\u5199Hello World\u6e90\u7801<\/a><\/h2>\n<h2>\u521b\u5efa Hello World<\/h2>\n<p>\u6211\u4eec\u4e0d\u7528\u8bbf\u95ee C \u6807\u51c6\u5e93\uff0c\u6240\u4ee5jiu\u8c03\u7528 write(fd,buffer,len) \u76f4\u63a5\u6620\u5c04\u5230 Linux \u7cfb\u7edf\u8c03\u7528\u3002 \u5e76\u4e14\u8ba9\u6211\u4eec\u5c06\u5b57\u7b26\u4e32\u7684\u5b9a\u4e49\u63d0\u5347\u5230\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf\u4e2d\uff0c\u56e0\u4e3a\u6c47\u7f16\u8bed\u8a00\u4e0d\u5141\u8bb8\u5b57\u7b26\u4e32\u4f5c\u4e3a\u53c2\u6570\u3002<\/p>\n<h3>\u8fd9\u7ed9\u6211\u4eec\u7559\u4e0b\u4e86\u4e00\u4e9b\u53ef\u76f4\u63a5\u7ffb\u8bd1\u7684 C \u4ee3\u7801\uff1a<\/h3>\n<pre><code>char* str = \"Hello World!\n\";\nint main(){\n    write(1,str,13);\n}<\/code><\/pre>\n<h3>\u7b2c\u4e00\u884c\u53ef\u4ee5\u7ffb\u8bd1\u6210 <code>RISC-V<\/code> \u6c47\u7f16\uff1a<\/h3>\n<pre><code>.data\nstr:  .string \"Hello World!\n\" <\/code><\/pre>\n<h3>C\u8bed\u8a00 <code>main<\/code> \u51fd\u6570 \u548c \u7cfb\u7edf\u8c03\u7528 <code>write<\/code> \u51fd\u6570\uff0c\u53ef\u4ee5\u7ffb\u8bd1\u6210  <code>RISC-V<\/code> \u6c47\u7f16\u8bed\u53e5<\/h3>\n<pre><code>.text\nmain:\nli a0, 1\nla a1, str\nli a2, 13\nli a7, 64\necall<\/code><\/pre>\n<h3>\u52a0\u4e0a\u6ce8\u91ca\u548c <code>exit<\/code> \u7cfb\u7edf\u8c03\u7528\uff0c\u5b8c\u6210\u5b8c\u6574\u7684 <code>RISC-V<\/code> \u6c47\u7f16\u6e90\u7801<\/h3>\n<pre><code>.data # Tell the assembler we are defining data not code\n         # \u544a\u8bc9\u6c47\u7f16\u5668\u6211\u4eec\u5b9a\u4e49\u7684\u662f\u6570\u636e\u800c\u4e0d\u662f\u4ee3\u7801\n\nstr:   # Label this position in memory so it can be referred to in our code\n         # \u5728\u5185\u5b58\u4e2d\u6807\u8bb0\u8fd9\u4e2a\u4f4d\u7f6e\uff0c\u4ee5\u4fbf\u6211\u4eec\u7684\u4ee3\u7801\u4e2d\u5f15\u7528\u5b83\n  .string \"Hello World!\n\" # Copy the string \"Hello World!\n\" into memory\n                                        # \u5c06\u5b57\u7b26\u4e32 \"Hello World!\n\" \u590d\u5236\u5230\u5185\u5b58\u4e2d\n\n.text # Tell the assembler that we are writing code (text) now\n         # \u544a\u8bc9\u6c47\u7f16\u7a0b\u5e8f\u6211\u4eec\u73b0\u5728\u6b63\u5728\u7f16\u5199\u4ee3\u7801\uff08\u6587\u672c\uff09\n\nmain: # Make a label to say where our program should start from\n          # \u505a\u4e00\u4e2a\u6807\u7b7e\u6765\u8bf4\u660e\u6211\u4eec\u7684\u7a0b\u5e8f\u5e94\u8be5\u4ece\u54ea\u91cc\u5f00\u59cb\n\n  li a0, 1   # li means to Load Immediate and we want to load the value 1 into register a0\n                  # li \u8868\u793a\u7acb\u5373\u52a0\u8f7d\uff0c\u6211\u4eec\u8981\u5c06\u503c 1 \u52a0\u8f7d\u5230\u5bc4\u5b58\u5668 a0\n  la a1, str # la is similar to li, but works for loading addresses\n                    # la \u7c7b\u4f3c\u4e8e li\uff0c\u4f46\u7528\u4e8e\u52a0\u8f7d\u5730\u5740\n  li a2, 13  # like the first line, but with 13. This is the final argument to the system call\n                   # \u4e0e\u7b2c\u4e00\u884c\u76f8\u4f3c\uff0c\u4f46\u5e26\u6709 13\u3002\u8fd9\u662f\u7cfb\u7edf\u8c03\u7528\u7684\u6700\u540e\u4e00\u4e2a\u53c2\u6570\n  li a7, 64  # a7 is what determines which system call we are calling and we what to call write (64)\n                   # a7 \u51b3\u5b9a\u4e86\u6211\u4eec\u6b63\u5728\u8c03\u7528\u54ea\u4e2a\u7cfb\u7edf\u8c03\u7528\u4ee5\u53ca\u6211\u4eec\u8c03\u7528\u4ec0\u4e48 write (64)\n  ecall      # actually issue the call\n                # \u5b9e\u9645\u53d1\u51fasyscall\n\n  li a0, 0   # The exit code we will be returning is 0\n                  # \u6211\u4eec\u5c06\u8fd4\u56de\u7684\u9000\u51fa\u4ee3\u7801\u662f 0\n  li a7, 93  # Again we need to indicate what system call we are making and this time we are calling exit(93)\n                  # \u6211\u4eec\u9700\u8981\u518d\u6b21\u6307\u51fa\u6211\u4eec\u6b63\u5728\u8fdb\u884c\u7684\u7cfb\u7edf\u8c03\u7528\uff0c\u8fd9\u6b21\u6211\u4eec\u8c03\u7528 exit(93)\n  ecall <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>RARS\uff0c\u5373 RISC-V \u6c47\u7f16\u7a0b\u5e8f\u3001\u6a21\u62df\u5668\u548c\u8fd0\u884c\u65f6\uff0c\u5c06\u6c47\u7f16\u548c\u6a21\u62df RISC-V \u6c47\u7f16\u8bed\u8a00\u7a0b\u5e8f\u7684\u6267\u884c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,11,12],"tags":[31,72],"class_list":["post-1249","post","type-post","status-publish","format-standard","hentry","category-linux","category-mcu","category-learn","tag-cpp","tag-riscv"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1249","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=1249"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1249\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=1249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=1249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=1249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}