1

Is there a simple way to draw blackbox circuits in latex where I can connect lines to the inputs and outputs? The assignment is to draw a 4-bit CPU, so I'm trying to find a clean way to specify everything.

An example of a full-adder blackbox circuit:

Full-adder blackbox

  • Have you tried with the circuitikz package ? – Jérôme Dequeker Nov 12 '15 at 17:45
4

Just an idea. The main problem will be to adjust labels position inside main node.

\documentclass[tikz,border=2mm]{standalone}
\usepackage{amsmath}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[
    fulladder/.style={draw, minimum size=3cm,
    label={[xshift=8mm]left:$c_\text{out}$},
    label={[yshift=5mm]below:$s$},
    label={[xshift=-6mm]right:$c_\text{in}$},
    label={[yshift=-3mm, anchor=center]65:$b$},
    label={[yshift=-3mm, anchor=center]115:$a$},
    }]

    \node[fulladder] (a) {};
    \node[fulladder, right=1cm of a] (b) {};

    \draw[<-] (a.115) --++(90:0.5cm) node [above] {$a_1$};
    \draw[<-] (a.65) --++(90:0.5cm) node [above] {$b_1$};
    \draw[<-] (b.115) --++(90:0.5cm) node [above] {$a_0$};
    \draw[<-] (b.65) --++(90:0.5cm) node [above] {$b_0$};
    \draw[<-] (b.east) --++(0:0.5cm) node [right] {$0$};
    \draw[<-] (a.east) -- (b.west);
    \draw[->] (a.west) --++(180:0.5cm) node [left] {$c$};
    \draw[->] (a.south) --++(-90:0.5cm) node [below] {$s_1$};
    \draw[->] (b.south) --++(-90:0.5cm) node [below] {$s_0$};

\end{tikzpicture}

\end{document}

enter image description here

Update: Easily adjusted labels

I've learned how to better adjust labels inside nodes from Torbjørn's answer to How to draw architecture with tikz.

Previous code with new label's declaration could be:

\documentclass[tikz,border=2mm]{standalone}
\usepackage{amsmath}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[
    fulladder/.style={draw, minimum size=3cm,
    label={[anchor=west]left:$c_\text{out}$},
    label={[anchor=south]below:$s$},
    label={[anchor=east]right:$c_\text{in}$},
    label={[anchor=north]65:$b$},
    label={[anchor=north]115:$a\vphantom{b}$},
    }]

    \node[fulladder] (a) {};
    \node[fulladder, right=1cm of a] (b) {};

    \draw[<-] (a.115) --++(90:0.5cm) node [above] {$a_1$};
    \draw[<-] (a.65) --++(90:0.5cm) node [above] {$b_1$};
    \draw[<-] (b.115) --++(90:0.5cm) node [above] {$a_0$};
    \draw[<-] (b.65) --++(90:0.5cm) node [above] {$b_0$};
    \draw[<-] (b.east) --++(0:0.5cm) node [right] {$0$};
    \draw[<-] (a.east) -- (b.west);
    \draw[->] (a.west) --++(180:0.5cm) node [left] {$c$};
    \draw[->] (a.south) --++(-90:0.5cm) node [below] {$s_1$};
    \draw[->] (b.south) --++(-90:0.5cm) node [below] {$s_0$};

\end{tikzpicture}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.