summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--alu.v14
1 files changed, 6 insertions, 8 deletions
diff --git a/alu.v b/alu.v
index 5fbb8ba..63812a7 100644
--- a/alu.v
+++ b/alu.v
@@ -26,16 +26,17 @@ module alu (
// 1111: result = x >> y (barrel shift)
wire [16:0] sum;
- wire [16:0] diff;
wire [16:0] prod;
wire [16:0] quot;
wire [15:0] anded;
wire [15:0] ored;
wire [15:0] xored;
wire [15:0] shifted;
+ wire issum;
- assign sum = x + y;
- assign diff = x - y;
+ assign issum = ~|(op[3:1]);
+
+ assign sum = x + (op[0] ? ~y + 1 : y);
assign prod = x * y;
assign quot = x / y;
assign anded = x & y;
@@ -51,8 +52,7 @@ module alu (
);
assign result =
- op == 4'b0000 ? sum[15:0] :
- op == 4'b0001 ? diff[15:0] :
+ issum ? sum[15:0] :
op == 4'b0010 ? prod[15:0] :
op == 4'b0011 ? quot[15:0] :
op == 4'b0100 ? anded :
@@ -62,8 +62,6 @@ module alu (
shifted;
assign zero = ~(|result);
- assign carry =
- op == 4'b0000 ? sum[16] :
- op == 4'b0001 ? diff[16] : 1'b0;
+ assign carry = issum ? sum[16] : 1'b0;
endmodule