Need Help On Calculator circuit

Thread Starter

warnexus

Joined Nov 17, 2012
23
HI, True, and 1 are all pretty much synonyms. When talking about pure logic, True/False (or T/F) are probably the best terms to use. When talking about actual logic circuits, HI/LO are probably the best (and refer to the two possible voltage values of the circuit, namely the HIgher of the two and the LOwer of the two). When talking about arithmetic circuits, 1/0 are probably best.



Thanks, and not a problem. That's why I'm leading you along but letting you struggle to actually get there. That's how you learn the best because you learn in a way that makes sense to you.



Your last circuit did have the sign extender done correctly. The idea you want to have is the notion that you bring a 4-bit two's complement value into a box and take out from that box an 8-bit two's complement value that you then take to your adder. What goes on inside that box? Not that you don't need any components in that box; it can be done just with how you wire the inputs to the outputs.

Now, think of what is different between your A+B and A-B circuits. It would appeat that you need a circuit that uses a control input in order to either pass a value through unchanged or to invert the value, based on the state of the control input. So draw a truth table for all of the possible combinations of the control input and the value (a 1-bit value) and what the 1-bit value should be for each case. Does this logic table look familiar to you?

For the multiplier, walk through the steps you would use to multiply two 4-bit values together. Now see if you can determine the associated logic functions that happen at each step. Note that there are lots of ways to implement an adder, but your goal is to come up an just one way that works -- you can worry about efficiency and elegance later.
Oh nice so HI means HIGH.

yes, I am familiar with the six logic gates and the values that they produce. the thing is the 1 bit value you mention for the truth table depends on the type of gate used.

If my circuit was finished in its entirety, it supposed to use a 2 bit control to perform various calculation on the 4 bit 2's complement numbers.
If the 2 bit control = 00 my output is suppose to be a 8 bit 2's complement number with all 0's
if the control = 01 the circuit is suppose to output the sum from the addition circuit
if the control = 10 the circuit is suppose to output the difference from the subtraction circuit
if the control = 11 the circuit is suppose to output the product from the multiplication circuit.

this is what I came up for multiplication circuit after going through my lecture notes. it's not pretty at the moment but it gives the correct result.

Is wiring 4 rightmost location of the 4 ALUs(which is the control) supposed to be wired to the control on the right since they are all controls?

 
Last edited:

WBahn

Joined Mar 31, 2012
30,058
Describe what this 1-bit ALU of yours is supposed to do.

I don't think you followed the point of my question. Take a step back and forget about this problem you are trying to solve for a moment. Think of this as an unrelated problem (it isn't, but think of it that way for now).

You have an input signal A.

You have a control bit C.

You want to send both into a logic circuit that has a single output, Y.

When C is LO, you want Y to be equal to A. When C is HI, you want Y to be equal to the opposite of A, namely A'.

What is the logic circuit that takes A and C as inputs and produces Y as the output?
 

Thread Starter

warnexus

Joined Nov 17, 2012
23
Describe what this 1-bit ALU of yours is supposed to do.

I don't think you followed the point of my question. Take a step back and forget about this problem you are trying to solve for a moment. Think of this as an unrelated problem (it isn't, but think of it that way for now).

You have an input signal A.

You have a control bit C.

You want to send both into a logic circuit that has a single output, Y.

When C is LO, you want Y to be equal to A. When C is HI, you want Y to be equal to the opposite of A, namely A'.

What is the logic circuit that takes A and C as inputs and produces Y as the output?
i'm pretty sure there is two input signal to that circuit with one control bit the 2 input mux has such a feature.
 

WBahn

Joined Mar 31, 2012
30,058
i'm pretty sure there is two input signal to that circuit with one control bit the 2 input mux has such a feature.
Yes, you can implement the function with a two-input MUX and an inverter. But if you would write out the truth table, you will see that you can do it with a single, standard logic gate.
 

Thread Starter

warnexus

Joined Nov 17, 2012
23
Yes, you can implement the function with a two-input MUX and an inverter. But if you would write out the truth table, you will see that you can do it with a single, standard logic gate.
I will write the truth table here:
Input| Control| Output
-------------
A | 0 |A
A |1 |A'(Not A)
 

Thread Starter

warnexus

Joined Nov 17, 2012
23
The not gate corresponds with input a and control bit you spoke of. The truth table is before this post. And that I think about it, it is a controlled not gate since you mentioned a control bit.

the 1 bit alu is suppose to multiply the bits together something like:

(Sign Extend the bits ) A1 A0
(Sign Extend the bits) X B1 B0
-----------------
(A1*B0)(A0*B0)
+(A1*B1)(A0*B1)
-----------------------------

The full adder will take care of the adding and the carry outing.
 
Last edited:

WBahn

Joined Mar 31, 2012
30,058
I will write the truth table here:
Input| Control| Output
-------------
A | 0 |A
A |1 |A'(Not A)
This is not a proper truth table, though it is compact and correct. But sometimes you need a proper truth table to see the underlying structure. A proper truth table enumerates every possible input condition and specifies the output for each.

Consider the following truth table:

A = Input
C = Control
Y = Output

C|A|Y
0|0|0
0|1|1
1|0|1
1|1|0

Does this look familiar?
 

Thread Starter

warnexus

Joined Nov 17, 2012
23
ah yes! the xor(exclusive or) gate. i think you are suggesting using an exclusive or gate to invert all the inputs of B so thats a total of 8 exclusive or gates to use! I think I am over-complicating things now o.0
 
Last edited:

WBahn

Joined Mar 31, 2012
30,058
ah yes! the xor(exclusive or) gate. i think you are suggesting using an exclusive or gate to invert all the inputs of B so thats a total of 8 exclusive or gates to use! o.0
Yes. An XOR gate acts as either a buffer or an inverter of one signal, depending on the state of another signal (the control).

You can use 8, or you could use 4 by putting them before your sign extender. Your choice.

For the multiplier... I'm a bit surprised that they are throwing this at you, particularly a signed multiplier. There are some subtleties associated with 2's complement multiplication. Multiply, say, (-2) and (-3) as four bit 2's complement numbers and see if you can recognize them.
 

Thread Starter

warnexus

Joined Nov 17, 2012
23
Yes. An XOR gate acts as either a buffer or an inverter of one signal, depending on the state of another signal (the control).

You can use 8, or you could use 4 by putting them before your sign extender. Your choice.

For the multiplier... I'm a bit surprised that they are throwing this at you, particularly a signed multiplier. There are some subtleties associated with 2's complement multiplication. Multiply, say, (-2) and (-3) as four bit 2's complement numbers and see if you can recognize them.
well i know in 3 bit form -2 in 2's complement is 110 and -3 is 101 hmm I need to think about this some more. oh now I got it! -2 is 0110 and -3 is 0101 in 4 bits.

i remember when i first took my first test i remember I had to sign extend the sign bit of the operands before I perform multiplication on the binary number. Now that I think about if I test input 1111(15 in binary) and another input 1111(15) my input would be 225 in binary (11100001) which is an 8 input result. I guess I do not need to sign extend for multiplication after all. =]
 
Last edited:

WBahn

Joined Mar 31, 2012
30,058
well i know in 3 bit form -2 in 2's complement is 110 and -3 is 101 hmm I need to think about this some more. oh now I got it! -2 is 0110 and -3 is 0101 in 4 bits.
Does that make sense? If I gave you the four bit values 0110 and 0101 and told you that they are represented in two's complement, what values would you say they represented? Would you say they are positive or negative?

i remember when i first took my first test i remember I had to sign extend the sign bit of the operands before I perform multiplication on the binary number. Now that I think about if I test input 1111(15 in binary) and another input 1111(15) my input would be 225 in binary (11100001) which is an 8 input result. I guess I do not need to sign extend for multiplication after all. =]
No? Work some examples and see.
 

Thread Starter

warnexus

Joined Nov 17, 2012
23
My answer did not make sense the sign bit is suppose to tell you the sign of 2's complement number. It should have put 1110 instead of 0110 for -2. I should put 1101 instead of 0101 for -3.
 

WBahn

Joined Mar 31, 2012
30,058
My answer did not make sense the sign bit is suppose to tell you the sign of 2's complement number. It should have put 1110 instead of 0110 for -2. I should put 1101 instead of 0101 for -3.
Good. So now take these two 4-bit two's complement values and try to multiply them to get an 8-bit two's complement result. You know what the answer has to turn out to be, namely +6. Do you get it?
 

WBahn

Joined Mar 31, 2012
30,058
yes after sign extending both 2's complement number and multiplying each other I got 00000110 (+6) as my result
Good. The point that you have hopefully seen is that you must sign extend the inputs to match the width of the output representation BEFORE you carry out the addition, subtraction, multiplication, or any other arithmetic operation.

Technically (and don't worry if you don't follow this), the reason is because the algorithms that we developed to perform binary arithmetic on N-bit wide straight binary values do nothing but map input values in a mod-2^N world onto other values (the output values) in that same mod-2^N world. We chose to use what is called the "least residue system" to enumerate this world and chose the mapping such that the results match what we want to see when the input and output values are interpreted as straight binary values. When we define two's complement, all we are really doing is simply choosing a different residue system to enumerate this world. As a consequence, the algorithms we came up with still work because they are still performing mappings in that same mod-2^N world, we are just choosing to use a different enumeration to interpret the results.

But, the math only works within each separate mod-2^N world. So it simply doesn't work (at least not for all possible input values) if the inputs are not ALL N-bit and if the outputs aren't ALL N-bit.
 

Thread Starter

warnexus

Joined Nov 17, 2012
23
Yeah that's too mathematical for me:) getting the 2's complement numbers to multiply is the biggest obstacle yet. I tried using alu but I'm not sure if there is a simpler way. I know the alu is for doing arithmetic but I do not know fundamentally how to apply it in circuit design :(
 

WBahn

Joined Mar 31, 2012
30,058
Well, before you can use an ALU you have to at least understand what it is doing and just "knowing" that it "is for doing arithmetic" doesn't qualify. At the very least, you have to know what will appear at the outputs in terms of the inputs and how those relate to arithmetic or logic operations. Without that knowledge, you are left with making random circuits and hoping that something wonderful will somehow happen.
 

Thread Starter

warnexus

Joined Nov 17, 2012
23
let's see 1 bit Alu, if the control becomes 0, the output is a multiplication result. if the control becomes 1, the output is a sum result. if i was to create a circuit that does multiplication, how do I know whether to use 1 bit, 2 bit or 4 bit ALU or is it entirely up to me. If so, would using 1 bit AlU mean more work on my part?
 

WBahn

Joined Mar 31, 2012
30,058
Okay, so let's say that I hand you as many 1-bit ALUs as you want. How many would you need to ask for in order to multiply two 2-bit straight binary numbers together to get a 4-bit result? How many would you need if the numbers are 2's complement values?
 
Top