How can I do 2A+3B(3 bits) with 4 bit ALU?

Thread Starter

ulas94

Joined Mar 26, 2016
7
Hi. I have a question about ALU design. I have A and B variables which are 3-bit and ALU which has 4-bit inputs.My purpose is adding up 2A+3B but I can use ALU one time. How can I do it?

q2.jpg
 

Thread Starter

ulas94

Joined Mar 26, 2016
7
For example I have two variable A and B which are 4-bit and I want to make 2A plus B and save the answer in 8-bit register.

Solution:
toplama.jpg blokdiagram.jpg

Answer of my question will be like this but I can't do 2A plus 3B ( A and B 3-bits) and I need help :)
 

WBahn

Joined Mar 31, 2012
29,932
What is the maximum value that 2A + 3B can have? Can that be represented by the output, including carry, of a 4-bit adder?

How many bits are required to represent it?

You circuit diagram embodies some of what you need to do. Do you know which parts those are? Did you come up with that circuit diagram yourself? If so, think about why you made the connects you did and what parts of the math are taken care of and what parts aren't.

And remember that it IS a math function you are trying to implement, so play with the math.

For example, see if something like

Y = 2A + 3B = 2(A+B) + B

helps you out.
 

kubeek

Joined Sep 20, 2005
5,793
I think you should be able to use the S inputs, so that you can put A<<1 to Ain, B<<1 to Bin and B to Sin so that you get 2A+2B+1B.
(A<<1 being A shifted left by one bit)
 
Last edited:

Thread Starter

ulas94

Joined Mar 26, 2016
7
I think put B to Select pins wrong choice because if I apply 000 to B , the F will be 0 although A is not 0
 

kubeek

Joined Sep 20, 2005
5,793
Oh sorry my mistake, i thought that S was the carry in, when in fact it is the mode select. Disregard my previous post.
My first idea was that +3B could be equal to -1B if the size of the processing busses was just right. I think this idea needs some practice becaues the ALU you described doesn't really cover all the possibilities of 4bit inputs and the according results.
So i suggest you try the A-B op code and see if it gets you anywhere.
 

Thread Starter

ulas94

Joined Mar 26, 2016
7
Yes this ALU works unsigned numbers I understand(but I don't know :) ) so inputs must be positive therefore signed numbers can be confusing in this scenario.
My approximation like this
20160328_030537.jpg
B0 is going to D0 directly and A0 and B0 are going to ALU's A0 and B0 respectively and B1 is going to Cn but I have hanged out there because A1+B1+B2 does not happen.Probably I should use ALU's A3 and B3 bits which are not used in the above event
 

djsfantasi

Joined Apr 11, 2010
9,155
Is "Not Possible" a valid answer? Given that the ALU can only be used once, that would be my answer. Because the function as defined has three operations. 2A can be calculated without using the ALU. But 3B needs to use the ALU. Leaving no way (since the ALU can only be used once) to add the two terms.
 

WBahn

Joined Mar 31, 2012
29,932
Is "Not Possible" a valid answer? Given that the ALU can only be used once, that would be my answer. Because the function as defined has three operations. 2A can be calculated without using the ALU. But 3B needs to use the ALU. Leaving no way (since the ALU can only be used once) to add the two terms.
I'm not quite convinced it's not possible yet. There is an easy way to get all but the msb of B of the odd term taken care of (so 2A + 2B + B%4). But I'm not seeing any way to get that last bit in there.
 
Top