8位补码器设计
- 格式:docx
- 大小:36.65 KB
- 文档页数:3
八
位
补
码
器
设
计
实
验
报
告
一、功能描述
将八位二进制数除最高位(符号位)取反得到反码,然后反码加一得到补码;
正数的原码、反码、补码都相同。
例如: 原码 反码 补码
00011010 00011010 00011010 (正数)
10011010 11100101 11100110 (负数)
二、元件及其VHDL代码
补码器代码
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity complement is
port (a: in std_logic_vector (7 downto 0); --定义输入数据
a(7..0)
b: out std_logic_vector (7 downto 0)); --定义输出数据b(7..0)
end complement;
architecture behave of complement is
begin
process (a)
begin
if (a (7) ='0' ) then b<=a; --当输入数据为正数,实现正数补码运
算
else b<='1'& (not a (6 downto 0) + '1' ); --当输入数据为负数,实现负数
补码运算
end if;
end process;
end behave;