2016-04-11 12:01:59 -04:00
|
|
|
//#############################################################################
|
2016-08-21 17:02:46 +02:00
|
|
|
//# Function: Two's complement adder/subtractor #
|
2016-04-11 12:01:59 -04:00
|
|
|
//#############################################################################
|
|
|
|
//# Author: Andreas Olofsson #
|
|
|
|
//# License: MIT (see LICENSE file in OH! repository) #
|
|
|
|
//#############################################################################
|
2015-12-17 13:50:59 -05:00
|
|
|
|
2016-04-11 12:01:59 -04:00
|
|
|
module oh_add #(parameter DW = 1 // data width
|
|
|
|
)
|
|
|
|
(
|
|
|
|
input [DW-1:0] a, //first operand
|
|
|
|
input [DW-1:0] b, //second operand
|
|
|
|
input opt_sub, //subtraction option
|
|
|
|
input cin, //carry in
|
|
|
|
output [DW-1:0] sum, //sum output
|
|
|
|
output cout, //carry output
|
|
|
|
output zero, //zero flag
|
|
|
|
output neg, //negative flag
|
|
|
|
output overflow //overflow flag
|
|
|
|
);
|
|
|
|
|
2015-12-17 13:50:59 -05:00
|
|
|
wire [DW-1:0] b_sub;
|
|
|
|
|
|
|
|
assign b_sub[DW-1:0] = {(DW){opt_sub}} ^ b[DW-1:0];
|
|
|
|
|
|
|
|
assign {cout,sum[DW-1:0]} = a[DW-1:0] +
|
|
|
|
b_sub[DW-1:0] +
|
|
|
|
opt_sub +
|
|
|
|
cin;
|
|
|
|
endmodule // oh_add
|