aboutsummaryrefslogtreecommitdiff
path: root/src/alu.sv
blob: c6d00bd7205bd71fd6329fcd408fc1aa8a2133bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module ALU(Ain, Bin, op, out, status);
	input [1:0] op;
	input [15:0] Ain, Bin;
	output [2:0] status;
	output reg [15:0] out;

	assign status[2] = out[15];
	assign status[1] = (out[15] ^ Ain[15]) & ~(out[15] ^ Bin[15]);
	assign status[0] = (out == 0);

	always_comb case (op)
		2'b00: out = Ain + Bin;
		2'b01: out = Ain - Bin;
		2'b10: out = Ain & Bin;
		2'b11: out = ~Bin;
	endcase
endmodule: ALU