

See the simulation waveform below to understand what I just explained. This way we can add binary numbers of any size without mentioning the value of N specifically. After a pair of numbers are added, just apply reset for at least one clock cycle to show the end of inputs. And the cout output bit is considered to be valid only on the first clock cycle after a high reset. The cin bit is considered to be valid only on the first clock cycle after a low reset. And in each clock cycle we get the corresponding bit on output s.

The design keeps adding the input bits in a serial way, when the reset is not high. Note that, even though this code works as a N-bit adder, we don't have to mention the value of N directly. generate clock with 10 ns clock period.

If ( reset = 1 ) begin //active high resetĬ = cin //on first iteration after reset, assign cin to c.įlag = 1 //then make flag 1, so that this if statement isnt executed any more.Ĭ = ( a & b ) | ( c & b ) | ( a & c ) //CARRY Output reg s, cout //note that s comes out at every clock cycle and cout is valid only for last clock cycle. Input a, b, cin, //note that cin is used for only first iteration. Note that we dont have to mention N here. This is a way to convert data from a parallel format to a. In addition, parallel-in/ serial-out really means that we can load data in parallel into all stages before any shifting ever begins. Though I have used behavioral level approach to write my code, it should be straight forward to understand if you have the basics right. The parallel-in/ serial-out shift register stores data, shifts it on a clock by clock basis, and delays it by the number of stages times the clock period. In this post, I have used a similar idea to implement the serial adder. The D flipflop is used to pass the output carry, back to the full adder with a clock cycle delay. The above block diagram shows how a serial adder can be implemented.
