-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
8,458 additions
and
9,203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# PipelineCPU | ||
A pipelined CPU implemented by Verilog | ||
A pipelined CPU implemented by Verilog. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
`include "ctrl_encode_def.v" | ||
|
||
module alu(A, B, ALUOp, C, Zero,PC); | ||
input signed [31:0] A, B; | ||
input [4:0] ALUOp; | ||
module alu(A, B, ALUOp, C, Zero, PC); | ||
input signed [31:0] A, B; | ||
input [4:0] ALUOp; | ||
input [31:0] PC; | ||
output signed [31:0] C; | ||
output Zero; | ||
|
||
reg [31:0] C; | ||
integer i; | ||
integer i; | ||
|
||
always @( * ) begin | ||
case ( ALUOp ) | ||
`ALUOp_nop :C=A; | ||
`ALUOp_lui :C=B; | ||
`ALUOp_auipc:C=PC+B; | ||
always @(*) begin | ||
case (ALUOp) | ||
`ALUOp_nop : C = A; | ||
`ALUOp_lui : C = B; | ||
`ALUOp_auipc: C = PC + B; | ||
|
||
`ALUOp_add:C=A+B; | ||
`ALUOp_sub:C=A-B; | ||
`ALUOp_xor:C=A^B; | ||
`ALUOp_or :C=A|B; | ||
`ALUOp_and:C=A&B; | ||
`ALUOp_sll:C=A<<B; | ||
`ALUOp_srl:C=A>>B; | ||
`ALUOp_sra:C=A>>>B; | ||
`ALUOp_add: C = A + B; | ||
`ALUOp_sub: C = A - B; | ||
`ALUOp_xor: C = A ^ B; | ||
`ALUOp_or : C = A | B; | ||
`ALUOp_and: C = A & B; | ||
`ALUOp_sll: C = A << B; | ||
`ALUOp_srl: C = A >> B; | ||
`ALUOp_sra: C = A >>> B; | ||
|
||
`ALUOp_bne :C={31'b0,(A==B)}; | ||
`ALUOp_blt :C={31'b0,(A>=B)}; | ||
`ALUOp_bge :C={31'b0,(A<B)}; | ||
`ALUOp_bltu:C={31'b0,($unsigned(A)>=$unsigned(B))}; | ||
`ALUOp_bgeu:C={31'b0,($unsigned(A)<$unsigned(B))}; | ||
`ALUOp_slt :C={31'b0,(A<B)}; | ||
`ALUOp_sltu:C={31'b0,($unsigned(A)<$unsigned(B))}; | ||
`ALUOp_bne : C = {31'b0, (A == B)}; | ||
`ALUOp_blt : C = {31'b0, (A >= B)}; | ||
`ALUOp_bge : C = {31'b0, (A < B)}; | ||
`ALUOp_bltu: C = {31'b0, ($unsigned(A) >= $unsigned(B))}; | ||
`ALUOp_bgeu: C = {31'b0, ($unsigned(A) < $unsigned(B))}; | ||
`ALUOp_slt : C = {31'b0, (A < B)}; | ||
`ALUOp_sltu: C = {31'b0, ($unsigned(A) < $unsigned(B))}; | ||
endcase | ||
end | ||
|
||
assign Zero = (C == 32'b0); // 运算结果是否为零,若为零则表示满足有条件跳转的条件 | ||
assign Zero = (C == 32'b0); // Jump condition | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.