aboutsummaryrefslogtreecommitdiff
path: root/src/abs8b.vhd
blob: 77b7a25e05ac2c528ebd5f204523cd6f6fa0ab6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
library ieee;
use ieee.std_logic_1164.all;

entity abs8b is
	port(
		A: in std_logic_vector(8 downto 0);
		X: out std_logic_vector(8 downto 0));
end abs8b;

architecture Behavioral of abs8b is
	component twoc
		port (
			A: in std_logic_vector(7 downto 0);
			Cin: in std_logic;
			X: out std_logic_vector(7 downto 0);
      Cout: out std_logic);
	end component;
	signal ntop: std_logic_vector(8 downto 0);
begin
	-- calculate two's complement for A (A * -1)
	inv: component twoc
		port map(
			A => A(7 downto 0),
			Cin => A(8),
			X => ntop(7 downto 0),
			Cout => ntop(8));
	-- output -A if A < 0 else A
	X <= ntop when A(8) = '1' else A;
end Behavioral;