diff options
author | Bobby Bingham <koorogi@koorogi.info> | 2017-01-08 22:45:04 -0600 |
---|---|---|
committer | Bobby Bingham <koorogi@koorogi.info> | 2017-01-08 22:45:04 -0600 |
commit | 47cfb7ba2df247310e2160e4e53d1843d4e4d1c8 (patch) | |
tree | 0627a39acd1996a00e2cbd2458afcfe037897f3d | |
parent | 67b51195967009edbcf26767f9f3e8e1dd2db780 (diff) |
Implement subtraction in terms of addition
-rw-r--r-- | alu.v | 14 |
1 files changed, 6 insertions, 8 deletions
@@ -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 |