From 464289c73853f13f6ccc4b584503c4c09988d1a0 Mon Sep 17 00:00:00 2001 From: dianshi Date: Mon, 14 Feb 2022 08:04:19 +0000 Subject: Add alu v0.1_16bit. compiles without warning risc cpu --- alu/v0.1_16bit/Makefile | 9 ++++++ alu/v0.1_16bit/alu.v | 46 ++++++++++++++++++++++++++++++ alu/v0.1_16bit/testbench_alu.v | 64 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 alu/v0.1_16bit/Makefile create mode 100644 alu/v0.1_16bit/alu.v create mode 100644 alu/v0.1_16bit/testbench_alu.v (limited to 'alu/v0.1_16bit') diff --git a/alu/v0.1_16bit/Makefile b/alu/v0.1_16bit/Makefile new file mode 100644 index 0000000..0459ab3 --- /dev/null +++ b/alu/v0.1_16bit/Makefile @@ -0,0 +1,9 @@ +make: + iverilog -g2005-sv -o alu alu.v + iverilog -g2005-sv -o test_alu testbench_alu.v alu.v + +test: + vvp test_alu + +wave: + gtkwave test_alu.vcd diff --git a/alu/v0.1_16bit/alu.v b/alu/v0.1_16bit/alu.v new file mode 100644 index 0000000..05bf227 --- /dev/null +++ b/alu/v0.1_16bit/alu.v @@ -0,0 +1,46 @@ +module alu( + input [15:0]a,b, + input [2:0]alu_sel, + output [15:0]alu_out, + output carry_out +); + +reg [7:0]alu_result; +wire [8:0]tmp; + +assign alu_out=alu_result; //result from alu +//??? +assign tmp = {1'b0,a}+{1'b0,b}; + + +always @(*) +begin + case (alu_sel) + 4'b0000: //addition + alu_result = a+b; + 4'b0001: //substraction + alu_result = a-b; + 4'b0010: //multiplication + alu_result = ~a; + 4'b0011: //division + alu_result = a<>b; + 4'b0101: //logical shift right + alu_result = a&b; + 4'b0110: //rotate right + alu_result = a|b; + 4'b0111: //rotate left + begin + if (a