查看: 993|回复: 0
收起左侧

RISC-V ISA brief(ASM brief)

[复制链接]

  离线 

  • TA的每日心情
    奋斗
    2021-3-3 12:32
  • 签到天数: 10 天

    [LV.3]

    发表于 2020-8-23 21:08:48 | 显示全部楼层 |阅读模式

    有人预言,RISC-V或将是继Intel和Arm之后的第三大主流处理器体系。欢迎访问全球首家只专注于RISC-V单片机行业应用的中文网站

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x
    本帖最后由 皋陶 于 2020-8-26 16:02 编辑

    从别处找来的RISCV 指令简介文档,包含了一些常用指令,不全


    1. Table of Contents
    2.   1. Architectural State
    3.   2. Tiny RISC-V Instruction Overview
    4.   3. Tiny RISC-V Instruction Encoding
    5.      3.1. Instruction Formats
    6.      3.2. Immediate Formats
    7.   4. Tiny RISC-V Instruction Details
    8.      4.1. Control/Status Register Instructions
    9.      4.2. Register-Register Arithmetic Instructions
    10.      4.3. Register-Immediate Arithmetic Instructions
    11.      4.4. Memory Instructions
    12.      4.5. Unconditional Jump Instructions
    13.      4.6. Conditional Branch Instructions
    14.   5. Tiny RISC-V Privileged ISA
    15.   6. Tiny RISC-V Pseudo-Instructions

    16. --------------------------------------------------------------------------
    17. 1. Architectural State
    18. --------------------------------------------------------------------------

    19. * Data Formats

    20. - Tiny RISC-V only supports 4B signed and unsigned integer values. There
    21.    are no byte nor half-word values and no floating-point.

    22. * General Purpose Registers

    23. - There are 31 general-purpose registers x1-x31 (called x registers),
    24.    which hold integer values. Register x0 is hardwired to the constant
    25.    zero. Each register is 32 bits wide. Tiny RISC-V uses the same calling
    26.    convention and symbolic register names as RISC-V:

    27.     + x0  : zero   the constant value 0
    28.     + x1  : ra     return address (caller saved)
    29.     + x2  : sp     stack pointer (called saved)
    30.     + x3  : gp     global pointer
    31.     + x4  : tp     thread pointer
    32.     + x5  : t0     temporary registers (caller saved)
    33.     + x6  : t1     "
    34.     + x7  : t2     "
    35.     + x8  : s0/fp  saved register or frame pointer (callee saved)
    36.     + x9  : s1     saved register (callee saved)
    37.     + x10 : a0     function arguments and/or return values (caller saved)
    38.     + x11 : a1     "
    39.     + x12 : a2     function arguments (caller saved)
    40.     + x13 : a3     "
    41.     + x14 : a4     "
    42.     + x15 : a5     "
    43.     + x16 : a6     "
    44.     + x17 : a7     "
    45.     + x18 : s2     saved registers (callee saved)
    46.     + x19 : s3     "
    47.     + x20 : s4     "
    48.     + x21 : s5     "
    49.     + x22 : s6     "
    50.     + x23 : s7     "
    51.     + x24 : s8     "
    52.     + x25 : s9     "
    53.     + x26 : s10    "
    54.     + x27 : s11    "
    55.     + x28 : t3     temporary registers (caller saved)
    56.     + x29 : t4     "
    57.     + x30 : t5     "
    58.     + x31 : t6     "

    59. * Memory

    60. - Tiny RISC-V only supports a 1MB virtual memory address space from
    61.    0x00000000 to 0x000fffff. The result of memory accesses to addresses
    62.    larger than 0x000fffff are undefined.

    63. - A key feature of any ISA is identifying the endianness of the memory
    64.    system. Endianness specifies if we load a word in memory, what order
    65.    should those bytes appear in the destination register. Assume the
    66.    letter A ia at byte address 0x0, the letter B is at byte address 0x1,
    67.    the letter C is at byte address 0x2, and the letter D is at byte
    68.    address 0x3. If we laod a four-byte word from address 0x0, there are
    69.    two options: the destination register can either hold 0xABCD (big
    70.    endian) or 0xDCBA (little endian). There is no significant benefit of
    71.    one system over the other. Tiny RISC-V uses a little endian memory
    72.    system.

    73. --------------------------------------------------------------------------
    74. 2. Tiny RISC-V ISA Overview
    75. --------------------------------------------------------------------------

    76. Here is a brief list of the instructions which make up both versions of
    77. the Tiny RISC-V ISA, and then some discussion about the differences
    78. between the two versions.

    79. * TinyRV1

    80. TinyRV1 contains a very small subset of the TinyRV2 ISA suitable for
    81. illustrating how small assembly sequences execute on various
    82. microarchitectures in lecture, problem sets, and exams.

    83. - ADD, ADDI, MUL
    84. - LW, SW
    85. - JAL, JR
    86. - BNE

    87. * TinyRV2

    88. TinyRV2 is suitable for executing simple C programs that do not use
    89. system calls.

    90. - ADD, ADDI, SUB, MUL
    91. - AND, ANDI, OR, ORI, XOR, XORI
    92. - SLT, SLTI, SLTU, SLTIU
    93. - SRA, SRAI, SRL, SRLI, SLL, SLLI
    94. - LUI, AUIPC
    95. - LW, SW
    96. - JAL, JALR
    97. - BEQ, BNE, BLT, BGE, BLTU, BGEU
    98. - CSRR, CSRW (proc2mngr, mngr2proc, stats_en, core_id, num_cores)

    99. * Discussion

    100. TinyRV1 includes the JR instruction, but technically this is not a real
    101. instruction but is instead a pseudo-instruction for the following usage
    102. of JALR:

    103. jalr x0, rs1, 0

    104. The JALR instruction is a bit complicated, and we really only need the JR
    105. functionality to explain function calls in TinyRV1. So TinyRV1 only
    106. includes the JR pseudo-instruction, while TinyRV2 includes the full JALR
    107. instruction.

    108. CSSR and CSRW are also pseudo-instructions in the full RV32IM ISA for
    109. specific usage of the CSRRW and CSRRS instructions. The full CSRRW and
    110. CSRRS instructions are rather complicated and we don't actually need any
    111. functionality beyond what CSSR and CSRW provide. So TinyRV2 only includes
    112. the CSSR and CSRW pseudo-instruction.

    113. --------------------------------------------------------------------------
    114. 3. Tiny RISC-V Instruction and Immediate Encoding
    115. --------------------------------------------------------------------------

    116. The Tiny RISC-V ISA uses the same instruction encoding as RISC-V. There
    117. are four instruction types and five immediate encodings. Each instruction
    118. has a specific instruction type, and if that instruction includes an
    119. immediate, then it will also have an immediate type.

    120. --------------------------------------------------------------------------
    121. 3.1. Tiny RISC-V Instruction Formats
    122. --------------------------------------------------------------------------

    123. * R-type

    124.   31        25 24     20 19     15 14  12 11      7 6           0
    125. +------------+---------+---------+------+---------+-------------+
    126. | funct7     | rs2     | rs1     |funct3| rd      | opcode      |
    127. +------------+---------+---------+------+---------+-------------+

    128. * I-type

    129.   31                  20 19     15 14  12 11      7 6           0
    130. +----------------------+---------+------+---------+-------------+
    131. | imm                  | rs1     |funct3| rd      | opcode      |
    132. +----------------------+---------+------+---------+-------------+

    133. * S-type

    134.   31        25 24     20 19     15 14  12 11      7 6           0
    135. +------------+---------+---------+------+---------+-------------+
    136. | imm        | rs2     | rs1     |funct3| imm     | opcode      |
    137. +------------+---------+---------+------+---------+-------------+

    138. * U-type

    139.   31                                      11      7 6           0
    140. +---------------------------------------+---------+-------------+
    141. | imm                                   | rd      | opcode      |
    142. +---------------------------------------+---------+-------------+

    143. --------------------------------------------------------------------------
    144. 3.2. Tiny RISC-V Immediate Formats
    145. --------------------------------------------------------------------------

    146. RISC-V has an asymmetric immediate encoding which means that the
    147. immediates are formed by concatenating different bits in an asymmetric
    148. order based on the specific immediate formats. Note that in RISC-V all
    149. immediates are always sign extended, and the sign-bit for the immediate
    150. is always in bit 31 of the instruction.

    151. The following diagrams illustrate how to create a 32-bit immediate from
    152. each of the five immediate formats. The fields are labeled with the
    153. instruction bits used to construct their value. <-- n is used to indicate
    154. repeating bit n of the instruction to fill that field and z is used to
    155. indicate a bit which is always set to zero.

    156. * I-immediate

    157.   31                                        10        5 4     1  0
    158. +-----------------------------------------+-----------+-------+--+
    159. |                                  <-- 31 | 30:25     | 24:21 |20|
    160. +-----------------------------------------+-----------+-------+--+

    161. * S-immediate

    162.   31                                        10        5 4     1  0
    163. +-----------------------------------------+-----------+-------+--+
    164. |                                  <-- 31 | 30:25     | 11:8  |7 |
    165. +-----------------------------------------+-----------+-------+--+

    166. * B-immediate

    167.   31                                  12 11 10        5 4     1  0
    168. +--------------------------------------+--+-----------+-------+--+
    169. |                               <-- 31 |7 | 30:25     | 11:8  |z |
    170. +--------------------------------------+--+-----------+-------+--+

    171. * U-immediate

    172.   31 30               20 19           12 11                      0
    173. +--+-------------------+---------------+-------------------------+
    174. |31| 30:20             | 19:12         |                   <-- z |
    175. +--+-------------------+---------------+-------------------------+

    176. * J-immediate

    177.   31                  20 19           12 11 10        5 4     1  0
    178. +----------------------+---------------+--+-----------+-------+--+
    179. |               <-- 31 | 19:12         |20| 30:25     | 24:21 |z |
    180. +----------------------+---------------+--+-----------+-------+--+

    181. --------------------------------------------------------------------------
    182. 4. PARC Instruction Details
    183. --------------------------------------------------------------------------

    184. For each instruction we include a brief summary, assembly syntax,
    185. instruction semantics, instruction and immediate encoding format, and the
    186. actual encoding for the instruction. We use the following conventions
    187. when specifying the instruction semantics:

    188. - R[rx]      : general-purpose register value for register specifier rx
    189. - CSR[src]   : control/status register value for register specifier csr
    190. - sext       : sign extend to 32 bits
    191. - M_4B[addr] : 4-byte memory value at address addr
    192. - PC         : current program counter
    193. - <s         : signed less-than comparison
    194. - >=s        : signed greater than or equal to comparison
    195. - <u         : unsigned less-than comparison
    196. - >=u        : unsigned greater than or equal to comparison
    197. - imm        : immediate according to the immediate type

    198. Unless otherwise specified assume instruction updates PC with PC+4.

    199. --------------------------------------------------------------------------
    200. 4.1. Control/Status Register Instructions
    201. --------------------------------------------------------------------------

    202. * CSRR

    203. - Summary   : Move value in control/status register to GPR
    204. - Assembly  : csrr rd, csr
    205. - Semantics : R[rd] = CSR[csr]
    206. - Format    : I-type, I-immediate

    207.   31                  20 19     15 14  12 11      7 6           0
    208. +----------------------+---------+------+---------+-------------+
    209. | csr                  | rs1     | 010  | rd      | 1110011     |
    210. +----------------------+---------+------+---------+-------------+

    211. The control/status register read instruction is used to read a CSR and
    212. write the result to a GPR. The CSRs supported in TinyRV2 are listed in
    213. Section 5. Note that in RISC-V CSRR is really a pseudo-instruction for a
    214. specific usage of CSRRS, but in TinyRV2 we only support the subset of
    215. CSRRS captured by CSRR. See Section 6 for more details about
    216. pseudo-instructions.

    217. * CSRW

    218. - Summary   : Move value in GPR to control/status register
    219. - Assembly  : csrw csr, rs1
    220. - Semantics : CSR[csr] = R[rs1]
    221. - Format    : I-type, I-immediate

    222.   31                  20 19     15 14  12 11      7 6           0
    223. +----------------------+---------+------+---------+-------------+
    224. | csr                  | rs1     | 001  | rd      | 1110011     |
    225. +----------------------+---------+------+---------+-------------+

    226. The control/status register write instruction is used to read a GPR and
    227. write the result to a CSR. The CSRs supported in TinyRV2 are listed in
    228. Section 5. Note that in RISC-V CSRW is really a pseudo-instruction for a
    229. specific usage of CSRRW, but in TinyRV2 we only support the subset of
    230. CSRRW captured by CSRW. See Section 6 for more details about
    231. pseudo-instructions.

    232. --------------------------------------------------------------------------
    233. 4.2. Register-Register Arithmetic Instructions
    234. --------------------------------------------------------------------------

    235. * ADD

    236. - Summary   : Addition with 3 GPRs, no overflow exception
    237. - Assembly  : add rd, rs1, rs2
    238. - Semantics : R[rd] = R[rs1] + R[rs2]
    239. - Format    : R-type

    240.   31        25 24     20 19     15 14  12 11      7 6           0
    241. +------------+---------+---------+------+---------+-------------+
    242. | 0000000    | rs2     | rs1     | 000  | rd      | 0110011     |
    243. +------------+---------+---------+------+---------+-------------+

    244. * SUB

    245. - Summary   : Subtraction with 3 GPRs, no overflow exception
    246. - Assembly  : sub rd, rs1, rs2
    247. - Semantics : R[rd] = R[rs1] - R[rs2]
    248. - Format    : R-type

    249.   31        25 24     20 19     15 14  12 11      7 6           0
    250. +------------+---------+---------+------+---------+-------------+
    251. | 0100000    | rs2     | rs1     | 000  | rd      | 0110011     |
    252. +------------+---------+---------+------+---------+-------------+

    253. * AND

    254. - Summary   : Bitwise logical AND with 3 GPRs
    255. - Assembly  : and rd, rs1, rs2
    256. - Semantics : R[rd] = R[rs1] & R[rs2]
    257. - Format    : R-type

    258.   31        25 24     20 19     15 14  12 11      7 6           0
    259. +------------+---------+---------+------+---------+-------------+
    260. | 0000000    | rs2     | rs1     | 111  | rd      | 0110011     |
    261. +------------+---------+---------+------+---------+-------------+

    262. * OR

    263. - Summary   : Bitwise logical OR with 3 GPRs
    264. - Assembly  : or rd, rs1, rs2
    265. - Semantics : R[rd] = R[rs1] | R[rs2]
    266. - Format    : R-type

    267.   31        25 24     20 19     15 14  12 11      7 6           0
    268. +------------+---------+---------+------+---------+-------------+
    269. | 0000000    | rs2     | rs1     | 110  | rd      | 0110011     |
    270. +------------+---------+---------+------+---------+-------------+

    271. * XOR

    272. - Summary   : Bitwise logical XOR with 3 GPRs
    273. - Assembly  : xor rd, rs1, rs2
    274. - Semantics : R[rd] = R[rs1] ^ R[rs2]
    275. - Format    : R-type

    276.   31        25 24     20 19     15 14  12 11      7 6           0
    277. +------------+---------+---------+------+---------+-------------+
    278. | 0000000    | rs2     | rs1     | 100  | rd      | 0110011     |
    279. +------------+---------+---------+------+---------+-------------+

    280. * SLT

    281. - Summary   : Record result of signed less-than comparison with 2 GPRs
    282. - Assembly  : slt rd, rs1, rs2
    283. - Semantics : R[rd] = ( R[rs1] <s R[rs2] )
    284. - Format    : R-type

    285.   31        25 24     20 19     15 14  12 11      7 6           0
    286. +------------+---------+---------+------+---------+-------------+
    287. | 0000000    | rs2     | rs1     | 010  | rd      | 0110011     |
    288. +------------+---------+---------+------+---------+-------------+

    289. This instruction uses a _signed_ comparison.

    290. * SLTU

    291. - Summary   : Record result of unsigned less-than comparison with 2 GPRs
    292. - Assembly  : sltu rd, rs1, rs2
    293. - Semantics : R[rd] = ( R[rs1] <u R[rs2] )
    294. - Format    : R-type

    295.   31        25 24     20 19     15 14  12 11      7 6           0
    296. +------------+---------+---------+------+---------+-------------+
    297. | 0000000    | rs2     | rs1     | 011  | rd      | 0110011     |
    298. +------------+---------+---------+------+---------+-------------+

    299. This instruction uses an _unsigned_ comparison.

    300. * SRA

    301. - Summary   : Shift right arithmetic by register value (sign-extend)
    302. - Assembly  : sra rd, rs1, rs2
    303. - Semantics : R[rd] = R[rs1] >>> R[rs2][4:0]
    304. - Format    : R-type

    305.   31        25 24     20 19     15 14  12 11      7 6           0
    306. +------------+---------+---------+------+---------+-------------+
    307. | 0100000    | rs2     | rs1     | 101  | rd      | 0110011     |
    308. +------------+---------+---------+------+---------+-------------+

    309. Note that the hardware should ensure that the sign-bit of R[rs1] is
    310. extended to the right as it does the right shift. The hardware _must_
    311. only use the bottom five bits of R[rs2] when performing the shift.

    312. * SRL

    313. - Summary   : Shift right logical by register value (append zeroes)
    314. - Assembly  : srl rd, rs1, rs2
    315. - Semantics : R[rd] = R[rs1] >> R[rs2][4:0]
    316. - Format    : R-type

    317.   31        25 24     20 19     15 14  12 11      7 6           0
    318. +------------+---------+---------+------+---------+-------------+
    319. | 0000000    | rs2     | rs1     | 101  | rd      | 0110011     |
    320. +------------+---------+---------+------+---------+-------------+

    321. Note that the hardware should append zeros to the left as it does the
    322. right shift. The hardware _must_ only use the bottom five bits of R[rs2]
    323. when performing the shift.

    324. * SLL

    325. - Summary   : Shift left logical by register value (append zeroes)
    326. - Assembly  : sll rd, rs1, rs2
    327. - Semantics : R[rd] = R[rs1] << R[rs2][4:0]
    328. - Format    : R-type

    329.   31        25 24     20 19     15 14  12 11      7 6           0
    330. +------------+---------+---------+------+---------+-------------+
    331. | 0000000    | rs2     | rs1     | 001  | rd      | 0110011     |
    332. +------------+---------+---------+------+---------+-------------+

    333. Note that the hardware should append zeros to the right as it does the
    334. left shift. The hardware _must_ only use the bottom five bits of R[rs2]
    335. when performing the shift.

    336. * MUL

    337. - Summary   : Signed multiplication with 3 GPRs, no overflow exception
    338. - Assembly  : mul rd, rs1, rs2
    339. - Semantics : R[rd] = R[rs1] * R[rs2]
    340. - Format    : R-type

    341.   31        25 24     20 19     15 14  12 11      7 6           0
    342. +------------+---------+---------+------+---------+-------------+
    343. | 0000001    | rs2     | rs1     | 000  | rd      | 0110011     |
    344. +------------+---------+---------+------+---------+-------------+

    345. --------------------------------------------------------------------------
    346. 4.3. Register-Immediate Arithmetic Instructions
    347. --------------------------------------------------------------------------

    348. * ADDI

    349. - Summary   : Add constant, no overflow exception
    350. - Assembly  : addi rd, rs1, imm
    351. - Semantics : R[rd] = R[rs1] + sext(imm)
    352. - Format    : I-type, I-immediate

    353.   31                  20 19     15 14  12 11      7 6           0
    354. +----------------------+---------+------+---------+-------------+
    355. | imm                  | rs1     | 000  | rd      | 0010011     |
    356. +----------------------+---------+------+---------+-------------+

    357. * ANDI

    358. - Summary   : Bitwise logical AND with constant
    359. - Assembly  : andi rd, rs1, imm
    360. - Semantics : R[rd] = R[rs1] & sext(imm)
    361. - Format    : I-type, I-immediate

    362.   31                  20 19     15 14  12 11      7 6           0
    363. +----------------------+---------+------+---------+-------------+
    364. | imm                  | rs1     | 111  | rd      | 0010011     |
    365. +----------------------+---------+------+---------+-------------+

    366. * ORI

    367. - Summary   : Bitwise logical OR with constant
    368. - Assembly  : ori rd, rs1, imm
    369. - Semantics : R[rd] = R[rs1] | sext(imm)
    370. - Format    : I-type, I-immediate

    371.   31                  20 19     15 14  12 11      7 6           0
    372. +----------------------+---------+------+---------+-------------+
    373. | imm                  | rs1     | 110  | rd      | 0010011     |
    374. +----------------------+---------+------+---------+-------------+

    375. * XORI

    376. - Summary   : Bitwise logical XOR with constant
    377. - Assembly  : xori rd, rs1, imm
    378. - Semantics : R[rd] = R[rs1] ^ sext(imm)
    379. - Format    : I-type, I-immediate

    380.   31                  20 19     15 14  12 11      7 6           0
    381. +----------------------+---------+------+---------+-------------+
    382. | imm                  | rs1     | 100  | rd      | 0010011     |
    383. +----------------------+---------+------+---------+-------------+

    384. * SLTI

    385. - Summary   : Set GPR if source GPR < constant, signed comparison
    386. - Assembly  : slti rd, rs1, imm
    387. - Semantics : R[rd] = ( R[rs1] <s sext(imm) )
    388. - Format    : I-type, I-immediate

    389.   31                  20 19     15 14  12 11      7 6           0
    390. +----------------------+---------+------+---------+-------------+
    391. | imm                  | rs1     | 010  | rd      | 0010011     |
    392. +----------------------+---------+------+---------+-------------+

    393. * SLTIU

    394. - Summary   : Set GPR if source GPR is < constant, unsigned comparison
    395. - Assembly  : sltiu rd, rs1, imm
    396. - Semantics : R[rd] = ( R[rs1] <u sext(imm) )
    397. - Format    : I-type, I-immediate

    398.   31                  20 19     15 14  12 11      7 6           0
    399. +----------------------+---------+------+---------+-------------+
    400. | imm                  | rs1     | 011  | rd      | 0010011     |
    401. +----------------------+---------+------+---------+-------------+

    402. * SRAI

    403. - Summary   : Shift right arithmetic by constant (sign-extend)
    404. - Assembly  : srai rd, rs1, imm
    405. - Semantics : R[rd] = R[rs1] >>> imm
    406. - Format    : I-type

    407.   31        25 24     20 19     15 14  12 11      7 6           0
    408. +------------+---------+---------+------+---------+-------------+
    409. | 0100000    | imm     | rs1     | 101  | rd      | 0010011     |
    410. +------------+---------+---------+------+---------+-------------+

    411. Note that the hardware should ensure that the sign-bit of R[rs1] is
    412. extended to the right as it does the right shift.

    413. * SRLI

    414. - Summary   : Shift right logical by constant (append zeroes)
    415. - Assembly  : srli rd, rs1, imm
    416. - Semantics : R[rd] = R[rs1] >> imm
    417. - Format    : I-type

    418.   31        25 24     20 19     15 14  12 11      7 6           0
    419. +------------+---------+---------+------+---------+-------------+
    420. | 0000000    | imm     | rs1     | 101  | rd      | 0010011     |
    421. +------------+---------+---------+------+---------+-------------+

    422. Note that the hardware should append zeros to the left as it does the
    423. right shift.

    424. * SLLI

    425. - Summary   : Shift left logical constant (append zeroes)
    426. - Assembly  : slli rd, rs1, imm
    427. - Semantics : R[rd] = R[rs1] << imm
    428. - Format    : R-type

    429.   31        25 24     20 19     15 14  12 11      7 6           0
    430. +------------+---------+---------+------+---------+-------------+
    431. | 0000000    | imm     | rs1     | 001  | rd      | 0010011     |
    432. +------------+---------+---------+------+---------+-------------+

    433. Note that the hardware should append zeros to the right as it does the
    434. left shift.

    435. * LUI

    436. - Summary   : Load constant into upper bits of word
    437. - Assembly  : lui rd, imm
    438. - Semantics : R[rd] = imm << 12
    439. - Format    : I-type, U-immediate

    440.   31                                      11      7 6           0
    441. +---------------------------------------+---------+-------------+
    442. | imm                                   | rd      | 0110111     |
    443. +---------------------------------------+---------+-------------+

    444. * AUIPC

    445. - Summary   : Load PC + constant into upper bits of word
    446. - Assembly  : auipc rd, imm
    447. - Semantics : R[rd] = PC + ( imm << 12 )
    448. - Format    : I-type, U-immediate

    449.   31                                      11      7 6           0
    450. +---------------------------------------+---------+-------------+
    451. | imm                                   | rd      | 0010111     |
    452. +---------------------------------------+---------+-------------+

    453. --------------------------------------------------------------------------
    454. 4.4. Memory Instructions
    455. --------------------------------------------------------------------------

    456. * LW

    457. - Summary   : Load word from memory
    458. - Assembly  : lw rd, imm(rs1)
    459. - Semantics : R[rd] = M_4B[ R[rs1] + sext(imm) ]
    460. - Format    : I-type, I-immediate

    461.   31                  20 19     15 14  12 11      7 6           0
    462. +----------------------+---------+------+---------+-------------+
    463. | imm                  | rs1     | 010  | rd      | 0000011     |
    464. +----------------------+---------+------+---------+-------------+

    465. All addresses used with LW instructions must be four-byte aligned. This
    466. means the bottom two bits of every effective address (i.e., after the
    467. base address is added to the offset) will always be zero.

    468. * SW

    469. - Summary   : Store word into memory
    470. - Assembly  : sw rs2, imm(rs1)
    471. - Semantics : M_4B[ R[rs1] + sext(imm) ] = R[rs2]
    472. - Format    : S-type, S-immediate

    473.   31        25 24     20 19     15 14  12 11      7 6           0
    474. +------------+---------+---------+------+---------+-------------+
    475. | imm        | rs2     | rs1     | 010  | imm     | 0100011     |
    476. +------------+---------+---------+------+---------+-------------+

    477. All addresses used with SW instructions must be four-byte aligned. This
    478. means the bottom two bits of every effective address (i.e., after the
    479. base address is added to the offset) will always be zero.

    480. --------------------------------------------------------------------------
    481. 4.5. Unconditional Jump Instructions
    482. --------------------------------------------------------------------------

    483. * JAL

    484. - Summary   : Jump to address and place return address in GPR
    485. - Assembly  : jal rd, imm
    486. - Semantics : R[rd] = PC + 4; PC = PC + sext(imm)
    487. - Format    : U-type, J-immediate

    488.   31                                      11      7 6           0
    489. +---------------------------------------+---------+-------------+
    490. | imm                                   | rd      | 1101111     |
    491. +---------------------------------------+---------+-------------+

    492. * JR

    493. - Summary   : Jump to address
    494. - Assembly  : jr rs1
    495. - Semantics : PC = R[rs1]
    496. - Format    : I-Type, I-immediate

    497.   31                  20 19     15 14  12 11      7 6           0
    498. +----------------------+---------+------+---------+-------------+
    499. | 000000000000         | rs1     | 000  | 00000   | 1100111     |
    500. +----------------------+---------+------+---------+-------------+

    501. Note that JR is a "real" instruction in TinyRV1, but it is a
    502. pseudo-instruction for a specific usage of JALR. We don't really worry
    503. about zero-ing out the the least-significant bit to zero in TinyRV1, but
    504. this must be done for TinyRV2.

    505. * JALR

    506. - Summary   : Jump to address and place return address in GPR
    507. - Assembly  : jalr rd, rs1, imm
    508. - Semantics : R[rd] = PC + 4; PC = ( R[rs1] + sext(imm) ) & 0xfffffffe
    509. - Format    : I-Type, I-immediate

    510.   31                  20 19     15 14  12 11      7 6           0
    511. +----------------------+---------+------+---------+-------------+
    512. | imm                  | rs1     | 000  | rd      | 1100111     |
    513. +----------------------+---------+------+---------+-------------+

    514. Note that the target address is obtained by adding the 12-bit signed
    515. I-immediate to the value in register rs1, then setting the
    516. least-significant bit of the result to zero. In other words, the JALR
    517. instruction ignores the lowest bit of the calculated target address.

    518. --------------------------------------------------------------------------
    519. 4.6. Conditional Branch Instructions
    520. --------------------------------------------------------------------------

    521. * BEQ

    522. - Summary   : Branch if 2 GPRs are equal
    523. - Assembly  : beq rs1, rs2, imm
    524. - Semantics : PC = ( R[rs1] == R[rs2] ) ? PC + sext(imm) : PC + 4
    525. - Format    : S-type, B-immediate

    526.   31        25 24     20 19     15 14  12 11      7 6           0
    527. +------------+---------+---------+------+---------+-------------+
    528. | imm        | rs2     | rs1     | 000  | imm     | 1100011     |
    529. +------------+---------+---------+------+---------+-------------+

    530. * BNE

    531. - Summary   : Branch if 2 GPRs are not equal
    532. - Assembly  : bne rs1, rs2, imm
    533. - Semantics : PC = ( R[rs1] != R[rs2] ) ? PC + sext(imm) : PC + 4
    534. - Format    : S-type, B-immediate

    535.   31        25 24     20 19     15 14  12 11      7 6           0
    536. +------------+---------+---------+------+---------+-------------+
    537. | imm        | rs2     | rs1     | 001  | imm     | 1100011     |
    538. +------------+---------+---------+------+---------+-------------+

    539. * BLT

    540. - Summary   : Branch based on signed comparison of two GPRs
    541. - Assembly  : blt rs1, rs2, imm
    542. - Semantics : PC = ( R[rs1] <s R[rs2] ) ? PC + sext(imm) : PC + 4
    543. - Format    : S-type, B-immediate

    544.   31        25 24     20 19     15 14  12 11      7 6           0
    545. +------------+---------+---------+------+---------+-------------+
    546. | imm        | rs2     | rs1     | 100  | imm     | 1100011     |
    547. +------------+---------+---------+------+---------+-------------+

    548. This instruction uses a _signed_ comparison.

    549. * BGE

    550. - Summary   : Branch based on signed comparison of two GPRs
    551. - Assembly  : bge rs1, rs2, imm
    552. - Semantics : PC = ( R[rs1] >=s R[rs2] ) ? PC + sext(imm) : PC + 4
    553. - Format    : S-type, B-immediate

    554.   31        25 24     20 19     15 14  12 11      7 6           0
    555. +------------+---------+---------+------+---------+-------------+
    556. | imm        | rs2     | rs1     | 101  | imm     | 1100011     |
    557. +------------+---------+---------+------+---------+-------------+

    558. This instruction uses a _signed_ comparison.

    559. * BLTU

    560. - Summary   : Branch based on unsigned comparison of two GPRs
    561. - Assembly  : bltu rs1, rs2, imm
    562. - Semantics : PC = ( R[rs1] <u R[rs2] ) ? PC + sext(imm) : PC + 4
    563. - Format    : S-type, B-immediate

    564.   31        25 24     20 19     15 14  12 11      7 6           0
    565. +------------+---------+---------+------+---------+-------------+
    566. | imm        | rs2     | rs1     | 110  | imm     | 1100011     |
    567. +------------+---------+---------+------+---------+-------------+

    568. This instruction uses an _unsigned_ comparison.

    569. * BGEU

    570. - Summary   : Branch based on unsigned comparison of two GPRs
    571. - Assembly  : bgeu rs1, rs2, imm
    572. - Semantics : PC = ( R[rs1] >=u R[rs2] ) ? PC + sext(imm) : PC + 4
    573. - Format    : S-type, B-immediate

    574.   31        25 24     20 19     15 14  12 11      7 6           0
    575. +------------+---------+---------+------+---------+-------------+
    576. | imm        | rs2     | rs1     | 111  | imm     | 1100011     |
    577. +------------+---------+---------+------+---------+-------------+

    578. This instruction uses an _unsigned_ comparison.
    复制代码
    本篇完,感谢关注:RISC-V单片机中文网




    上一篇:想要组装一台 RISC-V PC?试试这个 RISC-V 开发板
    下一篇:移植实时操作系统到 risc-v 架构芯片时上下文切换的实现
    RISCV作者优文
    全球首家只专注于RISC-V单片机行业应用的中文网站
    回复

    使用道具 举报

    高级模式
    B Color Image Link Quote Code Smilies

    本版积分规则

    关闭

    RISC-V单片机中文网上一条 /2 下一条



    版权及免责声明|RISC-V单片机中文网 |网站地图

    GMT+8, 2024-11-6 07:55 , Processed in 1.079072 second(s), 45 queries .

    快速回复 返回顶部 返回列表