实验CPU算术逻辑单元(共5页)_第1页
实验CPU算术逻辑单元(共5页)_第2页
实验CPU算术逻辑单元(共5页)_第3页
实验CPU算术逻辑单元(共5页)_第4页
实验CPU算术逻辑单元(共5页)_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精选优质文档-倾情为你奉上实验CPU 算术逻辑单元姓名: 闫盼蛟 学号: 一、实验目的(1)掌握运算器的工作原理。(2)验证运算器的功能。二、实验原理算术逻辑单元的主要功能是对二进制数据进行定点算术运算、逻辑运算和各种移位操作。算术运算包括定点加减乘除运算;逻辑运算主要有逻辑与、逻辑或、逻辑异或和逻辑非操作。ALU通常有两个数据输入端A和B,一个数据输出端Y以及标志位等。三、实验要求1、实验设计目标设计一个16位算术逻辑单元,满足以下要求。(1)16位算术逻辑单元能够进行下列运算:加法、减法、加1、减1、与、或、非和传送。用3位运算操作码OP2.0进行运算,控制方式如下表所示。运算操作码OP2

2、.0运算对标志位Z和C的影响000ResultßA+B影响标志位Z和C001ResultßA+1影响标志位Z和C010ResultßA-B影响标志位Z和C011ResultßA-1影响标志位Z和C100ResultßA and B影响标志位Z101ResultßA or B影响标志位Z110Resultßnot B影响标志位Z111Resultß B不影响标志位Z和C(2)设立两个标志寄存器Z和C。当复位信号reset为低电平时,将这两个标志寄存器清零。当运算结束后,在时钟clk的上升沿改变标志寄存器Z和C的值。运

3、算结果改变标志寄存器C、Z的情况如下:加法、减法、加1、减1运算改变Z、C;与、或、非运算改变Z,C保不变;传送操作保持Z、C不变。因此在运算结束Z、C需要两个D触发器保存。(3)为了保存操作数A和B,设计两个16位寄存器A和B。当寄存器选择信号sel=0时,如果允许写信号write=1.,则在诗中clk的上升沿将数据输入dinput送入A寄存器;当寄存器选择信号sel=1时,如果允许写信号write=1.,则在诗中clk的上升沿将数据输入dinput送入B寄存器。(4)算术逻辑单元用一个设计实体完成。2.顶层设计实体的引脚要求(1)clk对应试验台上的时钟(单脉冲)。(2)reset对应实验

4、台上的CPU复位信号CPU-RST。(3)数据输入dinput对应试验台开关SD15SD0。(4)允许写信号write对应试验台开关SA5.(5)OP2.0对应试验台开关SA2SA0.(6)寄存器选择信号sel对应试验台开关SA4.(7)16为运算结果result对应实验台上的指示灯A15A0.(8)Z、C标志位对应试验台上的Z、C指示灯。四、实验代码library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity ALU isport( re

5、set,clk :in std_logic; OP: in std_logic_vector(2 downto 0); sel: in std_logic; write:in std_logic; C,Z:out std_logic; Dinput: in std_logic_vector(15 downto 0); result: out std_logic_vector(15 downto 0);end ALU;architecture behav of alu iscomponent reg isport(clr: instd_logic;D: instd_logic_vector(15

6、 downto 0);clock:instd_logic;write:instd_logic; sel:instd_logic;Q: outstd_logic_vector(15 downto 0);end component;signal z_tmp :std_logic;signal A,B :std_logic_vector(15 downto 0);signal result_t: std_logic_vector(16 downto 0);beginA_reg: reg port map(clr=> reset, D=> Dinput, clock=> clk, w

7、rite=> write, sel=> (not sel), Q=> A);B_reg: reg port map(clr=> reset, D=> Dinput, clock=> clk, write=> write, sel=> sel, Q=> B);alu_proc:process(OP,A,B)begincase OP iswhen "000" =>result_t <= ('0' & A) + ('0' & B);when "001&quo

8、t; =>result_t <= ('0' & A) + '1' when "010" =>result_t <= ('0' & A) - ('0' & B);when "011" =>result_t <= ('0' & A) - '1'when "100" =>result_t <= ('0' & A) and ('0'

9、; & B);when "101" =>result_t <= ('0' & A) or ('0' & B);when "110" =>result_t <= not ('0' & B);when "111" =>result_t <= ('0' & B);end case;end process;result <= result_t(15 downto 0);z_tmp <= (no

10、t result_t(15) and (not result_t(14) and(not result_t(13) and (not result_t(12) and(not result_t(11) and (not result_t(10) and(not result_t(9) and (not result_t(8) and(not result_t(7) and (not result_t(6) and(not result_t(5) and (not result_t(4) and(not result_t(3) and (not result_t(2) and(not resul

11、t_t(1) and (not result_t(0);c_proc: Process(reset,clk,result_t,OP)begin if reset = '0' thenC <= '0'elsif clk'event and clk = '1' then if OP(2) = '0' thenC <= result_t(16);end if;end if;end process;z_proc: process(reset,clk,z_tmp,OP)begin if reset = '0

12、9; thenZ <= '0'elsif clk'event and clk = '1' then if OP /= "111" thenZ <= z_tmp; end if;end if;end process;end behav;五、 实验步骤(1) 实验台设置成FPGA-CPU独立调试模式。REGSEL=0、CLKSEL=1、FDSEL=0。使用实验台上的单脉冲,即STEP_CLK短路子短接,短路子RUN_CLK断开。(2) 将设计在Quartus下输入,编译后下载到TEC-CA上的FPGA中。(3) 对第1组数据进

13、行8种运算,A为0xAAAA,B为0x5555(4) 对第2组数据进行8种运算,A为0xFFFF,B为0x0000(5) 对第3组数据进行8种运算,A为0x0000,B为0xFFFF(6) 对第4组数据进行8种运算,A为0x8950,B为0x9863(7)根据4组数据运算结果,连同标志位的状态填写下表:算术逻辑单元实验运算数据运算类型操作码OP运算结果rezult标志C标志Z运算前运算后运算前运算后第1组数据A=0xAAAAB=0x5555Result<-A+B000oxFFFF0000Result<-A+1001oxAAAB0000Result<-A-B010ox55550

14、000Result<-A-1011oxAAA90000Result<-AandB100ox00000001Result<-AorB101oxFFFF0010Result<-notB110oxAAAA0000Result<-B111ox55550000第2组数据A=0x FFFFB=0x0000Result<-A+B000oxFFFF0000Result<-A+1001ox00000101Result<-A-B010oxFFFF1010Result<-A-1011oxFFFE0000Result<-AandB100ox00000001R

15、esult<-AorB101oxFFFF0010Result<-notB110oxFFFF0000Result<-B111ox00000000第3组数据A=0x0000B=0x FFFFResult<-A+B000oxFFFF0000Result<-A+1001ox00010000Result<-A-B010ox00010100Result<-A-1011oxFFFF1100Result<-AandB100ox00001101Result<-AorB101oxFFFF1110Result<-notB110ox00001101Result<-B111oxFFFF1111第4组数据A=0x 8950B=0x9863Result<-A+B000ox21B30100Result<-A+1

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论