Serial Adder Mealy Machine
A serial adder adds two numbers one bit pair per clock, least significant bit first. The only thing it has to remember between cycles is the carry.
The module reads input bits a and b and immediately produces the sum bit. The carry out of the current addition must be stored as the state for the next cycle's addition. Because the output depends on both the current state (the stored carry) and the current inputs, this must be implemented as a Mealy machine.
The design is synchronised to the positive edge of clk. It uses an asynchronous, active-low reset rst_n. On reset, the state becomes 0 (no carry) and the output sum reflects a ^ b immediately.
Cycle 1: rst_n=0 → state=0, a=0, b=0 → sum=0
Cycle 2: rst_n=1, a=1, b=1 → state=0 (carry=0), sum=0, next_state=1
Cycle 3: rst_n=1, a=0, b=1 → state=1 (carry=1), sum=0, next_state=1
Cycle 4: rst_n=1, a=0, b=0 → state=1 (carry=1), sum=1, next_state=0
| Signal | Direction | Width | Description |
|---|---|---|---|
clk |
input | 1 | Positive-edge triggered clock |
rst_n |
input | 1 | Asynchronous active-low reset; internal carry state goes to 0 |
a |
input | 1 | First operand bit |
b |
input | 1 | Second operand bit |
sum |
output | 1 | Combinational sum output (Mealy) |
Constraints
summust be a combinational output reflecting the immediate sum ofa,b, and the current state.- The internal state (carry) must update on the positive edge of
clk. rst_nis asynchronous and active-low.- On reset, the internal carry state must become 0.
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.
This problem is part of Codiode Pro. The statement above is free to read.
The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.
Part of FSM Coding
Problem 10 of 15 in the FSM Coding track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks