{"id":7150,"date":"2019-01-04T15:18:18","date_gmt":"2019-01-04T15:18:18","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=7150"},"modified":"2019-01-08T11:58:47","modified_gmt":"2019-01-08T11:58:47","slug":"using-linux-for-logic-linux-journal","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/01\/04\/using-linux-for-logic-linux-journal\/","title":{"rendered":"Using Linux for Logic | Linux Journal"},"content":{"rendered":"<p>I&#8217;ve covered tons of different scientific<br \/>\napplications you can run on your computer to do rather complex<br \/>\ncalculations, but so far, I&#8217;ve not really given much thought to<br \/>\nthe hardware on which this software runs. So in this article, I take a look at<br \/>\na software package that lets you dive deep down to the level of the<br \/>\nlogic gates used to build up computational units.<\/p>\n<p>At a certain point,<br \/>\nyou may find yourself asking your hardware to do too much work. In those cases,<br \/>\nyou need to understand what your hardware is and how it works. So,<br \/>\nlet&#8217;s start by looking at the lowest level: the lowly<br \/>\nlogic gate. To that end, let&#8217;s use a software package named <a href=\"http:\/\/www.cburch.com\/logisim\/index.html\">Logisim<\/a><br \/>\nin order to play with logic gates in various groupings.<\/p>\n<p>Logisim should be available in most distributions&#8217; package management<br \/>\nsystems. For example, in Debian-based distros, install it<br \/>\nwith the following command:<\/p>\n<p>sudo apt-get install logisim<\/p>\n<p>You then can start it from your desktop environment&#8217;s menu,<br \/>\nor you can open a terminal, type logisim and press<br \/>\nEnter. You should see a main section of the application<br \/>\nwhere you can start to design your logic circuit. On the left-hand side,<br \/>\nthere&#8217;s a selection pane with all of the units you can use for your<br \/>\ndesign, including basic elements like wires and logic gates, and<br \/>\nmore complex units like memory or arithmetic units.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.linuxjournal.com\/sites\/default\/files\/styles\/max_650x650\/public\/u%5Buid%5D\/logisim1.png\" alt=\"&quot;&quot;\" width=\"650\" height=\"404\" \/><\/p>\n<p><em>Figure 1. When you first start Logisim, you get a blank project where<br \/>\nyou can start to design your first logic circuit.<\/em><\/p>\n<p>To learn how to start using Logisim, let&#8217;s look at how to set up one of<br \/>\nthe most basic logic circuits: an AND gate.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.linuxjournal.com\/sites\/default\/files\/styles\/max_650x650\/public\/u%5Buid%5D\/logisim2.PNG\" alt=\"&quot;&quot;\" width=\"650\" height=\"528\" \/><\/p>\n<p><em>Figure 2. You easily can add logic gates to your circuit to model<br \/>\ncomputations.<\/em><\/p>\n<p>If you click the<br \/>\nGates entry on the left-hand side, you&#8217;ll see a full list of available<br \/>\nlogic gates. Clicking the AND gate allows you to add them to the design<br \/>\npane by clicking on the location where you want them added. At the bottom<br \/>\nof the left-hand side, you&#8217;ll see a pane that displays the attributes<br \/>\nof the selected gate. You can use this pane to edit those attributes to<br \/>\nmake the gate behave exactly the way you want. For this example,<br \/>\nlet&#8217;s change the number of inputs value from 5 to 2. The next<br \/>\nstep is to add an output pin in order to see when the output is either<br \/>\n1 or 0. You can find pins in the wiring section.<\/p>\n<p>On the front side of the<br \/>\nAND gate, you&#8217;ll want to add pins so you can control input. In the<br \/>\nattributes for each of the pins, you&#8217;ll see that you can change whether<br \/>\nthe pin is supposed to be an output pin. You also can set whether<br \/>\nthe pin is supposed to be a three-state pin.<\/p>\n<p>The last step is to<br \/>\nconnect all of these pieces by simply clicking and dragging<br \/>\nbetween the separate components.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.linuxjournal.com\/sites\/default\/files\/styles\/max_650x650\/public\/u%5Buid%5D\/logisim3.PNG\" alt=\"&quot;&quot;\" width=\"650\" height=\"517\" \/><\/p>\n<p><em>Figure 3. You can add extra items, like inputs and outputs, to your<br \/>\nlogic circuit.<\/em><\/p>\n<p>By default, the input pins<br \/>\ncurrently are set to 0, so once the wires are connected, you should see<br \/>\nthat the output is set to 0. In order to toggle the input pins, you first need<br \/>\nto select the toggle tool from the toolbar at the top of the window<br \/>\n(the one shaped like a pointing hand). Once you have selected this tool,<br \/>\nyou can click on the input pins to change their states. Once both inputs<br \/>\nare set to 1, you should see the output flip to 1 also.<\/p>\n<p>While you can build your circuits up from first principles and see how<br \/>\nthey behave, Logisim also lets you define the behavior first and generate<br \/>\na circuit that gives you the defined behavior. Clicking the<br \/>\nWindow\u2192Combinational Analysis menu item pops up a new window where you can<br \/>\ndo exactly that.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.linuxjournal.com\/sites\/default\/files\/styles\/max_650x650\/public\/u%5Buid%5D\/logisim4.PNG\" alt=\"&quot;&quot;\" width=\"650\" height=\"580\" \/><\/p>\n<p><em>Figure 4. You can build up your logic circuits in reverse by defining<br \/>\nthe behavior you wanted first, then allowing it to generate a circuit that<br \/>\ngives you this required behavior.<\/em><\/p>\n<p>The first step is to provide a list of<br \/>\ninputs. You simply add a series of labels, one for each input. For this<br \/>\nexample, you&#8217;ll define an x, y and z. Next, you&#8217;ll need to click<br \/>\nthe outputs tab and do the same for the number of outputs you want to<br \/>\nmodel. Let&#8217;s just define a single output for this example.<\/p>\n<p>The last step<br \/>\nis actually to define the behavior linking the inputs to the outputs. This<br \/>\nis done through a logic table. So here, you&#8217;ll have the output<br \/>\nas 0, unless either x and z or y and z are high.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.linuxjournal.com\/sites\/default\/files\/styles\/max_650x650\/public\/u%5Buid%5D\/logisim5.PNG\" alt=\"&quot;&quot;\" width=\"650\" height=\"580\" \/><\/p>\n<p><em><br \/>\nFigure 5. Logisim includes a tool that allows you to generate logic circuits<br \/>\nbased on a truth table that you define to handle the computation you&#8217;re<br \/>\ninterested in modeling.<\/em><\/p>\n<p>Once<br \/>\nyou&#8217;re happy with the definition, click the Build Circuit<br \/>\nbutton at the bottom of the window. This pops up a new dialog window<br \/>\nwhere you can define the name and select the destination project, as<br \/>\nwell as choosing whether to use only NAND gates or only 2-input<br \/>\ngates.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.linuxjournal.com\/sites\/default\/files\/styles\/max_650x650\/public\/u%5Buid%5D\/logisim6.PNG\" alt=\"&quot;&quot;\" width=\"650\" height=\"517\" \/><\/p>\n<p><em>Figure 6. By using the Combinational Analysis window, you can create<br \/>\nmore complex circuits based purely on their expected behavior.<\/em><\/p>\n<p>You can click on the inputs to toggle them and<br \/>\nverify that everything behaves as you had planned.<br \/>\nThe Combinational Analysis window has two other tabs: Expression and Minimized. The<br \/>\nExpression tab shows you the logical mathematical expression that<br \/>\ndescribes the truth table you defined. You can edit your<br \/>\ncircuit further by editing this equation directly. The minimized tab gives you<br \/>\nthe logical equation as either the sum of products or the product of sums.<\/p>\n<p>Once you finish your circuit, you can save it in a .circ<br \/>\nfile. These files define a complete circuit that can be reused as a single<br \/>\nunit. When you do want to reuse them in a larger, more complex circuit,<br \/>\nclick Project\u2192Load Library\u2192Logisim Library and<br \/>\nselect the saved file. This allows you to build up very<br \/>\ncomplicated computing circuits rather quickly.<\/p>\n<p>You also can export the circuit itself<br \/>\nby clicking File\u2192Export Image. This allows you<br \/>\nto save the circuit as an image that you can use in a report or<br \/>\nsome other process.<\/p>\n<p>This is just a brief introduction, but I hope Logisim helps you learn a bit more<br \/>\nabout the fundamentals of computing and logical structures.<\/p>\n<p><a href=\"https:\/\/www.linuxjournal.com\/content\/using-linux-logic\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve covered tons of different scientific applications you can run on your computer to do rather complex calculations, but so far, I&#8217;ve not really given much thought to the hardware on which this software runs. So in this article, I take a look at a software package that lets you dive deep down to the &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/01\/04\/using-linux-for-logic-linux-journal\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Using Linux for Logic | Linux Journal&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7150","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/7150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=7150"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/7150\/revisions"}],"predecessor-version":[{"id":7488,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/7150\/revisions\/7488"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=7150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=7150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=7150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}