summaryrefslogtreecommitdiff
path: root/alu.v
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2017-01-08 21:58:16 -0600
committerBobby Bingham <koorogi@koorogi.info>2017-01-08 23:18:31 -0600
commit17f5cbe781ae761d86d55fec7d46ba3172167894 (patch)
treeb02d0dc075eb94a56cccd49a471e852a6799c266 /alu.v
parent47cfb7ba2df247310e2160e4e53d1843d4e4d1c8 (diff)
Add carry input to ALU
Diffstat (limited to 'alu.v')
-rw-r--r--alu.v5
1 files changed, 3 insertions, 2 deletions
diff --git a/alu.v b/alu.v
index 63812a7..37a84d5 100644
--- a/alu.v
+++ b/alu.v
@@ -2,6 +2,7 @@ module alu (
input [3:0] op,
input [15:0] x,
input [15:0] y,
+ input carry_in,
output [15:0] result,
output zero,
output carry
@@ -36,7 +37,7 @@ module alu (
assign issum = ~|(op[3:1]);
- assign sum = x + (op[0] ? ~y + 1 : y);
+ assign sum = x + ({16{op[0]}} ^ y) + (op[0] ^ carry_in);
assign prod = x * y;
assign quot = x / y;
assign anded = x & y;
@@ -62,6 +63,6 @@ module alu (
shifted;
assign zero = ~(|result);
- assign carry = issum ? sum[16] : 1'b0;
+ assign carry = issum ? op[0] ^ sum[16] : 1'b0;
endmodule