mubase 0 Report post Posted January 25, 2013 Hi all. I recieved my LogicStart today so as I have a few hours spare I thought I'd get cracking wth Hamster's PDF of tutorials and info. I've just finished making a 4 bit adder using the swithces and LEDs of the board and would like to know if my code looks right. It seems to work.. From right to left, the switches in 2 groups of 4 seem to add up all the way to 15.The code is here:entity switches_leds is Port ( switches : in STD_LOGIC_VECTOR(7 downto 0);LEDs : out STD_LOGIC_VECTOR(7 downto 0));end switches_leds;architecture Behavioral of switches_leds issignal x : STD_LOGIC_VECTOR (3 downto 0);signal y : STD_LOGIC_VECTOR (3 downto 0);signal carry : STD_LOGIC_VECTOR (3 downto 0);signal result : STD_LOGIC_VECTOR (4 downto 0);beginLEDs <= "000" & result;x <= switches (3 downto 0);y <= switches ( 7 downto 4 );result(0) <= x(0) XOR y(0);carry(0) <= x(0) AND y(0);result(1) <= x(1) XOR y(1) XOR carry(0);carry(1) <= (x(1) AND y(1)) OR (carry(0) AND x(1)) OR (carry(0) AND y(1));result(2) <= x(2) XOR y(2) XOR carry(1);carry(2) <= (x(2) AND y(2)) OR (carry(1) AND x(2)) OR (carry(1) AND y(2));result(3) <= x(3) XOR y(3) XOR carry(2);carry(3) <= (x(3) AND y(3)) OR (carry(2) AND x(3)) OR (carry(2) AND y(3));--result(4) <= x(4) XOR y(4) XOR carry(3);--carry(4) <= x(4) AND y(4) OR (carry(3) AND x(4)) OR (carry(3) AND y(4));end Behavioral; I have some boolean experience having gone to college to do an access course in Audio electronics/music technology and being thrown in the deep end of boolean logic. :sAt the time all of us in the class were wondering where it all fitted in with Audio systems electronics but I am glad of it now. If someone could verify this for me I'd be much appreciative.All the best,Steve. Share this post Link to post Share on other sites
alvieboy 25 Report post Posted January 25, 2013 You can try this in a different way, like explained on my basic tutorial: http://alvie.com/zpuino/vhdl1.html You'll have a 4-bit adder on the third example. Alvie Share this post Link to post Share on other sites
hamster 47 Report post Posted January 26, 2013 Steve! Looking good... you could just assign result(4) the value of carry(4)., and then you could add all the way to 30! Share this post Link to post Share on other sites
mubase 0 Report post Posted January 26, 2013 Hi! thats great to hear! I'll try the suggestions and then try and tackle the subtractor...:s Share this post Link to post Share on other sites