实验cpu算术逻辑单元

上传人:第*** 文档编号:32759194 上传时间:2018-02-12 格式:DOC 页数:5 大小:102.50KB
返回 下载 相关 举报
实验cpu算术逻辑单元_第1页
第1页 / 共5页
实验cpu算术逻辑单元_第2页
第2页 / 共5页
实验cpu算术逻辑单元_第3页
第3页 / 共5页
实验cpu算术逻辑单元_第4页
第4页 / 共5页
实验cpu算术逻辑单元_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《实验cpu算术逻辑单元》由会员分享,可在线阅读,更多相关《实验cpu算术逻辑单元(5页珍藏版)》请在金锄头文库上搜索。

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

2、下表所示。运算操作码 OP2.0 运算 对标志位 Z 和 C 的影响000 ResultA+B 影响标志位 Z 和 C001 ResultA+1 影响标志位 Z 和 C010 ResultA-B 影响标志位 Z 和 C011 ResultA-1 影响标志位 Z 和 C100 ResultA and B 影响标志位 Z101 ResultA or B 影响标志位 Z110 Resultnot B 影响标志位 Z111 Result B 不影响标志位 Z 和 C(2)设立两个标志寄存器 Z 和 C。当复位信号 reset 为低电平时,将这两个标志寄存器清零。当运算结束后,在时钟 clk 的上升沿改

3、变标志寄存器 Z 和 C 的值。运算结果改变标志寄存器 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)算术逻辑单元

4、用一个设计实体完成。2.顶层设计实体的引脚要求(1)clk 对应试验台上的时钟(单脉冲) 。(2)reset 对应实验台上的 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

5、 ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity ALU isport(reset,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 be

6、hav of alu iscomponent reg isport(clr: in std_logic;D: in std_logic_vector(15 downto 0);clock: in std_logic;write: in std_logic;sel: in std_logic;Q: out std_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

7、downto 0);beginA_reg: reg port map(clr = reset,D = Dinput,clock = clk,write = 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 result_t result_t result_t result_t result_t resu

8、lt_t result_t = (0 end case;end process;result = result_t(15 downto 0);z_tmp = (not 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 resul

9、t_t(5) and (not result_t(4) and(not result_t(3) and (not result_t(2) and(not result_t(1) and (not result_t(0);c_proc: Process(reset,clk,result_t,OP)beginif reset = 0 thenC = 0;elsif clkevent and clk = 1 thenif OP(2) = 0 thenC = result_t(16);end if;end if;end process;z_proc: process(reset,clk,z_tmp,O

10、P)beginif reset = 0 thenZ = 0;elsif clkevent and clk = 1 thenif 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 组数据进行 8 种运算,A 为 0xAA

11、AA,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 组数据运算结果,连同标志位的状态填写下表:算术逻辑单元实验标志 C 标志 Z运算数据 运算类型操作码OP运算结果 rezult 运算前 运算后 运算前 运算后Result-A+B 000 oxFFFF 0 0 0 0Result-A+1 001 oxAAAB 0 0 0 0Result-A-B 010 o

12、x5555 0 0 0 0Result-A-1 011 oxAAA9 0 0 0 0Result-AandB 100 ox0000 0 0 0 1Result-AorB 101 oxFFFF 0 0 1 0第 1 组数据A=0xAAAAB=0x5555Result-notB 110 oxAAAA 0 0 0 0Result-B 111 ox5555 0 0 0 0Result-A+B 000 oxFFFF 0 0 0 0Result-A+1 001 ox0000 0 1 0 1Result-A-B 010 oxFFFF 1 0 1 0Result-A-1 011 oxFFFE 0 0 0 0R

13、esult-AandB 100 ox0000 0 0 0 1Result-AorB 101 oxFFFF 0 0 1 0Result-notB 110 oxFFFF 0 0 0 0第 2 组数据A=0x FFFFB=0x0000Result-B 111 ox0000 0 0 0 0Result-A+B 000 oxFFFF 0 0 0 0Result-A+1 001 ox0001 0 0 0 0Result-A-B 010 ox0001 0 1 0 0Result-A-1 011 oxFFFF 1 1 0 0Result-AandB 100 ox0000 1 1 0 1Result-AorB

14、101 oxFFFF 1 1 1 0Result-notB 110 ox0000 1 1 0 1第 3 组数据A=0x0000B=0x FFFFResult-B 111 oxFFFF 1 1 1 1Result-A+B 000 ox21B3 0 1 0 0Result-A+1 001 ox8951 1 0 0 0Result-A-B 010 oxF0ED 0 1 0 0Result-A-1 011 ox894F 1 0 0 0Result-AandB 100 ox8840 0 0 0 0Result-AorB 101 ox9973 0 0 0 0Result-notB 110 ox679C 0 0 0 0第 4 组数据A=0x 8950B=0x9863Result-B 111 ox9863 0 0 0 0

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 工程造价

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号