现代计算机组成原理——除法器设计

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

数字系统组成原理和设计技术
实验:除法器
学号 1115108052
姓名詹炳鑫
班级电子2班
华侨大学电子工程系
一.程序
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE IEEE.std_logic_unsigned.ALL;
ENTITY devide IS
PORT
(
reset, clock, start : IN STD_LOGIC;
x : IN STD_LOGIC_VECTOR( 4 DOWNTO 0 );
y : IN STD_LOGIC_VECTOR( 8 DOWNTO 0 ); done, overflow : OUT STD_LOGIC;
q, r : OUT STD_LOGIC_VECTOR( 4 DOWNTO 0 ) );
END devide;
ARCHITECTURE behav OF devide IS
SIGNAL rx : STD_LOGIC_VECTOR( 5 DOWNTO 0 ); SIGNAL ry : STD_LOGIC_VECTOR( 5 DOWNTO 0 ); SIGNAL rq : STD_LOGIC_VECTOR( 4 DOWNTO 0 );
SIGNAL rmd : STD_LOGIC_VECTOR( 5 DOWNTO 0 ); SIGNAL flag_subadd : bit;
SIGNAL state : integer RANGE 0 TO 6;
BEGIN
PROCESS ( reset, clock )
V ARIABLE sq : STD_LOGIC;
BEGIN
IF reset = '0' THEN
rx <= ( OTHERS => '0' );
ry <= ( OTHERS => '0' );
rq <= ( OTHERS => '0' );
state <= 0;
ELSIF clock'event AND clock = '1' THEN
CASE STATE IS
WHEN 0 =>
rx( 5 DOWNTO 0 ) <= x(4) & x( 4 DOWNTO 0 ) ;
ry( 5 DOWNTO 0 ) <= y(8) & y( 8 DOWNTO 4 ) ;
rq( 4 DOWNTO 0 ) <= y( 3 DOWNTO 0 ) & '0';
flag_subadd <= '1';
done <= '0';
overflow <= '0';
IF start = '1' THEN
state <= 1;
END IF;
WHEN 1 =>
IF rmd(5) = '0' THEN
overflow <= '1';
state <= 0;
done <= '1';
ELSE
state <= state + 1;
sq := '0';
ry( 5 DOWNTO 0 ) <= rmd( 4 DOWNTO 0 ) & rq(4); rq( 4 DOWNTO 0 ) <= rq( 3 DOWNTO 0 ) & sq; flag_subadd <= '0';
END IF;
WHEN 5 =>
IF rmd(5) = '0' THEN
sq := '1';
flag_subadd <= '1';
ELSE
sq := '0';
flag_subadd <= '0';
END IF;
ry( 5 DOWNTO 0 ) <= rmd( 4 DOWNTO 0 ) & rq(4); ry( 5 DOWNTO 0 ) <= rmd( 5 DOWNTO 0 );
rq( 4 DOWNTO 0 ) <= rq( 3 DOWNTO 0 ) & sq; state <= state + 1;
WHEN 6 =>
IF rq(0) = '0' THEN
ry <= rmd( 5 DOWNTO 0 );
r <= rmd( 4 DOWNTO 0 );
ELSE
r <= ry( 4 DOWNTO 0);
END IF;
state <= 0;
q <= rq;
done <= '1' ;
WHEN OTHERS =>
IF rmd(5) = '0' THEN
sq := '1';
flag_subadd <= '1';
ELSE
sq := '0';
flag_subadd <= '0';
END IF;
ry( 5 DOWNTO 0 ) <= rmd( 4 DOWNTO 0 ) & rq(4);
rq( 4 DOWNTO 0 ) <= rq( 3 DOWNTO 0 ) & sq;
state <= state + 1;
END CASE;
END IF;
END PROCESS;
rmd <= ry + rx WHEN flag_subadd = '0' ELSE
ry + NOT rx + 1;
END behav;
-- Copyright (C) 1991-2011 Altera Corporation
-- Your use of Altera Corporation's design tools, logic functions
-- and other software and tools, and its AMPP partner logic
-- functions, and any output files from any of the foregoing
-- (including device programming or simulation files), and any
-- associated documentation or information are expressly subject
-- to the terms and conditions of the Altera Program License
-- Subscription Agreement, Altera MegaCore Function License
-- Agreement, or other applicable license agreement, including,
-- without limitation, that your use is for the sole purpose of
-- programming logic devices manufactured by Altera and sold by
-- Altera or its authorized distributors. Please refer to the
-- applicable agreement for further details.
-- *************************************************************************** -- This file contains a Vhdl test bench template that is freely editable to
-- suit user's needs .Comments are provided in each section to help the user
-- fill out necessary details.
-- *************************************************************************** -- Generated on "03/04/2014 15:45:59"
-- Vhdl Test Bench template for design : devide
--
-- Simulation tool : ModelSim-Altera (VHDL)
--
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY devide_tb IS
END devide_tb;
ARCHITECTURE devide_arch OF devide_tb IS
-- constants
-- signals
SIGNAL clock : STD_LOGIC:='0';
SIGNAL done : STD_LOGIC:='0';
SIGNAL overflow : STD_LOGIC:='0';
SIGNAL q : STD_LOGIC_VECTOR(4 DOWNTO 0):="00000"; SIGNAL r : STD_LOGIC_VECTOR(4 DOWNTO 0):="00000"; SIGNAL reset : STD_LOGIC:='0';
SIGNAL start : STD_LOGIC:='0';
SIGNAL x : STD_LOGIC_VECTOR(4 DOWNTO 0); SIGNAL y : STD_LOGIC_VECTOR(8 DOWNTO 0); CONSTANT CLK_P : TIME :=10 ns;
COMPONENT devide
PORT (
clock : IN STD_LOGIC;
done : OUT STD_LOGIC;
overflow : OUT STD_LOGIC;
q : OUT STD_LOGIC_VECTOR(4 DOWNTO 0);
r : OUT STD_LOGIC_VECTOR(4 DOWNTO 0);
reset : IN STD_LOGIC;
start : IN STD_LOGIC;
x : IN STD_LOGIC_VECTOR(4 DOWNTO 0);
y : IN STD_LOGIC_VECTOR(8 DOWNTO 0)
);
END COMPONENT;
BEGIN
i1 : devide
PORT MAP (
-- list connections between master ports and signals
clock => clock,
done => done,
overflow => overflow,
q => q,
r => r,
reset => reset,
start => start,
x => x,
y => y
);
PROCESS
BEGIN
CLOCK<='0';
W AIT FOR CLK_P;
CLOCK<='1';
W AIT FOR CLK_P;
END PROCESS;
reset <= '0','1' AFTER 10 ns;
start <='0','1' AFTER 25 ns;
x<="00000","01011"AFTER 60 ns,"00010"AFTER 120 ns;
y<="000000000","010010000"AFTER 60 ns,"000001101"AFTER 120 ns; END devide_arch;
二.仿真图。

相关文档
最新文档