Half adder is a combinational circuit which computer binary addition of two binary inputs. It is one of the basic combinational circuit in which we have combination of two gates (ex-or gate, and gate). The truth table of half adder is given below and we can write boolean expression for half adder as follows $$sum = a\oplus b$$ $$carry = ab$$

## Input a |
## Input b |
## Output sum |
## Output carry |

0 |
0 |
0 |
0 |

0 |
1 |
1 |
0 |

1 |
0 |
1 |
0 |

1 |
1 |
0 |
1 |

Half adder has two inputs (a,b) and two outputs (sum,carry). First, create a module with a module name half_adder_s as given below.

```
//half adder using structural modeling
module half_adder_s ();
endmodule
```

Now create input output port list.

```
//half adder using structural modeling
module half_adder_s (
input a,b,
output sum,carry
);
endmodule
```

Now desciribe the hardware inside the module. Sum is a ex-or b and carry is a and b. We can use any hardware modeling for describing a half adder. Below is the verilog code using structural modeling because we are using logic gate instantiation for descibing logic gates.

```
//half adder using structural modeling
module half_adder_s (
input a,b,
output sum,carry
);
xor(sum,a,b);
and(carry,a,b);
endmodule
```

Below is the Verilog code for half adder using data-flow modeling because we are using assign statement to assign a logic function to the output.

```
//half adder using data flow modeling
module half_adder_d (
input a,b,
output sum,carry
);
assign sum = a ^ b;
assign carry = a & b;
endmodule
```

We can also use adder operator for creating half adder crcuit because half adder is basically addition of two binary inputs as given below.

```
//half adder using Verilog Operator
module half_adder_o (
input a,b,
output sum,carry
);
assign {carry,sum} = a+b;
endmodule
```

```
module half_adder_tb;
reg a,b;
wire sum,carry;
half_adder_s uut(a,b,sum,carry);
initial begin
a = 0; b = 0;
#10
b = 0; b = 1;
#10
a = 1; b = 0;
#10
b = 1; b = 1;
#10
$finish();
end
endmodule
```

Privacy Policy

This policy contains information about your privacy. By posting, you are declaring that you understand this policy:

- Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
- Aside from the data entered into these form fields, other stored data about your comment will include:
- Your IP address (not displayed)
- The time/date of your submission (displayed)

- Your email address will not be shared. It is collected for only two reasons:
- Administrative purposes, should a need to contact you arise.
- To inform you of new comments, should you subscribe to receive notifications.

- A cookie may be set on your computer. This is used to remember your inputs. It will expire by itself.

This policy is subject to change at any time and without notice.

Terms and Conditions

These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:

- Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
- You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
- You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
- The administrator has the right to edit, move or remove any comment for any reason and without notice.

Failure to comply with these rules may result in being banned from submitting further comments.

These terms and conditions are subject to change at any time and without notice.

## Comments