Skip to content

Instantly share code, notes, and snippets.

@sonOfRa
Created November 6, 2017 02:14
Show Gist options
  • Save sonOfRa/b813143a2d6d661d1c46b19f80c591e1 to your computer and use it in GitHub Desktop.
Save sonOfRa/b813143a2d6d661d1c46b19f80c591e1 to your computer and use it in GitHub Desktop.
\begin{figure}[htbp]
\centering
\begin{tikzpicture}
\node[draw,minimum width=7cm,minimum height=3cm,
label={[anchor=east]right:$c_{in}$},label={[anchor=west]left:$c_{out}$}] (adder1) {};
\node[below right=1mm and 5mm of adder1.north] (adder1a3) {$a_3$};
\node[right=1mm of adder1a3] (adder1a2) {$a_2$};
\node[right=1mm of adder1a2] (adder1a1) {$a_1$};
\node[right=1mm of adder1a1] (adder1a0) {$a_0$};
\node[above=5mm of adder1a3] (a3init) {$0$};
\draw (a3init.south) -- ++(-90:4mm);
\node[left=1cm of adder1a3] (adder1b0) {$b_0$};
\node[left=1mm of adder1b0] (adder1b1) {$b_1$};
\node[left=1mm of adder1b1] (adder1b2) {$b_2$};
\node[left=1mm of adder1b2] (adder1b3) {$b_3$};
\node[above left=1mm and 1mm of adder1.south] (adder1res2) {$res_2$};
\node[left=2mm of adder1res2] (adder1res3) {$res_3$};
\node[right=2mm of adder1res2] (adder1res1) {$res_1$};
\node[right=2mm of adder1res1] (adder1res0) {$res_0$};
\node[right=5mm of adder1.east] (cin1) {$0$};
\draw (cin1) -- (adder1.east);
\node[below=1cm of adder1res0] (prod1) {$prod_1$};
\draw (prod1.north) -- ++(90:9mm);
\node[right=2cm of prod1] (prod0) {$prod_0$};
\node[above=6cm of prod0,draw,and gate US,rotate=-90,anchor=output] (and00) {};
\draw (and00.output) -- (prod0);
\node[left=1cm of and00,draw,and gate US,rotate=-90,anchor=east,anchor=input 1] (and01) {};
\draw[shorten >=1mm] (and01.output) -- ++(-90:5mm) -| (adder1a0.north);
\node[left=1cm of and01,draw,and gate US,rotate=-90,anchor=east,anchor=input 1] (and02) {};
\draw[shorten >=1mm] (and02.output) -- ++(-90:5mm) -| (adder1a1.north);
\node[left=1cm of and02,draw,and gate US,rotate=-90,anchor=east,anchor=input 1] (and03) {};
\draw[shorten >=1mm] (and03.output) -- ++(-90:5mm) -| (adder1a2.north);
\node[branch,above=1cm of and03.input 2] (brancha03) {};
\node[above=1.5cm of and03.input 1] (a0b3) {$b_3$};
\draw (brancha03) -- (and03.input 2);
\draw(a0b3) -- (and03.input 1);
\node[branch,right=1cm of brancha03] (brancha02) {};
\node[above=1.5cm of and02.input 1] (a0b2) {$b_2$};
\draw (brancha02) -- (and02.input 2);
\draw(a0b2) -- (and02.input 1);
\node[branch,right=1cm of brancha02] (brancha01) {};
\node[left=1cm of brancha03] (a0) {$a_0$};
\node[above=1.5cm of and01.input 1] (a0b1) {$b_1$};
\draw (brancha01) -- (and01.input 2);
\draw(a0b1) -- (and01.input 1);
\draw (a0) -- (brancha03) -- (brancha02) -- (brancha01) -| (and00.input 2);
\node[above=1.5cm of and00.input 1] (a0b0) {$b_0$};
\draw(a0b0) -- (and00.input 1);
\node[draw,and gate US,rotate=-90,anchor=output] (and10) at (adder1b0 |- and03.output) {};
\draw[shorten >=.5mm] (and10.output) -- (adder1b0);
\node[draw,and gate US,rotate=-90,anchor=output,left=1cm of and10.output] (and11) {};
\draw[shorten >=.5mm] (and11.output) -- ++(-90:5mm) -| (adder1b1);
\node[draw,and gate US,rotate=-90,anchor=output,left=1cm of and11.output] (and12) {};
\draw[shorten >=.5mm] (and12.output) -- ++(-90:5mm) -| (adder1b2);
\node[draw,and gate US,rotate=-90,anchor=output,left=1cm of and12.output] (and13) {};
\draw[shorten >=.5mm] (and13.output) -- ++(-90:5mm) -| (adder1b3);
\node[branch,above=1cm of and13.input 2] (brancha13) {};
\node[above=1.5cm of and13.input 1] (a1b3) {$b_3$};
\draw (brancha13) -- (and13.input 2);
\draw(a1b3) -- (and13.input 1);
\node[branch,above=1cm of and12.input 2] (brancha12) {};
\node[above=1.5cm of and12.input 1] (a1b2) {$b_2$};
\draw (brancha12) -- (and12.input 2);
\draw(a1b2) -- (and12.input 1);
\node[branch,above=1cm of and11.input 2] (brancha11) {};
\node[left=1cm of brancha13] (a1) {$a_1$};
\node[above=1.5cm of and11.input 1] (a1b1) {$b_1$};
\draw (brancha11) -- (and11.input 2);
\draw(a1b1) -- (and11.input 1);
\draw (a1) -- (brancha13) -- (brancha12) -- (brancha11) -| (and10.input 2);
\node[above=1.5cm of and10.input 1] (a1b0) {$b_0$};
\draw(a1b0) -- (and10.input 1);
\node[below left=2cm and 2.5mm of adder1.south,draw,minimum width=7cm,minimum height=3cm,
label={[anchor=east]right:$c_{in}$},label={[anchor=west]left:$c_{out}$}] (adder2) {};
\node[below right=1mm and 5mm of adder2.north] (adder2a3) {$a_3$};
\node[right=1mm of adder2a3] (adder2a2) {$a_2$};
\node[right=1mm of adder2a2] (adder2a1) {$a_1$};
\node[right=1mm of adder2a1] (adder2a0) {$a_0$};
\draw[shorten <=1mm,shorten >=1mm] (adder1res1) -- ++(-90:15mm) -| (adder2a0);
\draw[shorten <=1mm,shorten >=1mm] (adder1res2) -- ++(-90:10mm) -| (adder2a1);
\draw[shorten <=1mm,shorten >=1mm] (adder1res3) -- ++(-90:5mm) -| (adder2a2);
\draw[shorten >=1mm] (adder1.west) -- ++(180:5mm) -- ++(-90:2cm) -| (adder2a3);
\node[left=1cm of adder2a3] (adder2b0) {$b_0$};
\node[left=1mm of adder2b0] (adder2b1) {$b_1$};
\node[left=1mm of adder2b1] (adder2b2) {$b_2$};
\node[left=1mm of adder2b2] (adder2b3) {$b_3$};
\node[above left=1mm and 1mm of adder2.south] (adder2res2) {$res_2$};
\node[left=2mm of adder2res2] (adder2res3) {$res_3$};
\node[right=2mm of adder2res2] (adder2res1) {$res_1$};
\node[right=2mm of adder2res1] (adder2res0) {$res_0$};
\node[right=5mm of adder2.east] (cin2) {$0$};
\draw (cin2) -- (adder2.east);
\node[below=1cm of adder2res0] (prod2) {$prod_2$};
\draw (prod2.north) -- ++(90:9mm);
\node[draw,and gate US,rotate=-90,anchor=output] (and20) at (adder2b0 |- prod1) {};
\draw[shorten >=.5mm] (and20.output) -- (adder2b0);
\node[draw,and gate US,rotate=-90,anchor=output,left=1cm of and20.output] (and21) {};
\draw[shorten >=.5mm] (and21.output) -- ++(-90:5mm) -| (adder2b1);
\node[draw,and gate US,rotate=-90,anchor=output,left=1cm of and21.output] (and22) {};
\draw[shorten >=.5mm] (and22.output) -- ++(-90:5mm) -| (adder2b2);
\node[draw,and gate US,rotate=-90,anchor=output,left=1cm of and22.output] (and23) {};
\draw[shorten >=.5mm] (and23.output) -- ++(-90:5mm) -| (adder2b3);
\node[branch,above=1cm of and23.input 2] (brancha23) {};
\node[above=1.5cm of and23.input 1] (a2b3) {$b_3$};
\draw (brancha23) -- (and23.input 2);
\draw(a2b3) -- (and23.input 1);
\node[branch,above=1cm of and22.input 2] (brancha22) {};
\node[above=1.5cm of and22.input 1] (a2b2) {$b_2$};
\draw (brancha22) -- (and22.input 2);
\draw(a2b2) -- (and22.input 1);
\node[branch,above=1cm of and21.input 2] (brancha21) {};
\node[left=1cm of brancha23] (a2) {$a_2$};
\node[above=1.5cm of and21.input 1] (a2b1) {$b_1$};
\draw (brancha21) -- (and21.input 2);
\draw(a2b1) -- (and21.input 1);
\draw (a2) -- (brancha23) -- (brancha22) -- (brancha21) -| (and20.input 2);
\node[above=1.5cm of and20.input 1] (a2b0) {$b_0$};
\draw(a2b0) -- (and20.input 1);
\node[below left=2cm and 2.5mm of adder2.south,draw,minimum width=7cm,minimum height=3cm,
label={[anchor=east]right:$c_{in}$},label={[anchor=west]left:$c_{out}$}] (adder3) {};
\node[below right=1mm and 5mm of adder3.north] (adder3a3) {$a_3$};
\node[right=1mm of adder3a3] (adder3a2) {$a_2$};
\node[right=1mm of adder3a2] (adder3a1) {$a_1$};
\node[right=1mm of adder3a1] (adder3a0) {$a_0$};
\draw[shorten <=1mm,shorten >=1mm] (adder2res1) -- ++(-90:15mm) -| (adder3a0);
\draw[shorten <=1mm,shorten >=1mm] (adder2res2) -- ++(-90:10mm) -| (adder3a1);
\draw[shorten <=1mm,shorten >=1mm] (adder2res3) -- ++(-90:5mm) -| (adder3a2);
\draw[shorten >=1mm] (adder2.west) -- ++(180:5mm) -- ++(-90:2cm) -| (adder3a3);
\node[left=1cm of adder3a3] (adder3b0) {$b_0$};
\node[left=1mm of adder3b0] (adder3b1) {$b_1$};
\node[left=1mm of adder3b1] (adder3b2) {$b_2$};
\node[left=1mm of adder3b2] (adder3b3) {$b_3$};
\node[draw,and gate US,rotate=-90,anchor=output] (and30) at (adder3b0 |- prod2) {};
\draw[shorten >=.5mm] (and30.output) -- (adder3b0);
\node[draw,and gate US,rotate=-90,anchor=output,left=1cm of and30.output] (and31) {};
\draw[shorten >=.5mm] (and31.output) -- ++(-90:5mm) -| (adder3b1);
\node[draw,and gate US,rotate=-90,anchor=output,left=1cm of and31.output] (and32) {};
\draw[shorten >=.5mm] (and32.output) -- ++(-90:5mm) -| (adder3b2);
\node[draw,and gate US,rotate=-90,anchor=output,left=1cm of and32.output] (and33) {};
\draw[shorten >=.5mm] (and33.output) -- ++(-90:5mm) -| (adder3b3);
\node[branch,above=1cm of and33.input 2] (brancha33) {};
\node[above=1.5cm of and33.input 1] (a3b3) {$b_3$};
\draw (brancha33) -- (and33.input 2);
\draw(a3b3) -- (and33.input 1);
\node[branch,above=1cm of and32.input 2] (brancha32) {};
\node[above=1.5cm of and32.input 1] (a3b2) {$b_2$};
\draw (brancha32) -- (and32.input 2);
\draw(a3b2) -- (and32.input 1);
\node[branch,above=1cm of and31.input 2] (brancha31) {};
\node[left=.5cm of brancha33] (a3) {$a_3$};
\node[above=1.5cm of and31.input 1] (a3b1) {$b_1$};
\draw (brancha31) -- (and31.input 2);
\draw(a3b1) -- (and31.input 1);
\draw (a3) -- (brancha33) -- (brancha32) -- (brancha31) -| (and30.input 2);
\node[above=1.5cm of and30.input 1] (a3b0) {$b_0$};
\draw(a3b0) -- (and30.input 1);
\node[above left=1mm and 1mm of adder3.south] (adder3res2) {$res_2$};
\node[left=2mm of adder3res2] (adder3res3) {$res_3$};
\node[right=2mm of adder3res2] (adder3res1) {$res_1$};
\node[right=2mm of adder3res1] (adder3res0) {$res_0$};
\node[right=5mm of adder3.east] (cin3) {$0$};
\draw (cin3) -- (adder3.east);
\node[below=1cm of adder3res0] (prod3) {$prod_3$};
\draw (prod3.north) -- ++(90:9mm);
\node[below=1cm of adder3res1] (prod4) {$prod_4$};
\draw (prod4.north) -- ++(90:9mm);
\node[below=1cm of adder3res2] (prod5) {$prod_5$};
\draw (prod5.north) -- ++(90:9mm);
\node[below=1cm of adder3res3] (prod6) {$prod_6$};
\draw (prod6.north) -- ++(90:9mm);
\node[left=1cm of prod6] (prod7) {$prod_z$};
\draw (prod7.north) |- (adder3.west);
\end{tikzpicture}
\caption{4-Bit Multiplizierer}
\label{fig:4bitmul}
\end{figure}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment