2023-02-11 14:43:53 +00:00
|
|
|
`include "alu_header.v"
|
2023-02-09 20:16:50 +00:00
|
|
|
|
2023-02-12 01:05:39 +00:00
|
|
|
module ALU(input [15:0]A,input [15:0]B, input oe,output reg [15:0]OUT,input [`ALU_OP_BITS-1:0]op,output wire [7:0]FLAGS,input Wbit);
|
2023-02-11 14:43:53 +00:00
|
|
|
reg C_FLAG;
|
|
|
|
|
2023-02-12 01:05:39 +00:00
|
|
|
assign FLAGS={(Wbit==1)?OUT[15:15]:OUT[7:7],(Wbit==1) ? (OUT[15:0]=='h0000) : (OUT[7:0]=='h00),5'b00000,C_FLAG};
|
|
|
|
|
2023-02-11 14:43:53 +00:00
|
|
|
always @ ( * ) begin
|
|
|
|
case (op)
|
|
|
|
`ALU_OP_ADD: {C_FLAG,OUT}=A+B;
|
|
|
|
`ALU_OP_SUB: {C_FLAG,OUT}=A-B;
|
|
|
|
`ALU_OP_AND: OUT=A&B;
|
|
|
|
`ALU_OP_OR: OUT=A|B;
|
|
|
|
`ALU_OP_XOR: OUT=A^B;
|
|
|
|
endcase
|
|
|
|
end
|
2023-02-09 20:16:50 +00:00
|
|
|
|
|
|
|
endmodule
|