IC的帆哥 - 内联汇编
https://www.icfgblog.com/index.php/tag/%E5%86%85%E8%81%94%E6%B1%87%E7%BC%96/
-
C内联汇编nice指令解读
https://www.icfgblog.com/index.php/algorithm/183.html
2021-04-15T20:56:00+08:00
RVMCU课堂「8」: 手把手教你玩转RVSTAR—内联汇编篇
技术分享--利用 NucleiStudio IDE 和 vivado 进行软硬件联合仿真
一、基本结构
支持类型:只支持R型
Name
opcode
type
CUSTOM0
7'h0b
R type
CUSTOM1
7'h2b
R tpye
CUSTOM2
7'h5b
R type
CUSTOM3
7'h7b
R type
1.costom3 lbuf(a1): 加载内存中的数据至row_buf :
.insn r opcode,func3,func7,rd,rs1,rs2
2.costom3 sbuf(a1): 保存数据row_buf的数据至内存:
.insn r opcode,func3,func7,rd,rs1,rs2
3.costom3 acc rowsum: 加载a1地址的数据,累加row 数据并写回:
rowsum rd,a1,x0
.insn r opcode,func3,func7,rd,rs1,rs2
二、示例分析
1.custom_lbuf
".insn r 0x7b, 2, 1, x0, %1, x0"
:"=r"(zero)
:"r"(addr)
字母“r”表示使用编译器自动分配的寄存器来存储该操作数变量;字母“m” 表示使用内存地址来存储该操作数变量。如果同时指明“rm”,则编译器自动选择最优方案。。
对于“输出操作数”而言,等号“=”代表输出变量用作输出,原来的值会被新值替换;“+”代表输出变量不仅作为输出,而且作为输入。
opcode
func3
func7
rd
rs1
rs2
0x7b
2
1
x0
%1
x0
custom3
只读取rs1的数据
第一种操作
零寄存器
保存addr地址
零寄存器
1111011
010
0000001
00000
01010
00000
机器码:
funct7
rs2
rs1
funct3
rd
opcode
0000001
00000
01010
010
00000
1111011
把addr的地址加载到源寄存器1,编译器会自动分配rs1用哪一个寄存器(这里是x10),执行lbuf操作,将数据导入nice_core。
2.custom_sbuf
".insn r 0x7b, 2, 2, x0, %1, x0"
:"=r"(zero)
:"r"(addr)
opcode
func3
func7
rd
rs1
rs2
0x7b
2
2
x0
%1
x0
custom3
只读取rs1的数据
第二种操作
零寄存器
保存addr地址
零寄存器
1111011
010
0000010
00000
01010
00000
机器码:
funct7
rs2
rs1
funct3
rd
opcode
0000010
00000
01010
010
00000
1111011
把addr的地址加载到源寄存器1,编译器会自动分配rs1用哪一个寄存器(这里是x10),执行sbuf操作,将nice_core的数据导出addr。
###3.custom_rowsum
".insn r 0x7b, 6, 6, %0, %1, x0"
:"=r"(rowsum)
:"r"(addr)
opcode
func3
func7
rd
rs1
rs2
0x7b
6
6
%0
%1
x0
custom3
读取rs1、rd的数据
第六种操作
rowsum地址
保存addr地址
零寄存器
1111011
110
0000110
01011
01010
00000
机器码:
funct7
rs2
rs1
funct3
rd
opcode
0000110
00000
01010
110
01011
1111011
把addr、rd的地址加载到读源寄存器1、写目标寄存器rd,编译器会自动分配rs1,rd用哪一个寄存器(这里是x10、x11)。执行sumrow操作。
附
riscv 寄存器编号: