• 方案介紹
  • 附件下載
  • 相關推薦
申請入駐 產(chǎn)業(yè)圖譜

處理器CPU設計Verilog代碼vivado仿真

4小時前
236
加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點資訊討論

2-24010310564U30.doc

共1個文件

名稱:處理器CPU設計Verilog代碼vivado仿真

軟件:vivado

語言:Verilog

代碼功能:

處理器CPU設計

設計一個簡單的處理器,可以實現(xiàn)加減法以及簡單的邏輯運算。

設計包括程序計數(shù)器電路,指令存儲器電路,指令譯碼器電路(控制器),運算電路,數(shù)據(jù)存儲器(寄存器)電路。

FPGA代碼Verilog/VHDL代碼資源下載:www.hdlcode.com

演示視頻:

設計文檔:

1. Cpu

工程文件

程序文件

程序編譯

RTL圖

Testbench

仿真圖

指令格式:

-----------------------

opcode | rs | rt | rd |

-----------------------

15-12 ? 11-8 ?7-4 ?3-0

支持8個指令:ADD,SUB,INC ,DEC,AND,OR,NOT,XOR

操作方式如下:

ADD R1,R2,R3

=> R3 = R1 + R2;

SUB與ADD一致

INC:

INC R1,0,R1

=> R1 = R1 +1;

DEC,R1,0,R1

=> R1 = R1 -1;

測試指令如下:

2101 ?# INC R1 ? 結果:R1 =1

2101 ?# INC R1 ? 結果:R1 =2

2101 ?# INC R1 ? 結果:R1 =3

2202 ?# INC R2 ? 結果:R2 =1

2202 ?# INC R2 ? 結果:R2 =2

0123 ?# ADD R1,R2,R3 ? 結果:R3 =3 + 2 = 5

1124 ?# SUB R1,R2,R4 ? 結果:R4 =3 -2 =1

3303 ?# DEC R3 ? ? ? ? 結果:R3 =5 -1 = 4

4123 ?# AND R1,R2,R3 ? 結果:R3 =00000011 & 00000010 = 0010

5123 ?# OR ?R1,R2,R3 ? 結果:R3 =00000011 | 00000010 = 0011

6103 ?# NOT R1,,R3 ? ? 結果:R3 =~00000011 = 11111100

7123 ?# XOR R1,R2,R3 ? 結果:R3 =00000011 ^ 00000010 = 00000001

部分代碼展示:

`timescale?1ns?/?1ps
//CPU頂層模塊:設計包括程序計數(shù)器電路,指令存儲器電路,指令譯碼器電路,運算電路,數(shù)據(jù)存儲器電路
module?cpu(
????input?wire?clk,
????input?wire?rst_n,
?output?[15:0]?PC,
?output?[15:0]?inst,
?output?[3:0]?Addr1,
?output?[3:0]?Addr2,
?output?[3:0]?Addr3,
?output?[15:0]?Read_data1,
?output?[15:0]?Read_data2,?
?output?[15:0]?aluRes?
????);
//wire?[15:0]?inst;
//wire?[15:0]?PC;
wire?[3:0]?Opcode;
wire?[2:0]?aluOp;
wire?[15:0]?imm;
wire?[15:0]?Write_data;
wire?[15:0]?input1,input2;
wire?writereg;
assign?Opcode?=?inst[15:12];??//操作碼為指令的高四位
assign?Addr1?=?inst[11:8];???
assign?Addr2?=?inst[?7:4];???
assign?Addr3?=?inst[?3:0];???
assign?Write_data?=?aluRes;??
assign?input1?=?Read_data1;
assign?input2?=?Read_data2;
//指令存儲器例化????
im?u_im(
????.Addr(PC),
????.inst(inst)
);??
//指令譯碼器例化
ctr?u_ctr(
????.Opcode(Opcode),
????.aluOp(aluOp),
????.writereg(writereg)
);
//數(shù)據(jù)存儲器例化
rf?u_rf(
????.clk(clk),
????.rst_n(rst_n),
????.Addr1(Addr1),
????.Addr2(Addr2),
????.Addr3(Addr3),
????.Write_data(Write_data),
????.writereg(writereg),
????.Read_data1(Read_data1),
????.Read_data2(Read_data2)
);
//程序計數(shù)器電路例化??
pc?u_pc(
????.clk(clk),
????.rst_n(rst_n),
????.current_pc(PC)
);??
//運算電路例化
alu?u_alu(
????.aluOp(aluOp),
????.input1(input1),
????.input2(input2),?
????.aluRes(aluRes),
????.Zero(Zero)
);
??
endmodule

點擊鏈接獲取代碼文件:http://www.hdlcode.com/index.php?m=home&c=View&a=index&aid=475

  • 2-24010310564U30.doc
    下載

相關推薦