Skip to content

Latest commit

 

History

History
61 lines (37 loc) · 1.15 KB

9.md

File metadata and controls

61 lines (37 loc) · 1.15 KB

算术指令

add

全称:add

语法:add rd, rs1, rs2

操作:x[rd] = x[rs1] + x[rs2]

R 31 - 25 24 - 20 19 - 15 14 - 12 11 - 7 6 - 0
0000000 rs2 rs1 000 rd 0110011

addi

全称:add immediate

语法:addi rd, rs1, imm

操作:x[rd] = x[rs1] + sext(immediate)

I 31 - 20 19 - 15 14 - 12 11 - 7 6 - 0
imm[11:0] rs1 000 rd 0010011

sub

全称:subtract

语法:sub rd, rs1, rs2

操作:x[rd] = x[rs1] - sext(immediate)

R 31 - 25 24 - 20 19 - 15 14 - 12 11 - 7 6 - 0
0100000 rs2 rs1 000 rd 0110011

lui

全称:load upper immediate

语法:lui rd, imm

auipc

全称:add upper immediate to pc

语法:lui rd, imm

例程1:加减运算

计算 12+34-56

  .globl main
main:
  addi a0, zero, 12
  addi a0, a0, 34
  addi a0, a0, -56