学习yosys(一款开源综合器)

安装

复制代码
sudo apt-get install yosys		#ubuntu22.04仓库里面是yosys-0.9
sudo install xdot

创建脚本show_rtl.ys

复制代码
read_verilog cpu.v
hierarchy -top cpu
proc; opt; fsm; opt; memory; opt;
show -prefix cpu

调用脚本

复制代码
yosys show_rtl.ys

verilog代码

复制代码
module cpu(
    input clk,
    input [15:0]op,     //[15:11]指令 [10:8]目标Reg索引 [7:0]立即数或源Reg索引
    output [7:0]R0      // R0-R7组织成https://zhida.zhihu.com/search?content_id=253065908&content_type=Article&match_order=1&q=%E5%AF%84%E5%AD%98%E5%99%A8&zhida_source=entity组,  方便用寄存器索引 选择
);

reg[7:0]R[7:0];
assign R0 = R[0];
reg [7:0] in1,in2, out1;
always @ (*) begin
    in1 = R[op[10:8]];
    in2 = op[11]? R[op[2:0]] : op[7:0];
end

always @ (*) begin 
    case(op[15:12])
        0: out1 = in2;          // ldr
        1: out1 = in1 + in2;    // add
        2: out1 = in1 - in2;    // sub
        3: out1 = in1 & in2;    // and
        4: out1 = in1 | in2;    // or
        5: out1 = (in1 == in2);  // cmp
        default: out1 = 0;
    endcase
end

// 3-8https://zhida.zhihu.com/search?content_id=253065908&content_type=Article&match_order=1&q=%E8%AF%91%E7%A0%81%E5%99%A8&zhida_source=entity
wire [7:0]sel;
always @(*) begin
    case(op[10:8])
        3'b000: sel = 8'b0000_0001;
        3'b001: sel = 8'b0000_0010;
        3'b010: sel = 8'b0000_0100;
        3'b011: sel = 8'b0000_1000;
        3'b100: sel = 8'b0001_0000;
        3'b101: sel = 8'b0010_0000;
        3'b110: sel = 8'b0100_0000;
        3'b111: sel = 8'b1000_0000;
    endcase
end

always @(posedge clk) begin
    if(sel[0]) R[0]=out1;
    if(sel[1]) R[1]=out1;
    if(sel[2]) R[2]=out1;
    if(sel[3]) R[3]=out1;
    if(sel[4]) R[4]=out1;
    if(sel[5]) R[5]=out1;
    if(sel[6]) R[6]=out1;
    if(sel[7]) 
        R[7]=out1;
    else  
        R[7]=R[7]+1;
end

endmodule

生成RTL图

相关推荐
博览鸿蒙17 小时前
FPGA会用到UVM吗?
fpga开发
ThreeYear_s1 天前
基于FPGA实现数字QAM调制系统
fpga开发
小飞侠学FPGA1 天前
VIVADO的IP核 DDS快速使用——生成正弦波,线性调频波
fpga开发·vivado·dds
博览鸿蒙1 天前
成为一个年薪30W+的FPGA工程师是一种什么体验?
fpga开发
喜欢丸子头2 天前
xilinx vivado fir ip(FIR Compiler)核 ADC高采样率,FPGA工作时钟为采样率的1/4,同一个时钟周期来四个数据。
fpga开发
璞致电子2 天前
【PZ-AU15P】璞致fpga开发板 Aritx UltraScalePlus PZ-AU15P 核心板与开发板用户手册
嵌入式硬件·fpga开发·fpga·fpga开发板·xilinx开发板
红糖果仁沙琪玛2 天前
fpga iic协议
fpga开发
嵌入式-老费2 天前
Zynq开发实践(FPGA之pwm输出)
fpga开发
hexiaoyan8272 天前
光纤加速的板卡设计原理图:基于6U VPX XCVU9P+XCZU7EV的双FMC信号处理板卡
嵌入式硬件·fpga开发·光纤加速板卡·国产化板卡·xcvu9p板卡·xcvu9p
XiaoChaoZhiNeng2 天前
Altera Quartus17.1 Modelsim 库编译与仿真
fpga开发