SAIFIINDUSTRIES commited on
Commit
c82255d
·
verified ·
1 Parent(s): 2110bdd

Add Repo: Jed-Z_computer-organization-lab

Browse files
Files changed (50) hide show
  1. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sim_1/new/CPU_sim_1.v +49 -0
  2. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/ALU.v +51 -0
  3. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Basys3_CPU.v +74 -0
  4. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/ControlUnit.v +238 -0
  5. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Counter4.v +33 -0
  6. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/DFF_32bits.v +35 -0
  7. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/DataMemory.v +49 -0
  8. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Four_LED.v +65 -0
  9. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Hex_To_7Seg.v +52 -0
  10. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/IR.v +35 -0
  11. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/ImmediateExtend.v +40 -0
  12. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/InstructionMemory.v +41 -0
  13. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Mux2_32bits.v +32 -0
  14. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Mux4_16bits.v +42 -0
  15. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Mux4_32bits.v +42 -0
  16. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Mux4_4bits.v +38 -0
  17. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Mux4_5bits.v +38 -0
  18. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/PC.v +40 -0
  19. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/RegisterFile.v +51 -0
  20. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/clk_div.v +37 -0
  21. Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/top_CPU.v +138 -0
  22. Jed-Z_computer-organization-lab/MultiCycleCPU/test_instructions.txt +24 -0
  23. Jed-Z_computer-organization-lab/README.md +17 -0
  24. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sim_1/new/CPU_sim_1.v +49 -0
  25. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/ALU.v +51 -0
  26. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Basys3_CPU.v +74 -0
  27. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Button_Debounce.v +59 -0
  28. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/ControlUnit.v +129 -0
  29. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Counter4.v +33 -0
  30. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/DataMemory.v +49 -0
  31. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Four_LED.v +65 -0
  32. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Hex_To_7Seg.v +52 -0
  33. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/ImmediateExtend.v +40 -0
  34. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/InstructionMemory.v +55 -0
  35. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Mux2_32bits.v +32 -0
  36. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Mux2_5bits.v +32 -0
  37. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Mux4_16bits.v +42 -0
  38. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Mux4_32bits.v +42 -0
  39. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Mux4_4bits.v +38 -0
  40. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/PC.v +40 -0
  41. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/RegisterFile.v +51 -0
  42. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/clk_div.v +37 -0
  43. Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/top_CPU.v +115 -0
  44. Jed-Z_computer-organization-lab/SingleCycleCPU/test_instructions.txt +21 -0
  45. Jed-Z_computer-organization-lab/hex_to_7seg/hex_to_7seg.srcs/sim_1/new/sim1.v +46 -0
  46. Jed-Z_computer-organization-lab/hex_to_7seg/hex_to_7seg.srcs/sources_1/new/Counter4.v +37 -0
  47. Jed-Z_computer-organization-lab/hex_to_7seg/hex_to_7seg.srcs/sources_1/new/Hex_To_7Seg.v +52 -0
  48. Jed-Z_computer-organization-lab/hex_to_7seg/hex_to_7seg.srcs/sources_1/new/Mux4_8bits.v +38 -0
  49. Jed-Z_computer-organization-lab/hex_to_7seg/hex_to_7seg.srcs/sources_1/new/clk_div.v +37 -0
  50. Jed-Z_computer-organization-lab/hex_to_7seg/hex_to_7seg.srcs/sources_1/new/top_LEDs.v +68 -0
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sim_1/new/CPU_sim_1.v ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/13 16:02:28
7
+ // Design Name:
8
+ // Module Name: CPU_sim_1
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module CPU_sim_1;
24
+ reg clk, Reset;
25
+ wire [31:0] currentIAddr, nextIAddr;
26
+ wire [4:0] rs, rt;
27
+ wire [31:0] ReadData1, ReadData2;
28
+ wire [31:0] ALU_result, DataBus;
29
+
30
+ top_CPU uut(
31
+ .clk(clk),
32
+ .Reset(Reset),
33
+ .currentIAddr(currentIAddr), .nextIAddr(nextIAddr),
34
+ .rs(rs), .rt(rt),
35
+ .ReadData1(ReadData1), .ReadData2(ReadData2),
36
+ .ALU_result(ALU_result), .DataBus(DataBus)
37
+ );
38
+
39
+ always #50 clk = ~clk; // ����ʱ������Ϊ100ns
40
+
41
+ initial begin
42
+ clk = 1;
43
+ Reset = 0;
44
+ #25;
45
+ Reset = 1; // ��ʼ����
46
+ #11000; // ����11000ns���
47
+ $stop; // �ϵ�
48
+ end
49
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/ALU.v ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/11 19:11:01
7
+ // Design Name:
8
+ // Module Name: ALU
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module ALU(
24
+ input [2:0] ALUOp,
25
+ input [31:0] A,
26
+ input [31:0] B,
27
+ output reg [31:0] result,
28
+ output zero, // ����Ƿ�Ϊ0����Ϊ1����Ϊ0
29
+ output sign // ����Ƿ�Ϊ������Ϊ1����Ϊ0
30
+ );
31
+
32
+ assign zero = (result == 0) ? 1 : 0;
33
+ assign sign = result[31];
34
+
35
+ always @(ALUOp or A or B) begin
36
+ case(ALUOp)
37
+ 3'b000: result = A + B;
38
+ 3'b001: result = A - B;
39
+ 3'b010: result = B << A;
40
+ 3'b011: result = A | B;
41
+ 3'b100: result = A & B;
42
+ 3'b101: result = (A < B) ? 1 : 0; // 5: �Ƚ��޷�����
43
+ 3'b110: begin // 6: �Ƚϴ�������
44
+ if((A[31] == B[31]) && (A < B)) result = 1;
45
+ else if(A[31]==1 && B[31]==0) result = 1;
46
+ else result = 0;
47
+ end
48
+ 3'b111: result = A ^ B;
49
+ endcase
50
+ end
51
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Basys3_CPU.v ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/18 20:40:04
7
+ // Design Name:
8
+ // Module Name: Basys3_CPU
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Basys3_CPU(
24
+ input basys3_clock,
25
+ input reset_sw,
26
+ input [1:0] SW_in,
27
+ input next_button,
28
+ output [3:0] enable,
29
+ output [7:0] dispcode
30
+ );
31
+
32
+ wire [31:0] currentIAddr, nextIAddr;
33
+ wire [4:0] rs, rt;
34
+ wire [31:0] ReadData1, ReadData2;
35
+ wire [31:0] ALU_result, DataBus;
36
+
37
+ wire next_signal; // ��������ֶ������ź�
38
+ wire [15:0] DisplayData;
39
+
40
+ top_CPU top_CPU(
41
+ .clk(next_signal), // ȡ����ʹ�ð��°�ť�ṩ�͵�ƽ���ɿ���PC�ŵ���
42
+ .Reset(reset_sw),
43
+ .currentIAddr(currentIAddr), .nextIAddr(nextIAddr),
44
+ .rs(rs), .rt(rt),
45
+ .ReadData1(ReadData1), .ReadData2(ReadData2),
46
+ .ALU_result(ALU_result), .DataBus(DataBus)
47
+ );
48
+
49
+ Four_LED Four_LED(
50
+ .clock(basys3_clock),
51
+ .reset(reset_sw),
52
+ .hex3(DisplayData[15:12]),
53
+ .hex2(DisplayData[11:8]),
54
+ .hex1(DisplayData[7:4]),
55
+ .hex0(DisplayData[3:0]),
56
+ .enable(enable),
57
+ .dispcode(dispcode)
58
+ );
59
+
60
+ Mux4_16bits Mux4_16bits(
61
+ .choice(SW_in),
62
+ .in0({currentIAddr[7:0], nextIAddr[7:0]}),
63
+ .in1({3'b000, rs, ReadData1[7:0]}),
64
+ .in2({3'b000, rt, ReadData2[7:0]}),
65
+ .in3({ALU_result[7:0], DataBus[7:0]}),
66
+ .out(DisplayData)
67
+ );
68
+
69
+ Button_Debounce Button_Debounce(
70
+ .clk(basys3_clock),
71
+ .btn_in(next_button),
72
+ .btn_out(next_signal)
73
+ );
74
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/ControlUnit.v ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/12 22:03:51
7
+ // Design Name:
8
+ // Module Name: ControlUnit
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module ControlUnit(
24
+ input clk, rst,
25
+ input zero, sign,
26
+ input [5:0] opcode,
27
+ output wire InsMemRW,
28
+ output reg PCWre, ALUSrcA, ALUSrcB, DBDataSrc, RegWre, WrRegDSrc, mRD, mWR, IRWre, ExtSel,
29
+ output reg [1:0] PCSrc,
30
+ output reg [1:0] RegDst,
31
+ output reg [2:0] ALUOp
32
+ );
33
+
34
+ reg [2:0] state;
35
+ assign InsMemRW = 1; // ����ʵ���У�ָ��洢��ֻ��
36
+
37
+ /* ״̬ת�� */
38
+ always @(posedge clk or negedge rst) begin
39
+ if(rst==0) begin
40
+ state <= 3'b000;
41
+ PCWre <= 1;
42
+ IRWre <= 1;
43
+ end
44
+ else begin
45
+ case(state)
46
+ 3'b000: state <= 3'b001;
47
+ 3'b001: begin
48
+ if(opcode==6'b110100 || opcode==6'b110101 || opcode==6'b110110) state <= 3'b101;
49
+ else if(opcode==6'b110000 || opcode==6'b110001) state <= 3'b010;
50
+ else if(opcode==6'b111000 || opcode==6'b111001 || opcode==6'b111010 || opcode==6'b111111)
51
+ state <= 3'b000;
52
+ else state <= 3'b110;
53
+ end
54
+ 3'b110: state <= 3'b111;
55
+ 3'b010: state <= 3'b011;
56
+ 3'b011: begin
57
+ if(opcode==6'b110001) state <= 3'b100;
58
+ else state <= 3'b000;
59
+ end
60
+ 3'b111, 3'b101, 3'b100: state <= 3'b000;
61
+ endcase
62
+ end
63
+ end
64
+
65
+ /* ������� */
66
+ always @(state or opcode or zero or sign) begin // ע�ⴥ������
67
+ case(opcode)
68
+ 6'b000000: begin // add
69
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, PCSrc[1:0], RegDst[1:0], ALUOp[2:0]} <= 13'b000100_00_10_000;
70
+ case(state)
71
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
72
+ 3'b001: {IRWre, mWR, RegWre} = 4'b100;
73
+ 3'b110: {IRWre, mWR, RegWre} = 4'b100;
74
+ 3'b111: {IRWre, mWR, RegWre} = 4'b101;
75
+ endcase
76
+ end
77
+ 6'b000001: begin // sub
78
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, PCSrc[1:0], RegDst[1:0], ALUOp[2:0]} <= 13'b000100_00_10_001;
79
+ case(state)
80
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
81
+ 3'b001: {IRWre, mWR, RegWre} = 4'b100;
82
+ 3'b110: {IRWre, mWR, RegWre} = 4'b100;
83
+ 3'b111: {IRWre, mWR, RegWre} = 4'b101;
84
+ endcase
85
+ end
86
+ 6'b000010: begin // addiu
87
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, PCSrc[1:0], RegDst[1:0], ALUOp[2:0]} <= 13'b010101_00_01_000;
88
+ case(state)
89
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
90
+ 3'b001: {IRWre, mWR, RegWre} = 4'b100;
91
+ 3'b110: {IRWre, mWR, RegWre} = 4'b100;
92
+ 3'b111: {IRWre, mWR, RegWre} = 4'b101;
93
+ endcase
94
+ end
95
+ 6'b010000: begin // and
96
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, PCSrc[1:0], RegDst[1:0], ALUOp[2:0]} <= 13'b000100_00_10_100;
97
+ case(state)
98
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
99
+ 3'b001: {IRWre, mWR, RegWre} = 4'b100;
100
+ 3'b110: {IRWre, mWR, RegWre} = 4'b100;
101
+ 3'b111: {IRWre, mWR, RegWre} = 4'b101;
102
+ endcase
103
+ end
104
+ 6'b010001: begin // andi
105
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, PCSrc[1:0], RegDst[1:0], ALUOp[2:0]} <= 13'b010100_00_01_100;
106
+ case(state)
107
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
108
+ 3'b001: {IRWre, mWR, RegWre} = 4'b100;
109
+ 3'b110: {IRWre, mWR, RegWre} = 4'b100;
110
+ 3'b111: {IRWre, mWR, RegWre} = 4'b101;
111
+ endcase
112
+ end
113
+ 6'b010010: begin // ori
114
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, PCSrc[1:0], RegDst[1:0], ALUOp[2:0]} <= 13'b010100_00_01_011;
115
+ case(state)
116
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
117
+ 3'b001: {IRWre, mWR, RegWre} = 4'b100;
118
+ 3'b110: {IRWre, mWR, RegWre} = 4'b100;
119
+ 3'b111: {IRWre, mWR, RegWre} = 4'b101;
120
+ endcase
121
+ end
122
+ 6'b010011: begin // xori
123
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, PCSrc[1:0], RegDst[1:0], ALUOp[2:0]} <= 13'b010100_00_01_111;
124
+ case(state)
125
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
126
+ 3'b001: {IRWre, mWR, RegWre} = 4'b100;
127
+ 3'b110: {IRWre, mWR, RegWre} = 4'b100;
128
+ 3'b111: {IRWre, mWR, RegWre} = 4'b101;
129
+ endcase
130
+ end
131
+ 6'b011000: begin // sll
132
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, PCSrc[1:0], RegDst[1:0], ALUOp[2:0]} <= 13'b100100_00_10_010;
133
+ case(state)
134
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
135
+ 3'b001: {IRWre, mWR, RegWre} = 4'b100;
136
+ 3'b110: {IRWre, mWR, RegWre} = 4'b100;
137
+ 3'b111: {IRWre, mWR, RegWre} = 4'b101;
138
+ endcase
139
+ end
140
+ 6'b100110: begin // slti
141
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, PCSrc[1:0], RegDst[1:0], ALUOp[2:0]} <= 13'b010101_00_01_110;
142
+ case(state)
143
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
144
+ 3'b001: {IRWre, mWR, RegWre} = 4'b100;
145
+ 3'b110: {IRWre, mWR, RegWre} = 4'b100;
146
+ 3'b111: {IRWre, mWR, RegWre} = 4'b101;
147
+ endcase
148
+ end
149
+ 6'b100111: begin // slt
150
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, PCSrc[1:0], RegDst[1:0], ALUOp[2:0]} <= 13'b000100_00_10_110;
151
+ case(state)
152
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
153
+ 3'b001: {IRWre, mWR, RegWre} = 4'b100;
154
+ 3'b110: {IRWre, mWR, RegWre} = 4'b100;
155
+ 3'b111: {IRWre, mWR, RegWre} = 4'b101;
156
+ endcase
157
+ end
158
+ 6'b110000: begin // sw
159
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, PCSrc[1:0], RegDst[1:0], ALUOp[2:0]} <= 13'b010101_00_00_000;
160
+ case(state)
161
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
162
+ 3'b001: {IRWre, mWR, RegWre} = 4'b100;
163
+ 3'b010: {IRWre, mWR, RegWre} = 4'b100;
164
+ 3'b011: {IRWre, mWR, RegWre} = 4'b110;
165
+ endcase
166
+ end
167
+ 6'b110001: begin // lw
168
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, PCSrc[1:0], RegDst[1:0], ALUOp[2:0]} <= 13'b011111_00_01_000;
169
+ case(state)
170
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
171
+ 3'b001: {IRWre, mWR, RegWre} = 4'b100;
172
+ 3'b010: {IRWre, mWR, RegWre} = 4'b100;
173
+ 3'b011: {IRWre, mWR, RegWre} = 4'b100;
174
+ 3'b100: {IRWre, mWR, RegWre} = 4'b101;
175
+ endcase
176
+ end
177
+ 6'b110100: begin // beq
178
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, RegDst[1:0], ALUOp[2:0]} <= 11'b000101_00_001;
179
+ PCSrc[1:0] <= (zero==1) ? 2'b01 : 2'b00;
180
+ case(state)
181
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
182
+ default: {IRWre, mWR, RegWre} = 4'b100;
183
+ endcase
184
+ end
185
+ 6'b110101: begin // bne
186
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, RegDst[1:0], ALUOp[2:0]} <= 11'b000101_00_001;
187
+ PCSrc[1:0] <= (zero==0) ? 2'b01 : 2'b00;
188
+ case(state)
189
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
190
+ default: {IRWre, mWR, RegWre} = 4'b100;
191
+ endcase
192
+ end
193
+ 6'b110110: begin // bltz
194
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, RegDst[1:0], ALUOp[2:0]} <= 11'b000101_00_000;
195
+ PCSrc[1:0] <= (sign==1) ? 2'b01 : 2'b00;
196
+ case(state)
197
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
198
+ default: {IRWre, mWR, RegWre} = 4'b100;
199
+ endcase
200
+ end
201
+ 6'b111000: begin // j
202
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, PCSrc[1:0], RegDst[1:0], ALUOp[2:0]} <= 13'b000100_11_00_000;
203
+ case(state)
204
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
205
+ 3'b001: {IRWre, mWR, RegWre} = 4'b100;
206
+ endcase
207
+ end
208
+ 6'b111001: begin // jr
209
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, PCSrc[1:0], RegDst[1:0], ALUOp[2:0]} <= 13'b000100_10_00_000;
210
+ case(state)
211
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
212
+ 3'b001: {IRWre, mWR, RegWre} = 4'b100;
213
+ endcase
214
+ end
215
+ 6'b111010: begin // jal
216
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, PCSrc[1:0], RegDst[1:0], ALUOp[2:0]} <= 13'b000000_11_00_000;
217
+ case(state)
218
+ 3'b000: {IRWre, mWR, RegWre} = 4'b100;
219
+ 3'b001: {IRWre, mWR, RegWre} = 4'b101; // jal��ID�׶���001��д�Ĵ���
220
+ endcase
221
+ end
222
+ 6'b111111: begin // halt
223
+ {ALUSrcA, ALUSrcB, DBDataSrc, WrRegDSrc, mRD, ExtSel, PCSrc[1:0], RegDst[1:0], ALUOp[2:0]} <= 13'b000100_00_00_000;
224
+ {IRWre, mWR, RegWre} = 4'b100;
225
+ end
226
+ endcase
227
+ end
228
+
229
+ always @(negedge clk) begin
230
+ case(state)
231
+ 3'b111, 3'b101, 3'b100: PCWre <= 1;
232
+ 3'b011: PCWre <= (opcode==6'b110000 ? 1 : 0); // sw
233
+ 3'b001: PCWre <= (opcode==6'b111000||opcode==6'b111001||opcode==6'b111010 ? 1 : 0); // j, jr, jal
234
+ default: PCWre <= 0;
235
+ endcase
236
+ end
237
+
238
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Counter4.v ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/18 20:47:02
7
+ // Design Name:
8
+ // Module Name: Counter4
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Counter4(
24
+ input clk,
25
+ output reg [1:0] count
26
+ );
27
+
28
+ always @(posedge clk) begin
29
+ if(count == 2'b11) count <= 0;
30
+ else count <= count + 1;
31
+ end
32
+
33
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/DFF_32bits.v ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/11 20:07:17
7
+ // Design Name:
8
+ // Module Name: DFF_32bits
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module DFF_32bits(
24
+ input clk,
25
+ input Reset,
26
+ input [31:0] in,
27
+ output reg [31:0] out
28
+ );
29
+
30
+ always @(posedge clk/* or negedge Reset*/) begin
31
+ //if(Reset==0) out <= 0;
32
+ /*else*/ out <= in;
33
+ end
34
+
35
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/DataMemory.v ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/11 19:14:50
7
+ // Design Name:
8
+ // Module Name: DataMemory
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module DataMemory(
24
+ input clk,
25
+ input [31:0] DAddr,
26
+ input [31:0] DataIn,
27
+ input RD, // �����ƣ�1��Ч
28
+ input WR, // д���ƣ�1��Ч
29
+ output [31:0] DataOut // ����32���
30
+ );
31
+
32
+ reg [7:0] RAM [0:63]; // ÿ���ڴ浥ԪΪ8λ����һ���ֽ�
33
+
34
+ /* �� */
35
+ assign DataOut[7:0] = (RD==1) ? RAM[DAddr+3] : 8'bz;
36
+ assign DataOut[15:8] = (RD==1) ? RAM[DAddr+2] : 8'bz;
37
+ assign DataOut[23:16] = (RD==1) ? RAM[DAddr+1] : 8'bz;
38
+ assign DataOut[31:24] = (RD==1) ? RAM[DAddr+0] : 8'bz;
39
+
40
+ /* д */
41
+ always @(negedge clk) begin
42
+ if(WR == 1) begin
43
+ RAM[DAddr+0] <= DataIn[31:24];
44
+ RAM[DAddr+1] <= DataIn[23:16];
45
+ RAM[DAddr+2] <= DataIn[15:8];
46
+ RAM[DAddr+3] <= DataIn[7:0];
47
+ end
48
+ end
49
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Four_LED.v ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/18 20:39:17
7
+ // Design Name:
8
+ // Module Name: Four_LED
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Four_LED(
24
+ input clock,
25
+ input reset,
26
+ input [3:0] hex0,
27
+ input [3:0] hex1,
28
+ input [3:0] hex2,
29
+ input [3:0] hex3,
30
+ output reg [3:0] enable,
31
+ output [7:0] dispcode // �߶�����ܵ�����
32
+ );
33
+
34
+ wire clk_sys;
35
+ wire [1:0] count;
36
+ wire [3:0] hex_num;
37
+
38
+ clk_div clk_div(
39
+ .clk(clock),
40
+ .clk_sys(clk_sys)
41
+ );
42
+ Counter4 Counter4(
43
+ .clk(clk_sys),
44
+ .count(count)
45
+ );
46
+ Hex_To_7Seg Hex_To_7Seg(
47
+ .hex(hex_num),
48
+ .dispcode(dispcode)
49
+ );
50
+ Mux4_4bits Mux4_4bits(
51
+ .choice(count),
52
+ .in0(hex0), .in1(hex1), .in2(hex2), .in3(hex3),
53
+ .out(hex_num)
54
+ );
55
+
56
+ always @(count) begin
57
+ case(count)
58
+ 2'b00: enable = 4'b1110;
59
+ 2'b01: enable = 4'b1101;
60
+ 2'b10: enable = 4'b1011;
61
+ 2'b11: enable = 4'b0111;
62
+ endcase
63
+ end
64
+
65
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Hex_To_7Seg.v ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/18 20:47:40
7
+ // Design Name:
8
+ // Module Name: Hex_To_7Seg
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Hex_To_7Seg(
24
+ input [3:0] hex,
25
+ output reg [7:0] dispcode
26
+ );
27
+
28
+ always @(hex) begin
29
+ // '0'- ���ƣ�'1'- Ϩ��
30
+ // [7:0] �����ң�DP,g,f,e,d,c,b,a
31
+ case(hex)
32
+ 4'h0: dispcode <= 8'b1100_0000; //0
33
+ 4'h1: dispcode <= 8'b1111_1001; //1
34
+ 4'h2: dispcode <= 8'b1010_0100; //2
35
+ 4'h3: dispcode <= 8'b1011_0000; //3
36
+ 4'h4: dispcode <= 8'b1001_1001; //4
37
+ 4'h5: dispcode <= 8'b1001_0010; //5
38
+ 4'h6: dispcode <= 8'b1000_0010; //6
39
+ 4'h7: dispcode <= 8'b1101_1000; //7
40
+ 4'h8: dispcode <= 8'b1000_0000; //8
41
+ 4'h9: dispcode <= 8'b1001_0000; //9
42
+ 4'hA: dispcode <= 8'b1000_1000; //A
43
+ 4'hB: dispcode <= 8'b1000_0011; //b
44
+ 4'hC: dispcode <= 8'b1100_0110; //C
45
+ 4'hD: dispcode <= 8'b1010_0001; //d
46
+ 4'hE: dispcode <= 8'b1000_0110; //E
47
+ 4'hF: dispcode <= 8'b1000_1110; //F
48
+ default: dispcode <= 8'b0000_0000; // ����
49
+ endcase
50
+ end
51
+
52
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/IR.v ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/13 16:52:35
7
+ // Design Name:
8
+ // Module Name: IR
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module IR(
24
+ input clk,
25
+ input IRWre,
26
+ input [31:0] insIn,
27
+ output reg [31:0] insOut
28
+ );
29
+
30
+ always @(negedge clk) begin
31
+ /*if(IRWre==1)*/ insOut <= insIn;
32
+ /* else insOut <= insOut;*/
33
+ end
34
+
35
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/ImmediateExtend.v ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/11 19:21:36
7
+ // Design Name:
8
+ // Module Name: ImmediateExtend
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module ImmediateExtend(
24
+ input [15:0] original,
25
+ input ExtSel, // 0: Zero-extend; 1: Sign-extend.
26
+ output reg [31:0] extended
27
+ );
28
+
29
+ always @(*) begin
30
+ extended[15:0] <= original; // ??16��???????
31
+ if(ExtSel == 0) begin // Zero-extend ?????
32
+ extended[31:16] <= 0;
33
+ end
34
+ else begin // Sign-extended ???????
35
+ if(original[15] == 0) extended[31:16] <= 0;
36
+ else extended[31:16] <= 16'hFFFF;
37
+ end
38
+ end
39
+
40
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/InstructionMemory.v ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/11 19:17:34
7
+ // Design Name:
8
+ // Module Name: InstructionMemory
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module InstructionMemory(
24
+ input [31:0] IAddr,
25
+ //input [31:0] IDataIn,
26
+ //input RW, // ָ��洢����д�����źţ�Ϊ0д��Ϊ1��
27
+ output [31:0] IDataOut
28
+ );
29
+
30
+ reg [7:0] ROM [0:127];
31
+
32
+ initial begin
33
+ $readmemb("E:/_Vivado/MIPS_CPU_Design/MultiCycleCPU/test_instructions.txt", ROM);
34
+ end
35
+
36
+ assign IDataOut[31:24] = ROM[IAddr+0];
37
+ assign IDataOut[23:16] = ROM[IAddr+1];
38
+ assign IDataOut[15:8] = ROM[IAddr+2];
39
+ assign IDataOut[7:0] = ROM[IAddr+3];
40
+
41
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Mux2_32bits.v ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/11 19:31:00
7
+ // Design Name:
8
+ // Module Name: Mux2_32bits
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Mux2_32bits(
24
+ input choice,
25
+ input [31:0] in0,
26
+ input [31:0] in1,
27
+ output [31:0] out
28
+ );
29
+
30
+ assign out = (choice==0) ? in0 : in1;
31
+
32
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Mux4_16bits.v ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/18 20:40:56
7
+ // Design Name:
8
+ // Module Name: Mux4_16bits
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Mux4_16bits(
24
+ input [1:0] choice,
25
+ input [15:0] in0,
26
+ input [15:0] in1,
27
+ input [15:0] in2,
28
+ input [15:0] in3,
29
+ output reg [15:0] out
30
+ );
31
+
32
+ always @(choice or in0 or in1 or in2 or in3) begin
33
+ case(choice)
34
+ 2'b00: out = in0;
35
+ 2'b01: out = in1;
36
+ 2'b10: out = in2;
37
+ 2'b11: out = in3;
38
+ default: out = 0;
39
+ endcase
40
+ end
41
+
42
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Mux4_32bits.v ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/11 19:27:41
7
+ // Design Name:
8
+ // Module Name: Mux4_32bits
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Mux4_32bits(
24
+ input [1:0] choice,
25
+ input [31:0] in0,
26
+ input [31:0] in1,
27
+ input [31:0] in2,
28
+ input [31:0] in3,
29
+ output reg [31:0] out
30
+ );
31
+
32
+ always @(choice or in0 or in1 or in2 or in3) begin
33
+ case(choice)
34
+ 2'b00: out = in0;
35
+ 2'b01: out = in1;
36
+ 2'b10: out = in2;
37
+ 2'b11: out = in3;
38
+ default: out = 0;
39
+ endcase
40
+ end
41
+
42
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Mux4_4bits.v ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/18 20:48:38
7
+ // Design Name:
8
+ // Module Name: Mux4_4bits
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Mux4_4bits(
24
+ input [1:0] choice,
25
+ input [3:0] in0, in1, in2, in3,
26
+ output reg [3:0] out
27
+ );
28
+
29
+ always @(*) begin
30
+ case(choice)
31
+ 0: out <= in0;
32
+ 1: out <= in1;
33
+ 2: out <= in2;
34
+ 3: out <= in3;
35
+ endcase
36
+ end
37
+
38
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/Mux4_5bits.v ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/11 19:28:44
7
+ // Design Name:
8
+ // Module Name: Mux4_5bits
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Mux4_5bits(
24
+ input [1:0] choice,
25
+ input [4:0] in0, in1, in2, in3,
26
+ output reg [4:0] out
27
+ );
28
+
29
+ always @(*) begin
30
+ case(choice)
31
+ 0: out <= in0;
32
+ 1: out <= in1;
33
+ 2: out <= in2;
34
+ 3: out <= in3;
35
+ endcase
36
+ end
37
+
38
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/PC.v ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/11 19:22:47
7
+ // Design Name:
8
+ // Module Name: PC
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module PC(
24
+ input clk,
25
+ input Reset,
26
+ input PCWre,
27
+ input [31:0] nextIAddr,
28
+ output reg [31:0] currentIAddr
29
+ );
30
+
31
+ initial currentIAddr <= 0;
32
+
33
+ always @(posedge clk or negedge Reset) begin
34
+ if(Reset == 0) currentIAddr <= 0;
35
+ else begin
36
+ if(PCWre == 1) currentIAddr <= nextIAddr;
37
+ else currentIAddr <= currentIAddr;
38
+ end
39
+ end
40
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/RegisterFile.v ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/11 19:19:48
7
+ // Design Name:
8
+ // Module Name: RegisterFile
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module RegisterFile(
24
+ input clk,
25
+ input Reset,
26
+ input WE, // �Ĵ�����дʹ�ܣ�1Ϊ��Ч
27
+ input [4:0] ReadReg1,
28
+ input [4:0] ReadReg2,
29
+ input [4:0] WriteReg,
30
+ input [31:0] WriteData,
31
+ output [31:0] ReadData1,
32
+ output [31:0] ReadData2
33
+ );
34
+
35
+ reg [31:0] file [1:31];
36
+ integer i;
37
+
38
+ assign ReadData1 = (ReadReg1 == 0) ? 0 : file[ReadReg1];
39
+ assign ReadData2 = (ReadReg2 == 0) ? 0 : file[ReadReg2];
40
+
41
+ always @(negedge clk or negedge Reset) begin
42
+ if(Reset == 0) begin
43
+ for(i = 1; i <= 31; i=i+1) begin
44
+ file[i] <= 0;
45
+ end
46
+ end
47
+ else if(WE == 1 && WriteReg != 0)
48
+ file[WriteReg] <= WriteData;
49
+ end
50
+
51
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/clk_div.v ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/18 20:46:27
7
+ // Design Name:
8
+ // Module Name: clk_div
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module clk_div(
24
+ input clk,
25
+ output reg clk_sys = 0
26
+ );
27
+
28
+ reg [25:0] div_counter = 0;
29
+ always @(posedge clk) begin
30
+ if(div_counter >= 50000) begin
31
+ clk_sys <= ~clk_sys;
32
+ div_counter <= 0;
33
+ end
34
+ else div_counter <= div_counter + 1;
35
+ end
36
+
37
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/MultiCycleCPU.srcs/sources_1/new/top_CPU.v ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/12/13 16:57:32
7
+ // Design Name:
8
+ // Module Name: top_CPU
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module top_CPU(
24
+ input clk,
25
+ input Reset,
26
+ output [31:0] currentIAddr, nextIAddr,
27
+ output [4:0] rs, rt,
28
+ output [31:0] ReadData1, ReadData2,
29
+ output [31:0] ALU_result, DataBus
30
+ );
31
+ /* ��������ͨ· */
32
+ wire [31:0] bincode, IDataOut;
33
+ wire [31:0] ALU_inA, ALU_inB;
34
+ wire [31:0] DataOut;
35
+ wire [5:0] opcode;
36
+ wire ALU_zero, ALU_sign;
37
+ wire [15:0] immediate;
38
+ wire [31:0] extended;
39
+ wire [31:0] ADR_out, BDR_out, ALUoutDR_out, DataBus_before;
40
+ wire [4:0] rd;
41
+
42
+ assign opcode = bincode[31:26];
43
+ assign rs = bincode[25:21];
44
+ assign rt = bincode[20:16];
45
+ assign rd = bincode[15:11];
46
+ assign immediate = bincode[15:0];
47
+
48
+ /* �����ź� */
49
+ wire PCWre, ALUSrcA, ALUSrcB, DBDataSrc, RegWre, WrRegDSrc, InsMemRW, mRD, mWR, IRWre, ExtSel;
50
+ wire [1:0] PCSrc;
51
+ wire [1:0] RegDst;
52
+ wire [2:0] ALUOp;
53
+ wire [5:0] WriteReg;
54
+ wire [31:0] WriteData;
55
+
56
+ /* CPU�Ĺؼ����� */
57
+ ControlUnit ControlUnit(
58
+ .clk(clk), .rst(Reset),
59
+ .zero(ALU_zero), .sign(ALU_sign),
60
+ .opcode(opcode),
61
+ .PCWre(PCWre), .ALUSrcA(ALUSrcA), .ALUSrcB(ALUSrcB), .DBDataSrc(DBDataSrc), .RegWre(RegWre), .WrRegDSrc(WrRegDSrc), .InsMemRW(InsMemRW), .mRD(mRD), .mWR(mWR), .IRWre(IRWre), .ExtSel(ExtSel),
62
+ .PCSrc(PCSrc),
63
+ .RegDst(RegDst),
64
+ .ALUOp(ALUOp)
65
+ );
66
+ PC PC(
67
+ .clk(clk), .Reset(Reset), .PCWre(PCWre), .nextIAddr(nextIAddr),
68
+ .currentIAddr(currentIAddr)
69
+ );
70
+ InstructionMemory InstructionMemory(
71
+ .IAddr(currentIAddr),
72
+ .IDataOut(IDataOut)
73
+ );
74
+ RegisterFile RegisterFile(
75
+ .clk(clk), .Reset(Reset), .WE(RegWre),
76
+ .ReadReg1(rs), .ReadReg2(rt), .WriteReg(WriteReg), .WriteData(WriteData),
77
+ .ReadData1(ReadData1), .ReadData2(ReadData2)
78
+ );
79
+ ALU ALU(
80
+ .ALUOp(ALUOp), .A(ALU_inA), .B(ALU_inB),
81
+ .result(ALU_result), .zero(ALU_zero), .sign(ALU_sign)
82
+ );
83
+ DataMemory DataMemory(
84
+ .clk(clk), .DAddr(ALU_result), .DataIn(ReadData2), .RD(mRD), .WR(mWR),
85
+ .DataOut(DataOut)
86
+ );
87
+ ImmediateExtend ImmediateExtend(
88
+ .original(immediate), .ExtSel(ExtSel),
89
+ .extended(extended)
90
+ );
91
+
92
+ /* ������CPU���еļĴ��� */
93
+ IR IR(
94
+ .clk(clk), .IRWre(IRWre), .insIn(IDataOut),
95
+ .insOut(bincode)
96
+ );
97
+ DFF_32bits ADR(
98
+ .clk(clk), .Reset(Reset), .in(ReadData1),
99
+ .out(ADR_out)
100
+ );
101
+ DFF_32bits BDR(
102
+ .clk(clk), .Reset(Reset), .in(ReadData2),
103
+ .out(BDR_out)
104
+ );
105
+ DFF_32bits ALUoutDR(
106
+ .clk(clk), .Reset(Reset), .in(ALU_result),
107
+ .out(ALUoutDR_out)
108
+ );
109
+ DFF_32bits DBDR(
110
+ .clk(clk), .Reset(Reset), .in(DataBus_before),
111
+ .out(DataBus)
112
+ );
113
+ /* ����ѡ���� */
114
+ Mux4_32bits Mux_nextIAddr(
115
+ .choice(PCSrc), .in0(currentIAddr+4), .in1(currentIAddr+4+(extended<<2)), .in2(ReadData1), .in3({currentIAddr[31:28], bincode[25:0], 2'b00}),
116
+ .out(nextIAddr)
117
+ );
118
+ Mux4_5bits Mux_WriteReg(
119
+ .choice(RegDst), .in0(5'd31), .in1(rt), .in2(rd), .in3(5'bzzzzz),
120
+ .out(WriteReg)
121
+ );
122
+ Mux2_32bits Mux_WriteData(
123
+ .choice(WrRegDSrc), .in0(currentIAddr+4), .in1(DataBus),
124
+ .out(WriteData)
125
+ );
126
+ Mux2_32bits Mux_ALU_inA(
127
+ .choice(ALUSrcA), .in0(ADR_out), .in1({27'd0, immediate[10:6]}),
128
+ .out(ALU_inA)
129
+ );
130
+ Mux2_32bits Mux_ALU_inB(
131
+ .choice(ALUSrcB), .in0(BDR_out), .in1(extended),
132
+ .out(ALU_inB)
133
+ );
134
+ Mux2_32bits Mux_DBDR(
135
+ .choice(DBDataSrc), .in0(ALU_result), .in1(DataOut),
136
+ .out(DataBus_before)
137
+ );
138
+ endmodule
Jed-Z_computer-organization-lab/MultiCycleCPU/test_instructions.txt ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 00001000 00000001 00000000 00001000
2
+ 01001000 00000010 00000000 00000010
3
+ 01001100 01000011 00000000 00001000
4
+ 00000100 01100001 00100000 00000000
5
+ 01000000 10000010 00101000 00000000
6
+ 01100000 00000101 00101000 10000000
7
+ 11010000 10100001 11111111 11111110
8
+ 11101000 00000000 00000000 00010100
9
+ 10011101 10100001 01000000 00000000
10
+ 00001000 00001110 11111111 11111110
11
+ 10011101 00001110 01001000 00000000
12
+ 10011001 00101010 00000000 00000010
13
+ 10011001 01001011 00000000 00000000
14
+ 00000001 01101010 01011000 00000000
15
+ 11010101 01100010 11111111 11111110
16
+ 00001000 00001100 11111111 11111110
17
+ 00001001 10001100 00000000 00000001
18
+ 11011001 10000000 11111111 11111110
19
+ 01000100 01001100 00000000 00000010
20
+ 11100000 00000000 00000000 00010111
21
+ 11000000 00100010 00000000 00000100
22
+ 11000100 00101101 00000000 00000100
23
+ 11100111 11100000 00000000 00000000
24
+ 11111100 00000000 00000000 00000000
Jed-Z_computer-organization-lab/README.md ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 计算机组成原理实验(课程项目)
2
+
3
+ 使用 Verilog HDL 实现的简易单周期和多周期 CPU 设计。
4
+
5
+ * 中山大学计算机学院
6
+ * 操作系统原理实验(Laboratory of Computer Organization, DCS209)
7
+ * 教师:何朝东
8
+ * 2018-2019 学年第一学期(大二上)
9
+
10
+
11
+ ## 目录说明
12
+
13
+ 这些文件是从 Vivado 2018.1 的工程中提取的,仅保留了`.srcs`目录。
14
+
15
+ * [MultiCycleCPU](MultiCycleCPU):多周期 CPU 设计与实现。
16
+ * [SingleCycleCPU](SingleCycleCPU):单周期 CPU 设计与实现。
17
+ * [hex_to_7seg](hex_to_7seg):子模块,作用是将十六进制数转换为可供七段数码管显示的编码。
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sim_1/new/CPU_sim_1.v ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/14 15:44:41
7
+ // Design Name:
8
+ // Module Name: CPU_sim_1
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module CPU_sim_1;
24
+ reg clk, Reset;
25
+ wire [31:0] currentIAddr, nextIAddr;
26
+ wire [4:0] rs, rt;
27
+ wire [31:0] ReadData1, ReadData2;
28
+ wire [31:0] ALU_result, DataBus;
29
+
30
+ top_CPU uut(
31
+ .clk(clk),
32
+ .Reset(Reset),
33
+ .currentIAddr(currentIAddr), .nextIAddr(nextIAddr),
34
+ .rs(rs), .rt(rt),
35
+ .ReadData1(ReadData1), .ReadData2(ReadData2),
36
+ .ALU_result(ALU_result), .DataBus(DataBus)
37
+ );
38
+
39
+ always #50 clk = ~clk; // ����ʱ������Ϊ100ns
40
+
41
+ initial begin
42
+ clk = 1;
43
+ Reset = 0;
44
+ #25;
45
+ Reset = 1; // ��ʼ����
46
+ #3000; // ����3000ns���
47
+ #100; $stop; // �ϵ�
48
+ end
49
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/ALU.v ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/12 14:47:50
7
+ // Design Name:
8
+ // Module Name: ALU
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module ALU(
24
+ input [2:0] ALUOp,
25
+ input [31:0] A,
26
+ input [31:0] B,
27
+ output reg [31:0] result,
28
+ output zero, // ����Ƿ�Ϊ0����Ϊ1����Ϊ0
29
+ output sign // ����Ƿ�Ϊ������Ϊ1����Ϊ0
30
+ );
31
+
32
+ assign zero = (result == 0) ? 1 : 0;
33
+ assign sign = result[31];
34
+
35
+ always @(ALUOp or A or B) begin
36
+ case(ALUOp)
37
+ 3'b000: result = A + B;
38
+ 3'b001: result = A - B;
39
+ 3'b010: result = B << A;
40
+ 3'b011: result = A | B;
41
+ 3'b100: result = A & B;
42
+ 3'b101: result = (A < B) ? 1 : 0; // 5: �Ƚ��޷�����
43
+ 3'b110: begin // 6: �Ƚϴ�������
44
+ if((A[31] == B[31]) && (A < B)) result = 1;
45
+ else if(A[31]==1 && B[31]==0) result = 1;
46
+ else result = 0;
47
+ end
48
+ 3'b111: result = A ^ B;
49
+ endcase
50
+ end
51
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Basys3_CPU.v ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/16 22:11:31
7
+ // Design Name:
8
+ // Module Name: Basys3_CPU
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Basys3_CPU(
24
+ input basys3_clock,
25
+ input reset_sw,
26
+ input [1:0] SW_in,
27
+ input next_button,
28
+ output [3:0] enable,
29
+ output [7:0] dispcode
30
+ );
31
+
32
+ wire [31:0] currentIAddr, nextIAddr;
33
+ wire [4:0] rs, rt;
34
+ wire [31:0] ReadData1, ReadData2;
35
+ wire [31:0] ALU_result, DataBus;
36
+
37
+ wire next_signal; // ��������ֶ������ź�
38
+ wire [15:0] DisplayData;
39
+
40
+ top_CPU top_CPU(
41
+ .clk(next_signal), // ȡ����ʹ�ð��°�ť�ṩ�͵�ƽ���ɿ���PC�ŵ���
42
+ .Reset(reset_sw),
43
+ .currentIAddr(currentIAddr), .nextIAddr(nextIAddr),
44
+ .rs(rs), .rt(rt),
45
+ .ReadData1(ReadData1), .ReadData2(ReadData2),
46
+ .ALU_result(ALU_result), .DataBus(DataBus)
47
+ );
48
+
49
+ Four_LED Four_LED(
50
+ .clock(basys3_clock),
51
+ .reset(reset_sw),
52
+ .hex3(DisplayData[15:12]),
53
+ .hex2(DisplayData[11:8]),
54
+ .hex1(DisplayData[7:4]),
55
+ .hex0(DisplayData[3:0]),
56
+ .enable(enable),
57
+ .dispcode(dispcode)
58
+ );
59
+
60
+ Mux4_16bits Mux4_16bits(
61
+ .choice(SW_in),
62
+ .in0({currentIAddr[7:0], nextIAddr[7:0]}),
63
+ .in1({3'b000, rs, ReadData1[7:0]}),
64
+ .in2({3'b000, rt, ReadData2[7:0]}),
65
+ .in3({ALU_result[7:0], DataBus[7:0]}),
66
+ .out(DisplayData)
67
+ );
68
+
69
+ Button_Debounce Button_Debounce(
70
+ .clk(basys3_clock),
71
+ .btn_in(next_button),
72
+ .btn_out(next_signal)
73
+ );
74
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Button_Debounce.v ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/16 23:55:36
7
+ // Design Name:
8
+ // Module Name: Button_Debounce
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Button_Debounce(
24
+ input clk,
25
+ input btn_in,
26
+ output btn_out
27
+ );
28
+
29
+ reg [2:0] btn=0;
30
+ wire clk_20ms;
31
+
32
+ ClockDivisor #(1000000) t_20ms(clk,clk_20ms);
33
+
34
+ always @(posedge clk_20ms) begin
35
+ btn[0]<=btn_in;
36
+ btn[1]<=btn[0];
37
+ btn[2]<=btn[1];
38
+ end
39
+ assign btn_out=(btn[2]&btn[1]&btn[0])|(~btn[2]&btn[1]&btn[0]);
40
+ endmodule
41
+
42
+
43
+ module ClockDivisor(
44
+ input clkin,
45
+ output reg clkout=0
46
+ );
47
+ parameter n=50000000;
48
+ reg [31:0] count=1;
49
+ always @ (posedge clkin)
50
+ begin
51
+ if(count<n)
52
+ count<=count+1;
53
+ else
54
+ begin
55
+ count<=1;
56
+ clkout<=~clkout;
57
+ end
58
+ end
59
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/ControlUnit.v ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/14 13:49:51
7
+ // Design Name:
8
+ // Module Name: ControlUnit
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module ControlUnit(
24
+ input [5:0] opcode,
25
+ input zero,
26
+ input sign,
27
+ output reg PCWre,
28
+ output reg ALUSrcA,
29
+ output reg ALUSrcB,
30
+ output reg DBDataSrc,
31
+ output reg RegWre,
32
+ output reg InsMemRW,
33
+ output reg mRD,
34
+ output reg mWR,
35
+ output reg RegDst,
36
+ output reg ExtSel,
37
+ output reg [1:0] PCSrc,
38
+ output reg [2:0] ALUOp
39
+ );
40
+
41
+ always @(opcode or zero or sign) begin
42
+ case(opcode)
43
+ 6'b000000: begin // add
44
+ PCWre <= 1;
45
+ {ALUSrcA, ALUSrcB, DBDataSrc, RegWre, InsMemRW, mRD, mWR, RegDst, ExtSel} <= 9'b000110010;
46
+ {PCSrc[1:0], ALUOp[2:0]} <= 5'b00_000;
47
+ end
48
+ 6'b000001: begin // sub
49
+ PCWre <= 1;
50
+ {ALUSrcA, ALUSrcB, DBDataSrc, RegWre, InsMemRW, mRD, mWR, RegDst, ExtSel} <= 9'b000110010;
51
+ {PCSrc[1:0], ALUOp[2:0]} <= 5'b00_001;
52
+ end
53
+ 6'b000010: begin // addiu
54
+ PCWre <= 1;
55
+ {ALUSrcA, ALUSrcB, DBDataSrc, RegWre, InsMemRW, mRD, mWR, RegDst, ExtSel} <= 9'b010110001;
56
+ {PCSrc[1:0], ALUOp[2:0]} <= 5'b00_000;
57
+ end
58
+ 6'b010000: begin // andi
59
+ PCWre <= 1;
60
+ {ALUSrcA, ALUSrcB, DBDataSrc, RegWre, InsMemRW, mRD, mWR, RegDst, ExtSel} <= 9'b010110000;
61
+ {PCSrc[1:0], ALUOp[2:0]} <= 5'b00_100;
62
+ end
63
+ 6'b010001: begin // and
64
+ PCWre <= 1;
65
+ {ALUSrcA, ALUSrcB, DBDataSrc, RegWre, InsMemRW, mRD, mWR, RegDst, ExtSel} <= 9'b000110010;
66
+ {PCSrc[1:0], ALUOp[2:0]} <= 5'b00_100;
67
+ end
68
+ 6'b010010: begin // ori
69
+ PCWre <= 1;
70
+ {ALUSrcA, ALUSrcB, DBDataSrc, RegWre, InsMemRW, mRD, mWR, RegDst, ExtSel} <= 9'b010110000;
71
+ {PCSrc[1:0], ALUOp[2:0]} <= 5'b00_011;
72
+ end
73
+ 6'b010011: begin // or
74
+ PCWre <= 1;
75
+ {ALUSrcA, ALUSrcB, DBDataSrc, RegWre, InsMemRW, mRD, mWR, RegDst, ExtSel} <= 9'b000110010;
76
+ {PCSrc[1:0], ALUOp[2:0]} <= 5'b00_011;
77
+ end
78
+ 6'b011000: begin // sll
79
+ PCWre <= 1;
80
+ {ALUSrcA, ALUSrcB, DBDataSrc, RegWre, InsMemRW, mRD, mWR, RegDst, ExtSel} <= 9'b100110010;
81
+ {PCSrc[1:0], ALUOp[2:0]} <= 5'b00_010;
82
+ end
83
+ 6'b011100: begin // slti
84
+ PCWre <= 1;
85
+ {ALUSrcA, ALUSrcB, DBDataSrc, RegWre, InsMemRW, mRD, mWR, RegDst, ExtSel} <= 9'b010110001;
86
+ {PCSrc[1:0], ALUOp[2:0]} <= 5'b00_110;
87
+ end
88
+ 6'b100110: begin // sw
89
+ PCWre <= 1;
90
+ {ALUSrcA, ALUSrcB, DBDataSrc, RegWre, InsMemRW, mRD, mWR, RegDst, ExtSel} <= 9'b010010101;
91
+ {PCSrc[1:0], ALUOp[2:0]} <= 5'b00_000;
92
+ end
93
+ 6'b100111: begin // lw
94
+ PCWre <= 1;
95
+ {ALUSrcA, ALUSrcB, DBDataSrc, RegWre, InsMemRW, mRD, mWR, RegDst, ExtSel} <= 9'b011111001;
96
+ {PCSrc[1:0], ALUOp[2:0]} <= 5'b00_000;
97
+ end
98
+ 6'b110000: begin // beq
99
+ PCWre <= 1;
100
+ {ALUSrcA, ALUSrcB, DBDataSrc, RegWre, InsMemRW, mRD, mWR, RegDst, ExtSel} <= 9'b000010001;
101
+ PCSrc[1:0] <= (zero==1) ? 2'b01 : 2'b00;
102
+ ALUOp[2:0] <= 3'b001;
103
+ end
104
+ 6'b110001: begin // bne
105
+ PCWre <= 1;
106
+ {ALUSrcA, ALUSrcB, DBDataSrc, RegWre, InsMemRW, mRD, mWR, RegDst, ExtSel} <= 9'b000010001;
107
+ PCSrc[1:0] <= (zero==0) ? 2'b01 : 2'b00;
108
+ ALUOp[2:0] <= 3'b001;
109
+ end
110
+ 6'b110010: begin // bltz
111
+ PCWre <= 1;
112
+ {ALUSrcA, ALUSrcB, DBDataSrc, RegWre, InsMemRW, mRD, mWR, RegDst, ExtSel} <= 9'b000010001;
113
+ PCSrc[1:0] <= (sign==1) ? 2'b01 : 2'b00;
114
+ ALUOp[2:0] <= 3'b000;
115
+ end
116
+ 6'b111000: begin // j
117
+ PCWre <= 1;
118
+ {ALUSrcA, ALUSrcB, DBDataSrc, RegWre, InsMemRW, mRD, mWR, RegDst, ExtSel} <= 9'b000010000;
119
+ {PCSrc[1:0], ALUOp[2:0]} <= 5'b10_000;
120
+ end
121
+ 6'b111111: begin // halt
122
+ PCWre <= 0;
123
+ {ALUSrcA, ALUSrcB, DBDataSrc, RegWre, InsMemRW, mRD, mWR, RegDst, ExtSel} <= 9'b000010000;
124
+ {PCSrc[1:0], ALUOp[2:0]} <= 5'b11_000;
125
+ end
126
+ endcase
127
+ end
128
+
129
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Counter4.v ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/15 14:03:28
7
+ // Design Name:
8
+ // Module Name: Counter4
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Counter4(
24
+ input clk,
25
+ output reg [1:0] count
26
+ );
27
+
28
+ always @(posedge clk) begin
29
+ if(count == 2'b11) count <= 0;
30
+ else count <= count + 1;
31
+ end
32
+
33
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/DataMemory.v ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/12 15:08:38
7
+ // Design Name:
8
+ // Module Name: DataMemory
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module DataMemory(
24
+ input clk,
25
+ input [31:0] DAddr,
26
+ input [31:0] DataIn,
27
+ input RD, // �����ƣ�1��Ч
28
+ input WR, // д���ƣ�1��Ч
29
+ output [31:0] DataOut // ����32���
30
+ );
31
+
32
+ reg [7:0] RAM [0:63]; // ÿ���ڴ浥ԪΪ8λ����һ���ֽ�
33
+
34
+ /* �� */
35
+ assign DataOut[7:0] = (RD==1) ? RAM[DAddr+3] : 8'bz;
36
+ assign DataOut[15:8] = (RD==1) ? RAM[DAddr+2] : 8'bz;
37
+ assign DataOut[23:16] = (RD==1) ? RAM[DAddr+1] : 8'bz;
38
+ assign DataOut[31:24] = (RD==1) ? RAM[DAddr+0] : 8'bz;
39
+
40
+ /* д */
41
+ always @(negedge clk) begin
42
+ if(WR == 1) begin
43
+ RAM[DAddr+0] <= DataIn[31:24];
44
+ RAM[DAddr+1] <= DataIn[23:16];
45
+ RAM[DAddr+2] <= DataIn[15:8];
46
+ RAM[DAddr+3] <= DataIn[7:0];
47
+ end
48
+ end
49
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Four_LED.v ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/15 17:29:57
7
+ // Design Name:
8
+ // Module Name: top_LEDs
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Four_LED(
24
+ input clock,
25
+ input reset,
26
+ input [3:0] hex0,
27
+ input [3:0] hex1,
28
+ input [3:0] hex2,
29
+ input [3:0] hex3,
30
+ output reg [3:0] enable,
31
+ output [7:0] dispcode // �߶�����ܵ�����
32
+ );
33
+
34
+ wire clk_sys;
35
+ wire [1:0] count;
36
+ wire [3:0] hex_num;
37
+
38
+ clk_div clk_div(
39
+ .clk(clock),
40
+ .clk_sys(clk_sys)
41
+ );
42
+ Counter4 Counter4(
43
+ .clk(clk_sys),
44
+ .count(count)
45
+ );
46
+ Hex_To_7Seg Hex_To_7Seg(
47
+ .hex(hex_num),
48
+ .dispcode(dispcode)
49
+ );
50
+ Mux4_4bits Mux4_4bits(
51
+ .choice(count),
52
+ .in0(hex0), .in1(hex1), .in2(hex2), .in3(hex3),
53
+ .out(hex_num)
54
+ );
55
+
56
+ always @(count) begin
57
+ case(count)
58
+ 2'b00: enable = 4'b1110;
59
+ 2'b01: enable = 4'b1101;
60
+ 2'b10: enable = 4'b1011;
61
+ 2'b11: enable = 4'b0111;
62
+ endcase
63
+ end
64
+
65
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Hex_To_7Seg.v ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/15 13:52:22
7
+ // Design Name:
8
+ // Module Name: Hex_To_7Seg
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Hex_To_7Seg(
24
+ input [3:0] hex,
25
+ output reg [7:0] dispcode
26
+ );
27
+
28
+ always @(hex) begin
29
+ // '0'- ���ƣ�'1'- Ϩ��
30
+ // [7:0] �����ң�DP,g,f,e,d,c,b,a
31
+ case(hex)
32
+ 4'h0: dispcode <= 8'b1100_0000; //0
33
+ 4'h1: dispcode <= 8'b1111_1001; //1
34
+ 4'h2: dispcode <= 8'b1010_0100; //2
35
+ 4'h3: dispcode <= 8'b1011_0000; //3
36
+ 4'h4: dispcode <= 8'b1001_1001; //4
37
+ 4'h5: dispcode <= 8'b1001_0010; //5
38
+ 4'h6: dispcode <= 8'b1000_0010; //6
39
+ 4'h7: dispcode <= 8'b1101_1000; //7
40
+ 4'h8: dispcode <= 8'b1000_0000; //8
41
+ 4'h9: dispcode <= 8'b1001_0000; //9
42
+ 4'hA: dispcode <= 8'b1000_1000; //A
43
+ 4'hB: dispcode <= 8'b1000_0011; //b
44
+ 4'hC: dispcode <= 8'b1100_0110; //C
45
+ 4'hD: dispcode <= 8'b1010_0001; //d
46
+ 4'hE: dispcode <= 8'b1000_0110; //E
47
+ 4'hF: dispcode <= 8'b1000_1110; //F
48
+ default: dispcode <= 8'b0000_0000; // ����
49
+ endcase
50
+ end
51
+
52
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/ImmediateExtend.v ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/13 19:57:33
7
+ // Design Name:
8
+ // Module Name: ImmediateExtend
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module ImmediateExtend(
24
+ input [15:0] original,
25
+ input ExtSel, // 0: Zero-extend; 1: Sign-extend.
26
+ output reg [31:0] extended
27
+ );
28
+
29
+ always @(*) begin
30
+ extended[15:0] <= original; // ��16λ���ֲ���
31
+ if(ExtSel == 0) begin // Zero-extend ����չ
32
+ extended[31:16] <= 0;
33
+ end
34
+ else begin // Sign-extended ������չ
35
+ if(original[15] == 0) extended[31:16] <= 0;
36
+ else extended[31:16] <= 16'hFFFF;
37
+ end
38
+ end
39
+
40
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/InstructionMemory.v ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/12 16:38:30
7
+ // Design Name:
8
+ // Module Name: InstructionMemory
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module InstructionMemory(
24
+ input [31:0] IAddr,
25
+ //input [31:0] IDataIn,
26
+ //input RW, // ָ��洢����д�����źţ�Ϊ0д��Ϊ1��
27
+ output [31:0] IDataOut
28
+ );
29
+
30
+ reg [7:0] ROM [0:95];
31
+
32
+ initial begin
33
+ $readmemb("E:/_Vivado/MIPS_CPU_Design/SingleCycleCPU/test_instructions.txt", ROM);
34
+ end
35
+
36
+ assign IDataOut[31:24] = ROM[IAddr+0];
37
+ assign IDataOut[23:16] = ROM[IAddr+1];
38
+ assign IDataOut[15:8] = ROM[IAddr+2];
39
+ assign IDataOut[7:0] = ROM[IAddr+3];
40
+ // always @(RW or Iaddr) begin
41
+ // if(RW == 1) begin
42
+ // IDataOut[31:24] <= ROM[Iaddr+0];
43
+ // IDataOut[23:16] <= ROM[Iaddr+1];
44
+ // IDataOut[15:8] <= ROM[Iaddr+2];
45
+ // IDataOut[7:0] <= ROM[Iaddr+3];
46
+ // end
47
+ // else begin
48
+ // ROM[Iaddr+0] <= IDataIn[31:24];
49
+ // ROM[Iaddr+1] <= IDataIn[23:16];
50
+ // ROM[Iaddr+2] <= IDataIn[15:8];
51
+ // ROM[Iaddr+3] <= IDataIn[7:0];
52
+ // end
53
+ // end
54
+
55
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Mux2_32bits.v ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/12 16:57:22
7
+ // Design Name:
8
+ // Module Name: Mux2_32bits
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Mux2_32bits(
24
+ input choice,
25
+ input [31:0] in0,
26
+ input [31:0] in1,
27
+ output [31:0] out
28
+ );
29
+
30
+ assign out = (choice==0) ? in0 : in1;
31
+
32
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Mux2_5bits.v ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/12 16:59:42
7
+ // Design Name:
8
+ // Module Name: Mux2_5bits
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Mux2_5bits(
24
+ input choice,
25
+ input [4:0] in0,
26
+ input [4:0] in1,
27
+ output [4:0] out
28
+ );
29
+
30
+ assign out = (choice==0) ? in0 : in1;
31
+
32
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Mux4_16bits.v ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/17 00:14:34
7
+ // Design Name:
8
+ // Module Name: Mux4_16bits
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Mux4_16bits(
24
+ input [1:0] choice,
25
+ input [15:0] in0,
26
+ input [15:0] in1,
27
+ input [15:0] in2,
28
+ input [15:0] in3,
29
+ output reg [15:0] out
30
+ );
31
+
32
+ always @(choice or in0 or in1 or in2 or in3) begin
33
+ case(choice)
34
+ 2'b00: out = in0;
35
+ 2'b01: out = in1;
36
+ 2'b10: out = in2;
37
+ 2'b11: out = in3;
38
+ default: out = 0;
39
+ endcase
40
+ end
41
+
42
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Mux4_32bits.v ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/14 13:56:31
7
+ // Design Name:
8
+ // Module Name: Mux4_32bits
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Mux4_32bits(
24
+ input [1:0] choice,
25
+ input [31:0] in0,
26
+ input [31:0] in1,
27
+ input [31:0] in2,
28
+ input [31:0] in3,
29
+ output reg [31:0] out
30
+ );
31
+
32
+ always @(choice or in0 or in1 or in2 or in3) begin
33
+ case(choice)
34
+ 2'b00: out = in0;
35
+ 2'b01: out = in1;
36
+ 2'b10: out = in2;
37
+ 2'b11: out = in3;
38
+ default: out = 0;
39
+ endcase
40
+ end
41
+
42
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/Mux4_4bits.v ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/15 14:00:50
7
+ // Design Name:
8
+ // Module Name: Mux4_8bits
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Mux4_4bits(
24
+ input [1:0] choice,
25
+ input [3:0] in0, in1, in2, in3,
26
+ output reg [3:0] out
27
+ );
28
+
29
+ always @(*) begin
30
+ case(choice)
31
+ 0: out <= in0;
32
+ 1: out <= in1;
33
+ 2: out <= in2;
34
+ 3: out <= in3;
35
+ endcase
36
+ end
37
+
38
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/PC.v ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/13 18:50:14
7
+ // Design Name:
8
+ // Module Name: PC
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module PC(
24
+ input clk,
25
+ input Reset,
26
+ input PCWre,
27
+ input [31:0] nextIAddr,
28
+ output reg [31:0] currentIAddr
29
+ );
30
+
31
+ initial currentIAddr <= 0;
32
+
33
+ always @(posedge clk or negedge Reset) begin
34
+ if(Reset == 0) currentIAddr <= 0;
35
+ else begin
36
+ if(PCWre == 1) currentIAddr <= nextIAddr;
37
+ else currentIAddr <= currentIAddr;
38
+ end
39
+ end
40
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/RegisterFile.v ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/12 15:40:53
7
+ // Design Name:
8
+ // Module Name: RegisterFile
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module RegisterFile(
24
+ input clk,
25
+ input Reset,
26
+ input WE, // �Ĵ�����дʹ�ܣ�1Ϊ��Ч
27
+ input [4:0] ReadReg1,
28
+ input [4:0] ReadReg2,
29
+ input [4:0] WriteReg,
30
+ input [31:0] WriteData,
31
+ output [31:0] ReadData1,
32
+ output [31:0] ReadData2
33
+ );
34
+
35
+ reg [31:0] file [1:31];
36
+ integer i;
37
+
38
+ assign ReadData1 = (ReadReg1 == 0) ? 0 : file[ReadReg1];
39
+ assign ReadData2 = (ReadReg2 == 0) ? 0 : file[ReadReg2];
40
+
41
+ always @(negedge clk or negedge Reset) begin
42
+ if(Reset == 0) begin
43
+ for(i = 1; i <= 31; i=i+1) begin
44
+ file[i] <= 0;
45
+ end
46
+ end
47
+ else if(WE == 1 && WriteReg != 0)
48
+ file[WriteReg] <= WriteData;
49
+ end
50
+
51
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/clk_div.v ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/15 14:08:04
7
+ // Design Name:
8
+ // Module Name: clk_div
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module clk_div(
24
+ input clk,
25
+ output reg clk_sys = 0
26
+ );
27
+
28
+ reg [25:0] div_counter = 0;
29
+ always @(posedge clk) begin
30
+ if(div_counter >= 50000) begin
31
+ clk_sys <= ~clk_sys;
32
+ div_counter <= 0;
33
+ end
34
+ else div_counter <= div_counter + 1;
35
+ end
36
+
37
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/SingleCycleCPU.srcs/sources_1/new/top_CPU.v ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/14 21:32:32
7
+ // Design Name:
8
+ // Module Name: top_CPU
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module top_CPU(
24
+ input clk,
25
+ input Reset,
26
+ output [31:0] currentIAddr, nextIAddr,
27
+ output [4:0] rs, rt,
28
+ output [31:0] ReadData1, ReadData2,
29
+ output [31:0] ALU_result, DataBus
30
+ );
31
+
32
+ wire [5:0] opcode;
33
+ wire [4:0] rd;
34
+ wire [15:0] immediate;
35
+
36
+ wire [31:0] bincode;
37
+ wire [31:0] extended;
38
+ wire PCWre, RegWre, RegDst, DBDataSrc, ALUSrcA, ALUSrcB, mRD, mWR, ExtSel;
39
+ wire [1:0] PCSrc;
40
+ wire [2:0] ALUOp;
41
+ wire ALU_zero, ALU_sign;
42
+ wire [5:0] WriteReg;
43
+ wire [31:0] WriteData;
44
+ wire [31:0] ALU_inA, ALU_inB;
45
+ wire [31:0] DataOut;
46
+
47
+ wire [31:0] next_in0, next_in1, next_in2;
48
+ assign opcode = bincode[31:26];
49
+ assign rs = bincode[25:21];
50
+ assign rt = bincode[20:16];
51
+ assign rd = bincode[15:11];
52
+ assign immediate = bincode[15:0];
53
+
54
+ assign next_in0 = currentIAddr + 4;
55
+ assign next_in1 = next_in0 + (extended<<2);
56
+ assign next_in2 = {currentIAddr[31:28], bincode[25:0], 2'b00};
57
+
58
+ assign DataBus = WriteData;
59
+ /* ���Ƶ�Ԫ */
60
+ ControlUnit ControlUnit(
61
+ .opcode(opcode), .zero(ALU_zero), .sign(ALU_sign),
62
+ .PCWre(PCWre), .ALUSrcA(ALUSrcA), .ALUSrcB(ALUSrcB), .DBDataSrc(DBDataSrc), .RegWre(RegWre), /*.InsMemRW(InsMemRW),*/ .mRD(mRD), .mWR(mWR), .RegDst(RegDst), .ExtSel(ExtSel),
63
+ .PCSrc(PCSrc), .ALUOp(ALUOp)
64
+ );
65
+
66
+ /* 5���ؼ��ײ�ģ�� */
67
+ PC PC(
68
+ .clk(clk), .Reset(Reset), .PCWre(PCWre), .nextIAddr(nextIAddr),
69
+ .currentIAddr(currentIAddr)
70
+ );
71
+ InstructionMemory InstructionMemory(
72
+ .IAddr(currentIAddr),
73
+ .IDataOut(bincode)
74
+ );
75
+ RegisterFile RegisterFile(
76
+ .clk(clk), .Reset(Reset), .WE(RegWre),
77
+ .ReadReg1(rs), .ReadReg2(rt), .WriteReg(WriteReg), .WriteData(WriteData),
78
+ .ReadData1(ReadData1), .ReadData2(ReadData2)
79
+ );
80
+ ALU ALU(
81
+ .ALUOp(ALUOp), .A(ALU_inA), .B(ALU_inB),
82
+ .result(ALU_result), .zero(ALU_zero), .sign(ALU_sign)
83
+ );
84
+ DataMemory DataMemory(
85
+ .clk(clk), .DAddr(ALU_result), .DataIn(ReadData2), .RD(mRD), .WR(mWR),
86
+ .DataOut(DataOut)
87
+ );
88
+
89
+ /* ��������չ */
90
+ ImmediateExtend ImmediateExtend(
91
+ .original(immediate), .ExtSel(ExtSel),
92
+ .extended(extended)
93
+ );
94
+ /* ����ѡ���� */
95
+ Mux4_32bits Mux_nextIAddr(
96
+ .choice(PCSrc), .in0(next_in0), .in1(next_in1), .in2(next_in2), .in3(currentIAddr),
97
+ .out(nextIAddr)
98
+ );
99
+ Mux2_5bits Mux_WriteReg(
100
+ .choice(RegDst), .in0(rt), .in1(rd),
101
+ .out(WriteReg)
102
+ );
103
+ Mux2_32bits Mux_WriteData(
104
+ .choice(DBDataSrc), .in0(ALU_result), .in1(DataOut),
105
+ .out(WriteData)
106
+ );
107
+ Mux2_32bits Mux_ALU_inA(
108
+ .choice(ALUSrcA), .in0(ReadData1), .in1({27'd0, immediate[10:6]}),
109
+ .out(ALU_inA)
110
+ );
111
+ Mux2_32bits Mux_ALU_inB(
112
+ .choice(ALUSrcB), .in0(ReadData2), .in1(extended),
113
+ .out(ALU_inB)
114
+ );
115
+ endmodule
Jed-Z_computer-organization-lab/SingleCycleCPU/test_instructions.txt ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 00001000 00000001 00000000 00001000
2
+ 01001000 00000010 00000000 00000010
3
+ 00000000 01000001 00011000 00000000
4
+ 00000100 01100010 00101000 00000000
5
+ 01000100 10100010 00100000 00000000
6
+ 01001100 10000010 01000000 00000000
7
+ 01100000 00001000 01000000 01000000
8
+ 11000101 00000001 11111111 11111110
9
+ 01110000 01000110 00000000 00000100
10
+ 01110000 11000111 00000000 00000000
11
+ 00001000 11100111 00000000 00001000
12
+ 11000000 11100001 11111111 11111110
13
+ 10011000 00100010 00000000 00000100
14
+ 10011100 00101001 00000000 00000100
15
+ 00001000 00001010 11111111 11111110
16
+ 00001001 01001010 00000000 00000001
17
+ 11001001 01000000 11111111 11111110
18
+ 01000000 01001011 00000000 00000010
19
+ 11100000 00000000 00000000 00010100
20
+ 01001100 10000010 01000000 00000000
21
+ 11111100 00000000 00000000 00000000
Jed-Z_computer-organization-lab/hex_to_7seg/hex_to_7seg.srcs/sim_1/new/sim1.v ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/15 17:40:44
7
+ // Design Name:
8
+ // Module Name: sim1
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module sim1;
24
+ reg clock;
25
+ reg reset;
26
+ wire [1:0] count;
27
+ Counter4 uut(
28
+ .clk(clock),
29
+ .reset(reset),
30
+ .count(count)
31
+ );
32
+
33
+ always #5 clock = ~clock;
34
+
35
+ initial begin
36
+ clock = 0;
37
+ reset = 0;
38
+ #100;
39
+ reset = 1;
40
+
41
+
42
+ #100;
43
+ $stop;
44
+ end
45
+
46
+ endmodule
Jed-Z_computer-organization-lab/hex_to_7seg/hex_to_7seg.srcs/sources_1/new/Counter4.v ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/15 14:03:28
7
+ // Design Name:
8
+ // Module Name: Counter4
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Counter4(
24
+ input clk,
25
+ input reset,
26
+ output reg [1:0] count
27
+ );
28
+
29
+ always @(posedge clk or posedge reset) begin
30
+ if(reset == 1) count <= 0;
31
+ else begin
32
+ if(count == 2'b11) count <= 0;
33
+ else count <= count + 1;
34
+ end
35
+ end
36
+
37
+ endmodule
Jed-Z_computer-organization-lab/hex_to_7seg/hex_to_7seg.srcs/sources_1/new/Hex_To_7Seg.v ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/15 13:52:22
7
+ // Design Name:
8
+ // Module Name: Hex_To_7Seg
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Hex_To_7Seg(
24
+ input [3:0] hex,
25
+ output reg [7:0] dispcode
26
+ );
27
+
28
+ always @(hex) begin
29
+ // '0'- ���ƣ�'1'- Ϩ��
30
+ // [7:0] �����ң�DP,g,f,e,d,c,b,a
31
+ case(hex)
32
+ 4'h0: dispcode <= 8'b1100_0000; //0
33
+ 4'h1: dispcode <= 8'b1111_1001; //1
34
+ 4'h2: dispcode <= 8'b1010_0100; //2
35
+ 4'h3: dispcode <= 8'b1011_0000; //3
36
+ 4'h4: dispcode <= 8'b1001_1001; //4
37
+ 4'h5: dispcode <= 8'b1001_0010; //5
38
+ 4'h6: dispcode <= 8'b1000_0010; //6
39
+ 4'h7: dispcode <= 8'b1101_1000; //7
40
+ 4'h8: dispcode <= 8'b1000_0000; //8
41
+ 4'h9: dispcode <= 8'b1001_0000; //9
42
+ 4'hA: dispcode <= 8'b1000_1000; //A
43
+ 4'hB: dispcode <= 8'b1000_0011; //b
44
+ 4'hC: dispcode <= 8'b1100_0110; //C
45
+ 4'hD: dispcode <= 8'b1010_0001; //d
46
+ 4'hE: dispcode <= 8'b1000_0110; //E
47
+ 4'hF: dispcode <= 8'b1000_1110; //F
48
+ default: dispcode <= 8'b0000_0000; // ����
49
+ endcase
50
+ end
51
+
52
+ endmodule
Jed-Z_computer-organization-lab/hex_to_7seg/hex_to_7seg.srcs/sources_1/new/Mux4_8bits.v ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/15 14:00:50
7
+ // Design Name:
8
+ // Module Name: Mux4_8bits
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module Mux4_4bits(
24
+ input [1:0] choice,
25
+ input [3:0] in0, in1, in2, in3,
26
+ output reg [3:0] out
27
+ );
28
+
29
+ always @(*) begin
30
+ case(choice)
31
+ 0: out <= in0;
32
+ 1: out <= in1;
33
+ 2: out <= in2;
34
+ 3: out <= in3;
35
+ endcase
36
+ end
37
+
38
+ endmodule
Jed-Z_computer-organization-lab/hex_to_7seg/hex_to_7seg.srcs/sources_1/new/clk_div.v ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/15 14:08:04
7
+ // Design Name:
8
+ // Module Name: clk_div
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module clk_div(
24
+ input clk,
25
+ output reg clk_sys = 0
26
+ );
27
+
28
+ reg [25:0] div_counter = 0;
29
+ always @(posedge clk) begin
30
+ if(div_counter >= 50000) begin
31
+ clk_sys <= ~clk_sys;
32
+ div_counter <= 0;
33
+ end
34
+ else div_counter <= div_counter + 1;
35
+ end
36
+
37
+ endmodule
Jed-Z_computer-organization-lab/hex_to_7seg/hex_to_7seg.srcs/sources_1/new/top_LEDs.v ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `timescale 1ns / 1ps
2
+ //////////////////////////////////////////////////////////////////////////////////
3
+ // Company:
4
+ // Engineer:
5
+ //
6
+ // Create Date: 2018/11/15 17:29:57
7
+ // Design Name:
8
+ // Module Name: top_LEDs
9
+ // Project Name:
10
+ // Target Devices:
11
+ // Tool Versions:
12
+ // Description:
13
+ //
14
+ // Dependencies:
15
+ //
16
+ // Revision:
17
+ // Revision 0.01 - File Created
18
+ // Additional Comments:
19
+ //
20
+ //////////////////////////////////////////////////////////////////////////////////
21
+
22
+
23
+ module top_LEDs(
24
+ input clock,
25
+ input reset,
26
+ input [3:0] hex0,
27
+ input [3:0] hex1,
28
+ input [3:0] hex2,
29
+ input [3:0] hex3,
30
+ output reg [3:0] enable,
31
+ output [7:0] dispcode, // �߶�����ܵ�����
32
+ output light
33
+ );
34
+
35
+ wire clk_sys;
36
+ wire [1:0] count;
37
+ wire [3:0] hex_num;
38
+
39
+ assign light = clk_sys;
40
+
41
+ clk_div clk_div(
42
+ .clk(clock),
43
+ .clk_sys(clk_sys)
44
+ );
45
+ Counter4 Counter4(
46
+ .clk(clk_sys), .reset(reset),
47
+ .count(count)
48
+ );
49
+ Hex_To_7Seg Hex_To_7Seg(
50
+ .hex(hex_num),
51
+ .dispcode(dispcode)
52
+ );
53
+ Mux4_4bits Mux4_4bits(
54
+ .choice(count),
55
+ .in0(hex0), .in1(hex1), .in2(hex2), .in3(hex3),
56
+ .out(hex_num)
57
+ );
58
+
59
+ always @(count) begin
60
+ case(count)
61
+ 2'b00: enable = 4'b1110;
62
+ 2'b01: enable = 4'b1101;
63
+ 2'b10: enable = 4'b1011;
64
+ 2'b11: enable = 4'b0111;
65
+ endcase
66
+ end
67
+
68
+ endmodule