# [残卷]RISC-V 指令集

## CALCULATE

• e.g. `ADD x1 x0 x0` means `x1 = x0 + x0`

• e.g. `ADDI x1 x0 0x11` means `x1 = x0 + 3 (DEC)`
• The difference is that ADDI is used for numerical, while ADD is used for registers (or variable we can say)
• Normally, we can discover `ADDI sp sp -32` at the beginning of the program. It’s used for allocate memory for the main program. `sp` is the pointer of a stack, use to record the runtime memory stack.

## MEMORY

### la

• `la` means load address
• e.g. `la x1 VAL` VAL’s address is at `0x100`, and it’s value is `0x11` then `x1 = 0x100`
• equal to
``````lui t0, SYMBOL[31:12]
``````

### lw

• `lw` means load word
• e.g. `lw x2 VAL` causes `x2 = 0x11`

### sw

• `sw` means save word
• e.g. `sw x3 0(x1)` will cause `x3 = 0x11` and `x3 = x2`

### li

• `li` means load immediate
• e.g. `li a0 VAL` means `a0 = VAL = 0x114514 `for example

the Point is that L means load, S means save. a|b|h|w|d means address, byte, half word, word or double word.

## Branch

### beq

• `beq x1 x2 Label1` means `if(x1 == x2) goto Label1`

## Others

### AUIPC

• `AUIPC` means add an immediate number to pc

• e.g. `auipc x28 65536` means