Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

4-bit binary adder and subtractor spartan 3

Status
Not open for further replies.

merkat

Newbie level 2
Newbie level 2
Joined
Dec 1, 2012
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,292
Hello,
I'm new here on the forum and generally in vhdl programming.

I have to write a code for a 4-bit binary adder and subtractor, but subtraction need to be performed only if the minuend has greater value than subtrahend. Input combinations are supposed to be set via switches on SPARTAN 3. And then the result of adding and subtracting need to be shown on 7 segment display of SPARTAN 3 board.

Can anybody help me to write a code for that?
 

Can someone tell me will this work and if not what should I change? This is the part for adder only.

Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity zbrajalo is
port
	(
	an0 : inout std_logic;
	an1 : inout std_logic;
	an2 : inout std_logic;
	an3 : inout std_logic;
	btn0: in std_logic;
	a: in std_logic_vector (3 downto 0);
	b: in std_logic_vector (3 downto 0);
	led : out std_logic_vector (7 downto 0)
	);
end zbrajalo;

architecture Behavioral of zbrajalo is

begin
process (btn0)
variable s : std_logic_vector (4 downto 0):="00000";
begin
		if(btn0='1') then
			s:=a+b;
			if(an0='0') then
				if(s(1)='0') then
					an0<='1';
					led<="00000011";
					an1<='0';
				elsif(s(1)='1') then
					an0<='1';
					led<="10011111";
					an1<='0';
				end if;
			elsif(an1='0')then
				if(s(2)='0')then
					an1<='1';
					led<="00000011";
					an2<='0';
				elsif(s(2)='1') then
					an1<='1';
					led<="10011111";
					an2<='0';
				end if;
			elsif(an2='0')then
				if(s(3)='0')then
					an2<='1';
					led<="00000011";
					an3<='0';
				elsif(s(3)='1') then
					an2<='1';
					led<="10011111";
					an3<='0';
				end if;
			elsif(an3='0')then
				if(s(0)='0')then
					an3<='1';
					led<="00000011";
					an0<='0';
				elsif(s(0)='1') then
					an3<='1';
					led<="10011111";
					an0<='0';
				end if;
			end if;
	end if;
end process;
end Behavioral;
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top