当前位置:首页 > > 全栈芯片工程师
[导读]本CPU设计基于16bitRISC指令集、哈佛结构完成,架构图如下:CPU架构A.MemoryAccessInstructions1.LoadWord:        LDws,offset(rs1)ws:=Mem16[rs1offset]2.StoreWord:        ...


本CPU设计基于16bit RISC指令集、哈佛结构完成,架构图如下:



CPU架构



A. Memory Access Instructions
1. Load Word:

               LD ws, offset(rs1) ws:=Mem16[rs1 offset]
2. Store Word:

               ST rs2, offset(rs1) Mem16[rs1 offset]=rs2


B. Data Processing Instructions
1. Add:

               ADD ws, rs1, rs2 ws:=rs1 rs2
2. Subtract:

               SUB ws, rs1, rs2 ws:=rs1 – rs2
3. Invert (1‘s complement):

               INV ws, rs1 ws:=!rs1
4. Logical Shift Left:

               LSL ws, rs1, rs2 ws:=rs1 << rs2
5. Logical Shift Right:

               LSR ws, rs1, rs2 ws:=rs1 >> rs2
6. Bitwise AND:

               AND ws, rs1, rs2 ws:=rs1 • rs2
7. Bitwise OR:

              OR ws, rs1, rs2 ws:=rs1 | rs2
8. Set on Less Than:
             SLT ws, rs1, rs2 ws:=1 if rs1 < rs2; ws:=0 if rs1 ≥ rs2


C. Control Flow Instructions
1. Branch on Equal:
               BEQ rs1, rs2, offset
               Branch to (PC 2 (offset << 1)) when rs1 = rs2

2. Branch on Not Equal:
              BNE rs1, rs2, offset
              Branch to (PC 2 (offset << 1)) when rs1 != rs2

3. Jump: JMP offset Jump to {PC [15:13], (offset << 1)}




Instruction Format of the RISC



Processor Control Unit Design:

ALU Control Unit Design:


Verilog code for the RISC processor:


1. Verilog code for Instruction Memory :


`include "Parameter.v"// fpga4student.com // FPGA projects, VHDL projects, Verilog projects // Verilog code for RISC Processor // Verilog code for Instruction Memorymodule Instruction_Memory( input[15:0] pc, output[15:0] instruction);
reg [`col - 1:0] memory [`row_i - 1:0]; wire [3 : 0] rom_addr = pc[4 : 1]; initial begin $readmemb("./test/test.prog", memory,0,14); end assign instruction = memory[rom_addr];
endmodule

2. Verilog code for register file:


`timescale 1ns / 1ps// fpga4student.com // FPGA projects, VHDL projects, Verilog projects // Verilog code for RISC Processor // Verilog code for register filemodule GPRs( input clk, // write port input reg_write_en, input [2:0] reg_write_dest, input [15:0] reg_write_data, //read port 1 input [2:0] reg_read_addr_1, output [15:0] reg_read_data_1, //read port 2 input [2:0] reg_read_addr_2, output [15:0] reg_read_data_2); reg [15:0] reg_array [7:0]; integer i; // write port //reg [2:0] i; initial begin for(i=0;i<8;i=i 1) reg_array[i] <= 16'd0; end always @ (posedge clk ) begin if(reg_write_en) begin reg_array[reg_write_dest] <= reg_write_data; end end  assign reg_read_data_1 = reg_array[reg_read_addr_1]; assign reg_read_data_2 = reg_array[reg_read_addr_2];
endmodule

3. Verilog code for Data Memory:

`include "Parameter.v"// fpga4student.com // FPGA projects, VHDL projects, Verilog projects // Verilog code for RISC Processor // Verilog code for data Memorymodule Data_Memory( input clk, // address input, shared by read and write port input [15:0] mem_access_addr, // write port input [15:0] mem_write_data, input mem_write_en, input mem_read, // read port output [15:0] mem_read_data);
reg [`col - 1:0] memory [`row_d - 1:0];integer f;wire [2:0] ram_addr=mem_access_addr[2:0];initial begin $readmemb("./test/test.data", memory); f = $fopen(`filename); $fmonitor(f, "time = %d\n", $time, "\tmemory[0] = %b\n", memory[0], "\tmemory[1] = %b\n", memory[1], "\tmemory[2] = %b\n", memory[2], "\tmemory[3] = %b\n", memory[3], "\tmemory[4] = %b\n", memory[4], "\tmemory[5] = %b\n", memory[5], "\tmemory[6] = %b\n", memory[6], "\tmemory[7] = %b\n", memory[7]); `simulation_time; $fclose(f); end always @(posedge clk) begin if (mem_write_en) memory[ram_addr] <= mem_write_data; end assign mem_read_data = (mem_read==1'b1) ? memory[ram_addr]: 16'd0;
endmodule


4. Verilog code for ALU unit:

// fpga4student.com // FPGA projects, VHDL projects, Verilog projects // Verilog code for RISC Processor // Verilog code for ALUmodule ALU( input [15:0] a, //src1 input [15:0] b, //src2 input [2:0] alu_control, //function sel output reg [15:0] result, //result output zero );
always @(*)begin case(alu_control) 3'b000: result = a b; // add 3'b001: result = a - b; // sub 3'b010: result = ~a; 3'b011: result = a< 3'b100: result = a>>b; 3'b101: result = a
本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读

不少团队把应用切成容器后,以为节点上线会更灵活。边缘计算真到现场时,最先暴露的往往不是编排能力,而是冷启动被镜像拉取和层展开拖得过长。

关键字: 边缘计算 冷启动 CPU

在现代多核CPU的高并发编程领域,Cache伪共享是最隐蔽也最容易被忽略的性能杀手,结合我们之前深入探讨过的C++内存模型、无锁队列实现、Mutex互斥锁优化等工程实践经验,很多开发者在编写高并发多线程代码时,明明逻辑上...

关键字: CPU 伪共享

在电力电子系统全面转向数字化的当下,很多工程师都会遇到一个看似矛盾的现象:明明选用了主频足够高的数字信号控制器,算法逻辑也经过反复验证没有问题,但最终整机的稳态精度和动态性能,始终达不到理论仿真的预期。反复排查软件逻辑后...

关键字: 数字控制 CPU

机器人产业的真正分水岭,可能既不在算力大小,也不在模型参数的多寡。在各类人形机器人、自主移动机器人与智能工业系统密集亮相的当下,一个更本质的问题正在被反复追问:一台已经掌握多项技能的机器人,为什么换一个场景、换一个任务,...

关键字: ARM 物理 AI 机器人 泛化能力 CPU 运动控制

微软和亚马逊云科技最新财报传递出同一个信号:基于 Arm 架构的 CPU 已成为智能体 AI 的核心基础设施。

关键字: 云计算 CPU AI

很多现场节点一遇到吞吐瓶颈,就想把内存复制次数砍掉。边缘计算若把零拷贝只当成省一次 memcpy,很容易把新的时延和一致性问题带进主链路。

关键字: 边缘计算 零拷贝 CPU

我们已经过了仅凭演示效果来评判人工智能 (AI) 基础设施的阶段。如今,更关键的问题在于,这些能力能否以可靠、可扩展且具备成本效益的方式交付。这正是我们在设计下一代 AI 基础设施过程中,与云服务提供商、芯片合作伙伴及系...

关键字: 人工智能 CPU 自研芯片

如果我们用Arduino核心在ESP8266上写任何代码,很可能已经遇到了这个瓶颈。你写的每一行代码都运行在loop()函数内部,而loop()是协作式的——它从上到下依次执行,只有在完成所有操作后,SDK才会有机会进行...

关键字: Arduino CPU LED ESP8266

本项目记录了将一块基于STM32F407的空开发板,通过将其内部12位数模转换器(DAC)连接至PA4引脚,成功改造为功能完整的模拟信号发生器的过程。从完全零基础构建的裸机模板出发,在调试固件配置方面积累了极为丰富的学习...

关键字: CPU 信号发生器 定时器 STM32F407

核心数量提升33%、PCIe带宽提升至2倍、内存带宽提升至2.6倍,大幅强化高性能工作负载的运行。 搭载第六代AMD EPYC CPU和AMD Instinct™...

关键字: AMD CPU MICRO SUPER
关闭