forked from deoregaurav92/SystemVerilog_Coding_Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alu.sv
36 lines (32 loc) · 916 Bytes
/
alu.sv
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
32
33
34
35
36
// package with opcode_t declaration
import typedefs_v2::*;
// SystemVerilog: time unit and time precision specification
timeunit 1ns;
timeprecision 100ps;
module alu ( input logic [7:0] accum,
input logic [7:0] data,
input opcode_t opcode,
input clk,
output logic [7:0] out,
output logic zero); // zero = '1' when accum is '0' otherwise '0'
always_comb begin
if (!accum)
zero = 1'b1;
else
zero = 1'b0;
end
always_ff @(negedge clk)
begin
unique case (opcode)
3'b000 : out = accum;
3'b001 : out = accum;
3'b010 : out = data + accum;
3'b011 : out = data & accum;
3'b100 : out = data ^ accum;
3'b101 : out = data;
3'b110 : out = accum;
3'b111 : out = accum;
default : out = 8'b0;
endcase
end
endmodule