Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part A: For decimal arithmetic, BCD (BinaryCoded Decimal) adder is used. With BC

ID: 1830972 • Letter: P

Question

Part A:For decimal arithmetic, BCD (BinaryCoded Decimal) adder is used. With BCD

arithmetic, digits 0 through 9 are usedand usually 4-bit is used to represent each digit.You

should write a verilog code that addstwo BCD number. Input for the adder is two 4-bitBCD

numbers and output of the adder is alsotwo 4-bit BCD numbers (result will be in the range of 0..

18). When you add two 4-bit BCD numbers,a correction step is required if result is biggerthan

9. Correction requires adding 6. Forexample if you add 5 and 7, then result shouldbe12.

5 + 7= 1100

Since the result is greater than 9, weshould add 6

1 0010 2is the corrected (least significant digit) result and themost

significant digit will be 1 becausethere is an overflow.

If result is less than or equal to 9,then the correction step is not required and the mostsignificant

digit will be zero. You do not need todesign an adder by using gates. You can simplywrite

verilog code and add numbers by using +operator.

Explanation / Answer

we need to correct the 4 lsb of the result only if the result is bigger or equals 10:

module bsd_add(a_bcd_in,b_bcd_in,bcd_out);

input [3:0] a_bcd_in;

input [3:0] b_bcd_in;

output [4:0] bcd_out;

wire [4:0] a_plus_b;

wire [4:0] a_plus_b_minus_10;

wire a_plus_b_is_greater_or_equals_10;

// logic part

a_plus_b = a+b;

a_plus_b_minus_10 = a_plus_b - 5'b01010;

assign a_plus_b_is_greater_or_equals_10 = ~(a_plus_b < 5'b01010);

assign bcd_out[4] = a_plus_b_is_greater_or_equals_10;

assign bcd_out[3:0] = a_plus_b_is_greater_or_equals_10 ?

a_plus_b_minus_10[3:0] :

a_plus_b[3:0];

endmodule