**Computer Logic and Organization for Beginners - Part 2**

- Introduction
- Logisim
- Our First Circuit: 1 bit adder
- 4 bit adder
- Other arithmetic

**1.)Introduction**

Hello, and welcome to part 2 of my Computer Logic and Organization series. This is a continuation of the more hardware look on how the inner workings of the computer works. In this tutorial, we'll go through the basics of building our first circuit. I'm using a free software I used at Wright State University that simulates the circuits virtually.

Computer Logic and Organization for Beginners Pt 1

**2.) Logisim**

Logisim is a free software I have used before that digitally simulates circuits. It gives you all kinds of functionality, so I'm going to give you a quick crash course. You can download Logisim here. Once you have it downloaded, just save it somewhere familiar.

This is the basic layout. I don't know for sure what all the stuff is officially called, so I just called it "goodies window" and workbench. If you open the folders, you can see the various premade components ready for use for whatever devious tasks you plan. But where's the fun in premade stuff when we can make our own?! />/>/> Anywho, you can go ahead and poke around a bit if you want.

**3.) Our First Circuit: 1 Bit Adder**

So we're gonna learn how to add 2 1-bit numbers together. How freaking exciting, huh? But how do we do this? Since it's only 2 1-bit numbers, we can just use a truth table. Z = X + Y and Cout is the carry out for the overflow, because 1 + 1 = 2, which is 10, which is 2 bits.

X Y | Z Cout

------------

0 0 | 0 0

0 1 | 1 0

1 0 | 1 0

1 1 | 0 1

You know what, lets get crazy and add a carry in bit! Just for funsies (also for portability). C = carry in. Normally I'd write Cin but it's easier to type. />/>/>

C X Y | Z Cout

--------------

0 0 0 | 0 0

0 0 1 | 1 0

0 1 0 | 1 0

0 1 1 | 0 1

1 0 0 | 1 0

1 0 1 | 0 1

1 1 0 | 0 1

1 1 1 | 1 1

So how do we turn this into a circuit, you may ask? Lets do a K-map! Yay, using what we learned!

I don't recall a table function so I just used wires to make the maps lol. For the output Z, we can see that it's a checkerboard. This means XOR. The Cout is slightly more complicated. I wrote out the equation for ya. So now lets turn those equations into a circuit!

You can use the hand tool to flip the bits to check that the inputs and outputs match your table. For all the gates I changed the number of inputs to 2 and made the gate size narrow so it's not freaking huge. Now for the XOR gate, in order to get it to work properly, you need to change the multi-input behavior to true when odd like so.

Now we have our first circuit! Fun! Save it as something useful, say, 1bitadder.circ like I did. Go ahead and just click the green plus sign (or go to program -> add new circuit) and create one called 1bitadder. Cut and paste the circuit into the new circuit.

**4.) 4 Bit Adder**

Just like with OOP, 'encapsulation' is WAAYYYYY easier than reinventing the wheel. This is why I added a carry out and a carry in, because you can pass the carry out to the carry in of another adder, and that way we can 'stack' them to make, say, a 4 bit adder, or even an 8 bit, 16 bit, etc. Go ahead and create yet another circuit called 4bitadder. Click on 1bitadder and put 4 of them in the new circuit, like so:

I was lazy and haven't put it in a new circuit yet, so it's just in main. I changed the bits to 4 bits and used splitters. Not the prettiest thing, but I'm half asleep. Noticed how I used the carry outs for the carry ins. The most significant bit is towards the top.

I think this will conclude this episode of the series. Next time we'll look at some other arithmetic functions and how to build circuits on them, and maybe even our first ALU! Cheers!

This post has been edited by **modi123_1**: 09 September 2014 - 06:24 PM