全称: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 |
全称: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 |
全称: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 |
全称:load upper immediate
语法:lui rd, imm
全称:add upper immediate to pc
语法:lui rd, imm
计算 12+34-56
.globl main
main:
addi a0, zero, 12
addi a0, a0, 34
addi a0, a0, -56