-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathALU.v
31 lines (24 loc) · 1.16 KB
/
ALU.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// fullname : Milad Nooraei
// student number : 9935701
// Computer Architecture HomeWork 2
//////////////////////////////////////////////////////////////////////////////////
module ALU(
input [31:0]firstInput, secondInput,
input [3:0]alucontrol,
output [31:0]ALUout,
output zero
);
assign ALUout = (alucontrol == 'b0000) ? (firstInput + secondInput) : //and
(alucontrol == 'b0001) ? (firstInput - secondInput) : //sub
(alucontrol == 'b0010) ? (firstInput ^ secondInput) : //xor
(alucontrol == 'b0011) ? (firstInput | secondInput) : //or
(alucontrol == 'b0100) ? (firstInput & secondInput) : //and
(alucontrol == 'b0101) ? (~firstInput) : //not
(alucontrol == 'b0110) ? (firstInput << secondInput[4:0]) : //shift left logical
(alucontrol == 'b0111) ? (firstInput >> secondInput[4:0]) : //shift right logical
(alucontrol == 'b1000) ? ((firstInput < secondInput) ? 1 : 0) ://set less than
-1;
assign zero = (ALUout == 0) ? 1 : 0;
endmodule