Contents

Lec12-RISC-V Instruction Formats II

RISC-V Instruction Formats II

B-Format Layout

branch/分支 ==> if-else, while, for

encode Label:

/lec12-risc-v-instruction-formats-ii/image.png

PC寻址, 用imm field来表示偏移量

/lec12-risc-v-instruction-formats-ii/image-1.png

/lec12-risc-v-instruction-formats-ii/image-2.png

实际上 RV compressed instruction format! 16bit 压缩指令格式,偏移量不再是4的倍数,而是2的倍数(所以imm 二进制结尾一定是0)

理论layout /lec12-risc-v-instruction-formats-ii/image-3.png

解释一下如何从指令解析出立即数的数值

/lec12-risc-v-instruction-formats-ii/image-4.png

B-type “|” 意思是专门分出一块区域来存一位数字

/lec12-risc-v-instruction-formats-ii/image-5.png

Long Immediate, U-Format Layout

I, B, S imm的12位扩展到long,找个地方放下剩下的20位

/lec12-risc-v-instruction-formats-ii/image-6.png

注意这里不直接使用branch指令跳转,而是采用jump直接来做

地方来了:同时来了两个新的指令lui & auipc /lec12-risc-v-instruction-formats-ii/image-7.png

Corner case

有符号扩展带过来的,1开头的符号扩展

/lec12-risc-v-instruction-formats-ii/image-8.png

用+1来避免这个问题

/lec12-risc-v-instruction-formats-ii/image-9.png

补充 auipc 指令 /lec12-risc-v-instruction-formats-ii/image-10.png

J-Format Layout

只有jal,因为jalr是I-type的

/lec12-risc-v-instruction-formats-ii/image-11.png

使用示例

/lec12-risc-v-instruction-formats-ii/image-12.png

jalr /lec12-risc-v-instruction-formats-ii/image-13.png

使用示例

/lec12-risc-v-instruction-formats-ii/image-14.png

留一个reference