EDA Playground lets you type in and run HDL code (using a selection of free and commercial simulators and synthesizers).
It's great for learning HDLs, it's great for testing out unfamiliar things and it's great for sharing code.
You can start typing straight away. But to run your code, you'll need to sign or log in. Logging in with a Google account gives you access to all non-commercial simulators and some commercial simulators:
To run commercial simulators, you need to register and log in with a username and password. Registration is free, and only pre-approved email's will have access to the commercial simulators.
202
-- Testbench
library IEEE;
use IEEE.std_logic_1164.all;
entity testbench is
end testbench;
architecture tb of testbench is
signal x, y, z, sHA, cHA, sFA, cFA: std_logic;
signal A, B, S: std_logic_vector (3 downto 0);
signal C0: std_logic;
signal C4: std_logic;
begin
DUT_HA: entity work.half_adder port map( x, y, sHA, cHA);
DUT_FA: entity work.full_adder port map( x, y, z, sFA, cFA);
DUT_Add4: entity work.adder_4bit(adder4_struct) port map( A, B, C0, S, C4);
process begin
x <= '0';
y <= '0';
z <= '0';
A <= "0000";
B <= "0000";
C0 <= '0';
wait for 10 ns;
report "HA: INPUT = (0,0) SUM = " & to_string(sHA) & " CARRY = " & to_string(cHA);
report "FA: INPUT = (0,0,0) SUM = " & to_string(sFA) & " CARRY = " & to_string(cFA);
report "Add4: INPUT = (0000,0000,0) SUM = " & to_string(S) & " CARRY = " & to_string(C4);
x <= '0';
y <= '1';
z <= '0';
A <= "0101";
B <= "1010";
C0 <= '0';
wait for 10 ns;
report "HA: INPUT = (0,1) SUM = " & to_string(sHA) & " CARRY = " & to_string(cHA);
report "FA: INPUT = (0,1,0) SUM = " & to_string(sFA) & " CARRY = " & to_string(cFA);
report "Add4: INPUT = (0101,1010,0) SUM = " & to_string(S) & " CARRY = " & to_string(C4);
x <= '1';
y <= '1';
z <= '0';
A <= "1100";
B <= "1001";
C0 <= '0';
wait for 10 ns;
report "HA: INPUT = (1,1) SUM = " & to_string(sHA) & " CARRY = " & to_string(cHA);
report "FA: INPUT = (1,1,0) SUM = " & to_string(sFA) & " CARRY = " & to_string(cFA);
report "Add4: INPUT = (1100,1001,0) SUM = " & to_string(S) & " CARRY = " & to_string(C4);
x <= '1';
y <= '1';
z <= '1';
A <= "1111";
B <= "0001";
C0 <= '0';
wait for 10 ns;
report "HA: INPUT = (1,1) SUM = " & to_string(sHA) & " CARRY = " & to_string(cHA);
report "FA: INPUT = (1,1,1) SUM = " & to_string(sFA) & " CARRY = " & to_string(cFA);
report "Add4: INPUT = (1111,0001,0) SUM = " & to_string(S) & " CARRY = " & to_string(C4);
wait;
end process;
end tb;
-- Alternative testbench
library IEEE;
use IEEE.std_logic_1164.all;
entity testbench2 is
end testbench2;
architecture tb of testbench2 is
signal x, y, z, sHA, cHA, sFA, cFA: std_logic;
signal A, B, S: std_logic_vector (3 downto 0);
signal C0, C4: std_logic;
begin
DUT_HA: entity work.half_adder port map( x, y, sHA, cHA);
DUT_FA: entity work.full_adder port map( x, y, z, sFA, cFA);
DUT_Add4: entity work.adder_4bit(adder4_struct) port map( A, B, C0, S, C4);
process begin
x <= '0';
y <= '0';
z <= '0';
A <= "0000";
B <= "0000";
C0 <= '0';
wait for 10 ns;
assert (sHA='0' and cHA='0') report "ERROR Half adder on (0,0)";
assert (sFA='0' and cFA='0') report "ERROR Full adder on (0,0,0)";
assert (S="0000" and C4='0') report "ERROR Adder 4 bit on (0000,0000,0)";
x <= '0';
y <= '1';
z <= '0';
A <= "0101";
B <= "1010";
C0 <= '0';
wait for 10 ns;
assert (sHA='1' and cHA='0') report "ERROR Half adder on (0,1)";
assert (sFA='1' and cFA='0') report "ERROR Full adder on (0,1,0)";
assert (S="1111" and C4='0') report "ERROR Adder 4 bit on (0101,1010,0)";
x <= '1';
y <= '1';
z <= '0';
A <= "1100";
B <= "1001";
C0 <= '0';
wait for 10 ns;
assert (sHA='0' and cHA='1') report "ERROR Half adder on (1,1)";
assert (sFA='0' and cFA='1') report "ERROR Full adder on (1,1,0)";
assert (S="0101" and C4='1') report "ERROR Adder 4 bit on (1100,1001,0)";
x <= '1';
y <= '1';
z <= '1';
A <= "1111";
B <= "0001";
C0 <= '0';
wait for 10 ns;
assert (sHA='0' and cHA='1') report "ERROR Half adder on (1,1)";
assert (sFA='1' and cFA='1') report "ERROR Full adder on (1,1,1)";
assert (S="0000" and C4='1') report "ERROR Adder 4 bit on (1111,0001,0)";
wait;
end process;
end tb;
xxxxxxxxxx
-- 4-bit ripple carry adder with gerarchic dataflow-structural architecture and behavioral architecture
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity adder_4bit is
port ( A, B: in std_logic_vector(3 downto 0);
C0: in std_logic;
S: out std_logic_vector(3 downto 0);
C4: out std_logic);
end adder_4bit;
architecture adder4_struct of adder_4bit is
signal C: std_logic_vector(4 downto 0);
begin
bit0: entity work.full_adder port map (A(0), B(0), C(0), S(0), C(1));
bit1: entity work.full_adder port map (A(1), B(1), C(1), S(1), C(2));
bit2: entity work.full_adder port map (A(2), B(2), C(2), S(2), C(3));
bit3: entity work.full_adder port map (A(3), B(3), C(3), S(3), C(4));
C(0) <= C0;
C4 <= C(4);
end adder4_struct;
architecture adder4_beh of adder_4bit is
signal
sum: std_logic_vector(4 downto 0);
begin
sum <= ('0' & A) + ('0' & B) + ("0000" & C0);
C4 <= sum(4);
S <= sum(3 downto 0);
end adder4_beh;
xxxxxxxxxx
-- full adder with structural-dataflow architecture
library IEEE;
use IEEE.std_logic_1164.all;
entity full_adder is
port ( x, y, z: in std_logic;
sum, carryout: out std_logic);
end full_adder;
architecture fa_struct_dataflow of full_adder is
signal s1, c1, c2: std_logic;
begin
HA1: entity work.half_adder port map(x, y, s1, c1);
HA2: entity work.half_adder port map(s1, z, sum, c2);
carryout <= c2 or c1;
end fa_struct_dataflow;
xxxxxxxxxx
-- half adder with dataflow architecture
library IEEE;
use IEEE.std_logic_1164.all;
entity half_adder is
port ( x, y: in std_logic;
s, c: out std_logic);
end half_adder;
architecture ha_dataflow of half_adder is
begin
s <= x xor y;
c <= x and y;
end ha_dataflow;
Your account is not validated. If you wish to use commercial simulators, you need a validated account.
If you have already registered (or have recently changed your email address), but have not clicked on the link in the email we sent you, please do so. If you cannot find the email, please check your spam/junk folder. Or click here to resend the email.
If you have not already registered for a full account, you can do so by clicking below. You will then need to provide us with some identification information. You may wish to save your code first.
Creating, deleting, and renaming files is not supported during Collaboration. To encourage development of these features for Collaboration, tweet to @EDAPlayground
This playground may have been modified. Please save or copy before starting collaboration.
Your exercise has been submitted.