From f665f0ff80397ab10dbbea6cfcb302bb131f9719 Mon Sep 17 00:00:00 2001 From: kryptoish Date: Tue, 3 Dec 2024 16:58:07 -0800 Subject: added files --- alu.sv | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 alu.sv (limited to 'alu.sv') diff --git a/alu.sv b/alu.sv new file mode 100644 index 0000000..4e17d8b --- /dev/null +++ b/alu.sv @@ -0,0 +1,21 @@ + module ALU(Ain,Bin,ALUop,out,Z); + input [15:0] Ain, Bin; + input [1:0] ALUop; + output reg [15:0] out; + output reg [2:0] Z; //Z[0] = zero flag, Z[1] = neg flag, Z[2] = overflow flag + + always_comb begin + case(ALUop) + 2'b00 : out = Ain + Bin; //add Ain and Bin + 2'b01 : out = Ain - Bin; //subtract Ain and Bin + 2'b10 : out = Ain & Bin; //AND Ain and Bin + 2'b11 : out = ~Bin; //Negate Bin + endcase + + //make it better by putting it into the add and subtraction above + Z[0] = out[15]; //negative + Z[1] = (ALUop == 2'b00) ? ((Ain[15] == Bin[15]) && (out[15] != Ain[15])) : + (ALUop == 2'b01) ? ((Ain[15] != Bin[15]) && (out[15] != Ain[15])) : 1'b0; //improvements could be made + Z[2] = out == {16{1'b0}}; //zero + end + endmodule \ No newline at end of file -- cgit v1.2.3