You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

331 line
14KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- This file documents the GNU Assembler "as".
  4. Copyright (C) 1991-2020 Free Software Foundation, Inc.
  5. Permission is granted to copy, distribute and/or modify this document
  6. under the terms of the GNU Free Documentation License, Version 1.3
  7. or any later version published by the Free Software Foundation;
  8. with no Invariant Sections, with no Front-Cover Texts, and with no
  9. Back-Cover Texts. A copy of the license is included in the
  10. section entitled "GNU Free Documentation License".
  11. -->
  12. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  15. <title>RISC-V-Formats (Using as)</title>
  16. <meta name="description" content="RISC-V-Formats (Using as)">
  17. <meta name="keywords" content="RISC-V-Formats (Using as)">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <link href="index.html#Top" rel="start" title="Top">
  22. <link href="AS-Index.html#AS-Index" rel="index" title="AS Index">
  23. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  24. <link href="RISC_002dV_002dDependent.html#RISC_002dV_002dDependent" rel="up" title="RISC-V-Dependent">
  25. <link href="RISC_002dV_002dATTRIBUTE.html#RISC_002dV_002dATTRIBUTE" rel="next" title="RISC-V-ATTRIBUTE">
  26. <link href="RISC_002dV_002dModifiers.html#RISC_002dV_002dModifiers" rel="prev" title="RISC-V-Modifiers">
  27. <style type="text/css">
  28. <!--
  29. a.summary-letter {text-decoration: none}
  30. blockquote.indentedblock {margin-right: 0em}
  31. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  32. blockquote.smallquotation {font-size: smaller}
  33. div.display {margin-left: 3.2em}
  34. div.example {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smalllisp {margin-left: 3.2em}
  39. kbd {font-style: oblique}
  40. pre.display {font-family: inherit}
  41. pre.format {font-family: inherit}
  42. pre.menu-comment {font-family: serif}
  43. pre.menu-preformatted {font-family: serif}
  44. pre.smalldisplay {font-family: inherit; font-size: smaller}
  45. pre.smallexample {font-size: smaller}
  46. pre.smallformat {font-family: inherit; font-size: smaller}
  47. pre.smalllisp {font-size: smaller}
  48. span.nolinebreak {white-space: nowrap}
  49. span.roman {font-family: initial; font-weight: normal}
  50. span.sansserif {font-family: sans-serif; font-weight: normal}
  51. ul.no-bullet {list-style: none}
  52. -->
  53. </style>
  54. </head>
  55. <body lang="en">
  56. <a name="RISC_002dV_002dFormats"></a>
  57. <div class="header">
  58. <p>
  59. Next: <a href="RISC_002dV_002dATTRIBUTE.html#RISC_002dV_002dATTRIBUTE" accesskey="n" rel="next">RISC-V-ATTRIBUTE</a>, Previous: <a href="RISC_002dV_002dModifiers.html#RISC_002dV_002dModifiers" accesskey="p" rel="prev">RISC-V-Modifiers</a>, Up: <a href="RISC_002dV_002dDependent.html#RISC_002dV_002dDependent" accesskey="u" rel="up">RISC-V-Dependent</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
  60. </div>
  61. <hr>
  62. <a name="RISC_002dV-Instruction-Formats"></a>
  63. <h4 class="subsection">9.38.4 RISC-V Instruction Formats</h4>
  64. <a name="index-instruction-formats_002c-risc_002dv"></a>
  65. <a name="index-RISC_002dV-instruction-formats"></a>
  66. <p>The RISC-V Instruction Set Manual Volume I: User-Level ISA lists 12
  67. instruction formats where some of the formats have multiple variants.
  68. For the &lsquo;<samp>.insn</samp>&rsquo; pseudo directive the assembler recognizes some
  69. of the formats.
  70. Typically, the most general variant of the instruction format is used
  71. by the &lsquo;<samp>.insn</samp>&rsquo; directive.
  72. </p>
  73. <p>The following table lists the abbreviations used in the table of
  74. instruction formats:
  75. </p>
  76. <div class="display">
  77. <table>
  78. <tr><td width="15%"><pre class="display">opcode</pre></td><td width="40%"><pre class="display">Unsigned immediate or opcode name for 7-bits opcode.</pre></td></tr>
  79. <tr><td width="15%"><pre class="display">opcode2</pre></td><td width="40%"><pre class="display">Unsigned immediate or opcode name for 2-bits opcode.</pre></td></tr>
  80. <tr><td width="15%"><pre class="display">func7</pre></td><td width="40%"><pre class="display">Unsigned immediate for 7-bits function code.</pre></td></tr>
  81. <tr><td width="15%"><pre class="display">func6</pre></td><td width="40%"><pre class="display">Unsigned immediate for 6-bits function code.</pre></td></tr>
  82. <tr><td width="15%"><pre class="display">func4</pre></td><td width="40%"><pre class="display">Unsigned immediate for 4-bits function code.</pre></td></tr>
  83. <tr><td width="15%"><pre class="display">func3</pre></td><td width="40%"><pre class="display">Unsigned immediate for 3-bits function code.</pre></td></tr>
  84. <tr><td width="15%"><pre class="display">func2</pre></td><td width="40%"><pre class="display">Unsigned immediate for 2-bits function code.</pre></td></tr>
  85. <tr><td width="15%"><pre class="display">rd</pre></td><td width="40%"><pre class="display">Destination register number for operand x, can be GPR or FPR.</pre></td></tr>
  86. <tr><td width="15%"><pre class="display">rd&rsquo;</pre></td><td width="40%"><pre class="display">Destination register number for operand x,
  87. only accept s0-s1, a0-a5, fs0-fs1 and fa0-fa5.</pre></td></tr>
  88. <tr><td width="15%"><pre class="display">rs1</pre></td><td width="40%"><pre class="display">First source register number for operand x, can be GPR or FPR.</pre></td></tr>
  89. <tr><td width="15%"><pre class="display">rs1&rsquo;</pre></td><td width="40%"><pre class="display">First source register number for operand x,
  90. only accept s0-s1, a0-a5, fs0-fs1 and fa0-fa5.</pre></td></tr>
  91. <tr><td width="15%"><pre class="display">rs2</pre></td><td width="40%"><pre class="display">Second source register number for operand x, can be GPR or FPR.</pre></td></tr>
  92. <tr><td width="15%"><pre class="display">rs2&rsquo;</pre></td><td width="40%"><pre class="display">Second source register number for operand x,
  93. only accept s0-s1, a0-a5, fs0-fs1 and fa0-fa5.</pre></td></tr>
  94. <tr><td width="15%"><pre class="display">simm12</pre></td><td width="40%"><pre class="display">Sign-extended 12-bit immediate for operand x.</pre></td></tr>
  95. <tr><td width="15%"><pre class="display">simm20</pre></td><td width="40%"><pre class="display">Sign-extended 20-bit immediate for operand x.</pre></td></tr>
  96. <tr><td width="15%"><pre class="display">simm6</pre></td><td width="40%"><pre class="display">Sign-extended 6-bit immediate for operand x.</pre></td></tr>
  97. <tr><td width="15%"><pre class="display">uimm8</pre></td><td width="40%"><pre class="display">Unsigned 8-bit immediate for operand x.</pre></td></tr>
  98. <tr><td width="15%"><pre class="display">symbol</pre></td><td width="40%"><pre class="display">Symbol or lable reference for operand x.</pre></td></tr>
  99. </table>
  100. </div>
  101. <p>The following table lists all available opcode name:
  102. </p>
  103. <dl compact="compact">
  104. <dt><code>C0</code></dt>
  105. <dt><code>C1</code></dt>
  106. <dt><code>C2</code></dt>
  107. <dd><p>Opcode space for compressed instructions.
  108. </p>
  109. </dd>
  110. <dt><code>LOAD</code></dt>
  111. <dd><p>Opcode space for load instructions.
  112. </p>
  113. </dd>
  114. <dt><code>LOAD_FP</code></dt>
  115. <dd><p>Opcode space for floating-point load instructions.
  116. </p>
  117. </dd>
  118. <dt><code>STORE</code></dt>
  119. <dd><p>Opcode space for store instructions.
  120. </p>
  121. </dd>
  122. <dt><code>STORE_FP</code></dt>
  123. <dd><p>Opcode space for floating-point store instructions.
  124. </p>
  125. </dd>
  126. <dt><code>AUIPC</code></dt>
  127. <dd><p>Opcode space for auipc instruction.
  128. </p>
  129. </dd>
  130. <dt><code>LUI</code></dt>
  131. <dd><p>Opcode space for lui instruction.
  132. </p>
  133. </dd>
  134. <dt><code>BRANCH</code></dt>
  135. <dd><p>Opcode space for branch instructions.
  136. </p>
  137. </dd>
  138. <dt><code>JAL</code></dt>
  139. <dd><p>Opcode space for jal instruction.
  140. </p>
  141. </dd>
  142. <dt><code>JALR</code></dt>
  143. <dd><p>Opcode space for jalr instruction.
  144. </p>
  145. </dd>
  146. <dt><code>OP</code></dt>
  147. <dd><p>Opcode space for ALU instructions.
  148. </p>
  149. </dd>
  150. <dt><code>OP_32</code></dt>
  151. <dd><p>Opcode space for 32-bits ALU instructions.
  152. </p>
  153. </dd>
  154. <dt><code>OP_IMM</code></dt>
  155. <dd><p>Opcode space for ALU with immediate instructions.
  156. </p>
  157. </dd>
  158. <dt><code>OP_IMM_32</code></dt>
  159. <dd><p>Opcode space for 32-bits ALU with immediate instructions.
  160. </p>
  161. </dd>
  162. <dt><code>OP_FP</code></dt>
  163. <dd><p>Opcode space for floating-point operation instructions.
  164. </p>
  165. </dd>
  166. <dt><code>MADD</code></dt>
  167. <dd><p>Opcode space for madd instruction.
  168. </p>
  169. </dd>
  170. <dt><code>MSUB</code></dt>
  171. <dd><p>Opcode space for msub instruction.
  172. </p>
  173. </dd>
  174. <dt><code>NMADD</code></dt>
  175. <dd><p>Opcode space for nmadd instruction.
  176. </p>
  177. </dd>
  178. <dt><code>NMSUB</code></dt>
  179. <dd><p>Opcode space for msub instruction.
  180. </p>
  181. </dd>
  182. <dt><code>AMO</code></dt>
  183. <dd><p>Opcode space for atomic memory operation instructions.
  184. </p>
  185. </dd>
  186. <dt><code>MISC_MEM</code></dt>
  187. <dd><p>Opcode space for misc instructions.
  188. </p>
  189. </dd>
  190. <dt><code>SYSTEM</code></dt>
  191. <dd><p>Opcode space for system instructions.
  192. </p>
  193. </dd>
  194. <dt><code>CUSTOM_0</code></dt>
  195. <dt><code>CUSTOM_1</code></dt>
  196. <dt><code>CUSTOM_2</code></dt>
  197. <dt><code>CUSTOM_3</code></dt>
  198. <dd><p>Opcode space for customize instructions.
  199. </p>
  200. </dd>
  201. </dl>
  202. <p>An instruction is two or four bytes in length and must be aligned
  203. on a 2 byte boundary. The first two bits of the instruction specify the
  204. length of the instruction, 00, 01 and 10 indicates a two byte instruction,
  205. 11 indicates a four byte instruction.
  206. </p>
  207. <p>The following table lists the RISC-V instruction formats that are available
  208. with the &lsquo;<samp>.insn</samp>&rsquo; pseudo directive:
  209. </p>
  210. <dl compact="compact">
  211. <dt><code>R type: .insn r opcode, func3, func7, rd, rs1, rs2</code></dt>
  212. <dd><pre class="verbatim">+-------+-----+-----+-------+----+-------------+
  213. | func7 | rs2 | rs1 | func3 | rd | opcode |
  214. +-------+-----+-----+-------+----+-------------+
  215. 31 25 20 15 12 7 0
  216. </pre>
  217. </dd>
  218. <dt><code>R type with 4 register operands: .insn r opcode, func3, func2, rd, rs1, rs2, rs3</code></dt>
  219. <dt><code>R4 type: .insn r4 opcode, func3, func2, rd, rs1, rs2, rs3</code></dt>
  220. <dd><pre class="verbatim">+-----+-------+-----+-----+-------+----+-------------+
  221. | rs3 | func2 | rs2 | rs1 | func3 | rd | opcode |
  222. +-----+-------+-----+-----+-------+----+-------------+
  223. 31 27 25 20 15 12 7 0
  224. </pre>
  225. </dd>
  226. <dt><code>I type: .insn i opcode, func3, rd, rs1, simm12</code></dt>
  227. <dt><code>I type: .insn i opcode, func3, rd, simm12(rs1)</code></dt>
  228. <dd><pre class="verbatim">+-------------+-----+-------+----+-------------+
  229. | simm12 | rs1 | func3 | rd | opcode |
  230. +-------------+-----+-------+----+-------------+
  231. 31 20 15 12 7 0
  232. </pre>
  233. </dd>
  234. <dt><code>S type: .insn s opcode, func3, rs2, simm12(rs1)</code></dt>
  235. <dd><pre class="verbatim">+--------------+-----+-----+-------+-------------+-------------+
  236. | simm12[11:5] | rs2 | rs1 | func3 | simm12[4:0] | opcode |
  237. +--------------+-----+-----+-------+-------------+-------------+
  238. 31 25 20 15 12 7 0
  239. </pre>
  240. </dd>
  241. <dt><code>B type: .insn s opcode, func3, rs1, rs2, symbol</code></dt>
  242. <dt><code>SB type: .insn sb opcode, func3, rs1, rs2, symbol</code></dt>
  243. <dd><pre class="verbatim">+------------+--------------+-----+-----+-------+-------------+-------------+--------+
  244. | simm12[12] | simm12[10:5] | rs2 | rs1 | func3 | simm12[4:1] | simm12[11]] | opcode |
  245. +------------+--------------+-----+-----+-------+-------------+-------------+--------+
  246. 31 30 25 20 15 12 7 0
  247. </pre>
  248. </dd>
  249. <dt><code>U type: .insn u opcode, rd, simm20</code></dt>
  250. <dd><pre class="verbatim">+---------------------------+----+-------------+
  251. | simm20 | rd | opcode |
  252. +---------------------------+----+-------------+
  253. 31 12 7 0
  254. </pre>
  255. </dd>
  256. <dt><code>J type: .insn j opcode, rd, symbol</code></dt>
  257. <dt><code>UJ type: .insn uj opcode, rd, symbol</code></dt>
  258. <dd><pre class="verbatim">+------------+--------------+------------+---------------+----+-------------+
  259. | simm20[20] | simm20[10:1] | simm20[11] | simm20[19:12] | rd | opcode |
  260. +------------+--------------+------------+---------------+----+-------------+
  261. 31 30 21 20 12 7 0
  262. </pre>
  263. </dd>
  264. <dt><code>CR type: .insn cr opcode2, func4, rd, rs2</code></dt>
  265. <dd><pre class="verbatim">+---------+--------+-----+---------+
  266. | func4 | rd/rs1 | rs2 | opcode2 |
  267. +---------+--------+-----+---------+
  268. 15 12 7 2 0
  269. </pre>
  270. </dd>
  271. <dt><code>CI type: .insn ci opcode2, func3, rd, simm6</code></dt>
  272. <dd><pre class="verbatim">+---------+-----+--------+-----+---------+
  273. | func3 | imm | rd/rs1 | imm | opcode2 |
  274. +---------+-----+--------+-----+---------+
  275. 15 13 12 7 2 0
  276. </pre>
  277. </dd>
  278. <dt><code>CIW type: .insn ciw opcode2, func3, rd, uimm8</code></dt>
  279. <dd><pre class="verbatim">+---------+--------------+-----+---------+
  280. | func3 | imm | rd' | opcode2 |
  281. +---------+--------------+-----+---------+
  282. 15 13 7 2 0
  283. </pre>
  284. </dd>
  285. <dt><code>CA type: .insn ca opcode2, func6, func2, rd, rs2</code></dt>
  286. <dd><pre class="verbatim">+---------+----------+-------+------+--------+
  287. | func6 | rd'/rs1' | func2 | rs2' | opcode |
  288. +---------+----------+-------+------+--------+
  289. 15 10 7 5 2 0
  290. </pre>
  291. </dd>
  292. <dt><code>CB type: .insn cb opcode2, func3, rs1, symbol</code></dt>
  293. <dd><pre class="verbatim">+---------+--------+------+--------+---------+
  294. | func3 | offset | rs1' | offset | opcode2 |
  295. +---------+--------+------+--------+---------+
  296. 15 13 10 7 2 0
  297. </pre>
  298. </dd>
  299. <dt><code>CJ type: .insn cj opcode2, symbol</code></dt>
  300. <dd><pre class="verbatim">+---------+--------------------+---------+
  301. | func3 | jump target | opcode2 |
  302. +---------+--------------------+---------+
  303. 15 13 7 2 0
  304. </pre>
  305. </dd>
  306. </dl>
  307. <p>For the complete list of all instruction format variants see
  308. The RISC-V Instruction Set Manual Volume I: User-Level ISA.
  309. </p>
  310. <hr>
  311. <div class="header">
  312. <p>
  313. Next: <a href="RISC_002dV_002dATTRIBUTE.html#RISC_002dV_002dATTRIBUTE" accesskey="n" rel="next">RISC-V-ATTRIBUTE</a>, Previous: <a href="RISC_002dV_002dModifiers.html#RISC_002dV_002dModifiers" accesskey="p" rel="prev">RISC-V-Modifiers</a>, Up: <a href="RISC_002dV_002dDependent.html#RISC_002dV_002dDependent" accesskey="u" rel="up">RISC-V-Dependent</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
  314. </div>
  315. </body>
  316. </html>