hey guys. Pulling my long beautiful hair out over this one
My class was assigned to write an ALU using mostly binary arithmetic, rather VHDL's built in functions. kind of a pain but rather educational. We're given 2 3bit inputs, plus a 3 bit input for selecting the functions.
So my ALU works. Except for one little tiny part on multiplication. Everything works beautifuly, except 7 x7. I dont get it.
The top half of my code, checks to see bit of the input_B, and AND's that to bring it down. i set up my vectors to go X, Y, Z
I would have preferred to simply read it as (Iput_A AND Input_B(0)) so on and so fourth, but this apparently isnt allowed? It errors out. Anyways. I "bypassed" that by using If Then.
The loop/lines of crazy math are the adders. This is where im thinking i have an issue?
so
But, this worked, until i enter 111 x 111
SO i tried to break it down completely manually in case i had an incremenet wrong with the loop
Alas, same result. Everything works perfectly. EXCEPT the entering of 111x111. The out put i SHOULD get is 110001. What i get is 101001. Where did i botch up? obvously my 4th bit isnt carrying over on this number?
So what am i doing wrong guys?
I know not the cleanest and most efficient of code, but im tryin!
Thanks in advance!
My class was assigned to write an ALU using mostly binary arithmetic, rather VHDL's built in functions. kind of a pain but rather educational. We're given 2 3bit inputs, plus a 3 bit input for selecting the functions.
So my ALU works. Except for one little tiny part on multiplication. Everything works beautifuly, except 7 x7. I dont get it.
The top half of my code, checks to see bit of the input_B, and AND's that to bring it down. i set up my vectors to go X, Y, Z
I would have preferred to simply read it as (Iput_A AND Input_B(0)) so on and so fourth, but this apparently isnt allowed? It errors out. Anyways. I "bypassed" that by using If Then.
The loop/lines of crazy math are the adders. This is where im thinking i have an issue?
so
Rich (BB code):
101 --Input_A
011 --Input_B
--------
101 --X
1010 --Y
10100 --Z
---------------
001111 --Sum
^
|
Carry(0)
Rich (BB code):
function Multiplication (A_Input, B_Input: std_ulogic_Vector(2 downto 0)) Return Std_ulogic_vector is
Variable x, y, z: std_ulogic_vector(4 downto 0):="00000";
variable sum, carry: std_ulogic_vector(5 downto 0):="000000";
begin --For whatever reason, VHDL won't directly compare a bit in a vector, so we manually break it down
--Compares the bits in B_Input and AND's A_Input down
if (B_Input(0) = '0') then
x(2 downto 0):= ("000" AND A_Input);
else
x(2 downto 0):= ("111" AND A_Input);
end if;
if (B_Input(1) = '0') then
y(3 downto 1):= ("000" AND A_Input);
else
y(3 downto 1):= ("111" AND A_Input);
end if;
if (B_Input(2) = '0') then
z(4 downto 2):= ("000" AND A_Input);
else
z(4 downto 2):= ("111" AND A_Input);
end if;
sum(0):=x(0); --Sets up bit(0) of the answer
for I in 1 to 4 loop --Finds bits 1 through 4 for the final result
sum(I):= x(I) xor y(I) xor z(I) xor carry(I-1);
carry(I):= (x(I) and y(I)) or (y(I) and z(I)) or (z(I) and x(I)) or (carry(I-1) AND x(I))
OR (carry(I-1) and y(I)) OR (carry(I-1) and z(I));
end loop;
sum(5):=carry(4);
return sum;
end Multiplication;
SO i tried to break it down completely manually in case i had an incremenet wrong with the loop
Rich (BB code):
sum(0):=x(0);
sum(1):=x(1) xor y(1) xor z(1);
carry(1):=(x(1) and y(1)) OR (y(1) and z(1));
sum(2):=x(2) xor y(2) xor z(2) xor carry(1);
carry(2):=(x(2) and y(2)) OR (y(2) and z(2)) or (carry(1) and x(2)) or (carry(1) and y(2)) or (carry(1) and z(2));
sum(3):=x(3) xor y(3) xor z(3) xor carry(2);
carry(3):=(x(3) and y(3)) OR (y(3) and z(3)) or (carry(2) and x(3)) or (carry(2) and y(3)) or (carry(2) and z(3));
sum(4):=x(4) xor y(4) xor z(4) xor carry(3);
carry(4):=(x(4) and y(4)) OR (y(4) and z(4)) or (carry(3) and x(4)) or (carry(3) and y(4)) or (carry(3) and z(4));
sum(5):= (x(4) and y(4)) or (y(4) and z(4)) or (x(4) and z(4)) or (carry(4) and x(4)) or (carry(4) and y(4)) or (carry(4) and z(4));
So what am i doing wrong guys?
I know not the cleanest and most efficient of code, but im tryin!
Thanks in advance!