组成专题实验报告三.doc_第1页
组成专题实验报告三.doc_第2页
组成专题实验报告三.doc_第3页
组成专题实验报告三.doc_第4页
组成专题实验报告三.doc_第5页
已阅读5页,还剩10页未读, 继续免费阅读

下载本文档

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

文档简介

计算机组成原理实验报告学 院:_ 电信学院_ _专 业:_计算机科学与技术_学 号:_2110505108_班 级:_计算机15_姓 名:_张玲玲_时 间:_ 2013年1月3日 _1、 实验目的 (1)掌握基本的算术运算和逻辑运算的运算规则和实现方法; (2)掌握基本运算器的信息传送通路; (3)掌握运算器的工作原理,设计并实现具有定点、浮点运算功能的模块。2、 实验内容 设计一个基本的算术逻辑运算模块,包括: 算术运算模块,主要包括定点运算:加减乘除运算及浮点运算(浮点运算依照IEEE754标准); 逻辑运算模块,主要包括与、或、非、异或和各种移位运算等;注: 运算器模块框图:运算器(ALU)通常有两个数据输入端(opr1和opr2),一个数据输出端(result),运算模式控制信号(code)和标志位( cin , flag)等。下图为运算器的逻辑框图:图2-1 运算器 运算器包含加法器(含用先行进位的构成的加法器,如4位一组构成16位)、减法器、乘法器、与门、或门、非门、异或门和移位器等及浮点运算模块;运算器模块中也可以加入寄存器组。 本实验中设计的运算器操作数可以分别为8/16/32位字长(32位字长运算可以只进行仿真分析) 定点乘法: 已知X=-0.1010,Y=0.0011,求 X*Y=? 利用原码乘法的方法,设计VHDL程序,完成乘法的运算并描述其算法及电路图;3、 实验原理 在计算机内实现原码乘法时,要做以下方面的改进工作。由于在运算器内通常只能完成对两数的求乘操作,则可以每求得一个相加数,就同时完成与上一次部分积相加的操作。其次是在手工计算时,各加数逐位左移,最终相加数为相乘二位数的两倍,而在计算机中,加法器的位数一般与乘法器的位数相同,而不是寄存器位数的两倍。这实际上也可以用另外的办法解决。手工计算时,各加数是逐位左移,但很容易发现,在求本次部分积之和时,前一部分积的最低一位是不再与任何数值相加的。这就意味着,若采用每求得一次部分积之后使其右移一位,则可以只用N位的加法器就能实现两个N位的数相乘j!显而易见,若前一次部分积已经右移一位,就可以用其高位部分加上被乘数或加零的方法求得本次部分积。最后一点是,手工计算时,乘数每一位的值是0还是1都直接看得见,而在计算机内,采用放乘数的寄存器的每一位直接决定本次相加数是被乘数还是零是很不方便的,若均采用该寄存器的最低一位来执行这种判别就简便了。为此,只要每求一次部分积就使放乘数的寄存器执行一次右移操作即可以了。若移位时,使其最高数值位接收加法器最低位的输出,则完成乘法运算后,该寄存器中保存的是乘积的低位部分。计算机内求乘积的符号,很容易用求相乘二数符号的半加和(异或值)实现。 原码一位乘法的规则: 判断参加运算的操作数是否合格; 令乘数的最低位为判断位,若为“1”,加被乘数,若为“0”,不加被乘数(加0); 累加后的部分积以及乘数右移一位 重复n次和 ; 符号位单独处理,同号为正,异号为负。 通常,乘法运算需要3个寄存器。被乘数存放在B寄存器中;乘数存放在C寄存器中;A寄存器用来存放部分积与最后乘积的高位部分,它的初值为0。运算结束后寄存器C中不再保留乘数,改为存放乘积的低位部分。 例:已知:X=0.1101,Y=-0.1011,求:XY。 |X|=00.1101B,|Y|=.1011C,0A原码一位乘法示例A C 说明 00.0000 1011 +|X| 00.1101 C4=1,+|X| 00.1101 00.0110 1101 部分积右移一位 +|X| 00.1101 C4=1,+|X| 01.0011 00.1001 1110 部分积右移一位 +0 00.0000 C4=0,+0 00.1001 00.0100 1111 部分积右移一位 +|X| 00.1101 C4=1,+|X| 01.0001 00.1000 1111 部分积右移一位PS=XSYS=01=1X*Y=-0.10001111 原码一位乘法流程图 这里为了简便,我编写了无符号数原码的乘法运算,不考虑符号位。即实现了两个四位数相乘,结果放入一个八位数中。4、 实验源代码library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity ALU isport( set:in std_logic;- 运算控制信号 code:in std_logic_vector(3 downto 0);- 操作码 cin:in std_logic;- 低位向高位的进位或者借位信号 opr1:in std_logic_vector(7 downto 0);- 第一操作数 opr2:in std_logic_vector(7 downto 0);- 第二操作数 result:out std_logic_vector(7 downto 0);- 运算结果 flag:out std_logic-运算结果标志位flag );end ALU;architecture behav of ALU issignal a:std_logic_vector(7 downto 0);signal b:std_logic_vector(7 downto 0);signal c:std_logic_vector(7 downto 0);shared variable y,x:std_logic_vector(7 downto 0);beginprocess(b,c,temp1,set,code,cin,opr1,opr2)variable i: integer;begina=00000000;b=00000000;C=00000000;x:=00000000;temp:=00000000;temp1=00000000;result=00000000;flag-+ a(0)=opr1(0) and opr2(0);b(0)=opr1(0) xor opr2(0);-产生本地进位和传递条件 a(1)=opr1(1) and opr2(1);b(1)=opr1(1) xor opr2(1); a(2)=opr1(2) and opr2(2);b(2)=opr1(2) xor opr2(2); a(3)=opr1(3) and opr2(3);b(3)=opr1(3) xor opr2(3); a(4)=opr1(4) and opr2(4);b(4)=opr1(4) xor opr2(4); a(5)=opr1(5) and opr2(5);b(5)=opr1(5) xor opr2(5); a(6)=opr1(6) and opr2(6);b(6)=opr1(6) xor opr2(6); a(7)=opr1(7) and opr2(7);b(7)=opr1(7) xor opr2(7);-每四位一组,组内先行进位加法,组间串行进位加法. result(0)=b(0) xor cin; c(0)=a(0) or (b(0) and cin); result(1)=b(1) xor c(0); c(1)=a(1) or (b(1) and a(0) or (b(1)and b(0)and cin); result(2)=b(2) xor c(1); c(2)=a(2) or (b(2) and a(1) or (b(2)and b(1)and a(0) or (b(2)and b(1)and b(0)and cin); result(3)=b(3) xor c(2); c(3)=a(3) or (b(3) and a(2) or (b(3)and b(2)and a(1) or (b(3)and b(2)and b(1)and a(0) or (b(3)and b(2)and b(1)and b(0)and cin); result(4)=b(4) xor c(3); c(4)=a(4) or (b(4) and c(3); result(5)=b(5) xor c(4); c(5)=a(5) or (b(5) and a(4) or (b(5)and b(4)and c(3); result(6)=b(6) xor c(5); c(6)=a(6) or (b(6) and a(5) or (b(6)and b(5)and a(4) or (b(6)and b(5)and b(4)and c(3); result(7)=b(7) xor c(6); flag-+1 result(0)=not opr1(0); result(1)=opr1(1) xor opr1(0); result(2)=opr1(2) xor (opr1(1) and opr1(0); result(3)=opr1(3) xor (opr1(2) and opr1(1) and opr1(0); result(4)=opr1(4) xor (opr1(3) and opr1(2) and opr1(1) and opr1(0); result(5)=opr1(5) xor (opr1(4) and opr1(3) and opr1(2) and opr1(1) and opr1(0); result(6)=opr1(6) xor (opr1(5) and opr1(4) and opr1(3) and opr1(2) and opr1(1) and opr1(0); result(7)=opr1(7) xor (opr1(6) and opr1(5) and opr1(4) and opr1(3) and opr1(2) and opr1(1) and opr1(0); flag- a(0)=opr1(0) and (not opr2(0);b(0)=opr1(0) xor (not opr2(0); a(1)=opr1(1) and (not opr2(1);b(1)=opr1(1) xor (not opr2(1); a(2)=opr1(2) and (not opr2(2);b(2)=opr1(2) xor (not opr2(2); a(3)=opr1(3) and (not opr2(3);b(3)=opr1(3) xor (not opr2(3); a(4)=opr1(4) and (not opr2(4);b(4)=opr1(4) xor (not opr2(4); a(5)=opr1(5) and (not opr2(5);b(5)=opr1(5) xor (not opr2(5); a(6)=opr1(6) and (not opr2(6);b(6)=opr1(6) xor (not opr2(6); a(7)=opr1(7) and (not opr2(7);b(7)=opr1(7) xor (not opr2(7); result(0)=b(0) xor (not cin); c(0)=a(0) or (b(0) and (not cin); result(1)=b(1) xor c(0); c(1)=a(1) or (b(1) and a(0) or (b(1)and b(0)and (not cin); result(2)=b(2) xor c(1); c(2)=a(2) or (b(2) and a(1) or (b(2)and b(1)and a(0) or (b(2)and b(1)and b(0)and (not cin); result(3)=b(3) xor c(2); c(3)=a(3) or (b(3) and a(2) or (b(3)and b(2)and a(1) or (b(3)and b(2)and b(1)and a(0) or (b(3)and b(2)and b(1)and b(0)and (not cin); result(4)=b(4) xor c(3); c(4)=a(4) or (b(4) and c(3); result(5)=b(5) xor c(4); c(5)=a(5) or (b(5) and a(4) or (b(5)and b(4)and c(3); result(6)=b(6) xor c(5); c(6)=a(6) or (b(6) and a(5) or (b(6)and b(5)and a(4) or (b(6)and b(5)and b(4)and c(3); result(7)=b(7) xor c(6); c(7)=a(7) or (b(7) and a(6) or (b(7)and b(6)and a(5) or (b(7)and b(6)and b(5)and a(4) or (b(7)and b(6)and b(5)and b(4)and c(3); flag-1 result(0)=not opr1(0); result(1)=opr1(1)xor(not opr1(0); result(2)=opr1(2)xor(not (opr1(1)or opr1(0); result(3)=opr1(3)xor(not (opr1(2)or opr1(1)or opr1(0); result(4)=opr1(4)xor(not (opr1(3)or opr1(2)or opr1(1)or opr1(0); result(5)=opr1(5)xor(not (opr1(4)or opr1(3)or opr1(2)or opr1(1)or opr1(0); result(6)=opr1(6)xor(not (opr1(5)or opr1(4)or opr1(3)or opr1(2)or opr1(1)or opr1(0); result(7)=opr1(7)xor(not (opr1(6)or opr1(5)or opr1(4)or opr1(3)or opr1(2)or opr1(1)or opr1(0); flag-*操作数为4位,结果为8位,无符号数原码乘法 -c=opr1(3 downto 0)*opr2(3 downto 0); x(0):=0; x(1):=0; x(2):=0; x(3):=0; x(4):=opr1(0); x(5):=opr1(1); x(6):=opr1(2); x(7):=opr1(3); y(0):=opr2(0); y(1):=opr2(1); y(2):=opr2(2); y(3):=opr2(3); y(4):=0; y(5):=0; y(6):=0; y(7):=0; i:=0;while (i4) loopif(y(0)=1) then y:=x+y;else y:=y;end if;y(0):=y(1); y(1):=y(2); y(2):=y(3); y(3):=y(4); y(4):=y(5); y(5):=y(6); y(6):=y(7); y(7):=0;-y(7 downto 0)=y1(7 downto 0);i:=i+1;end loop;-y(7)=opr1(7) xor opr2(7);result15) or (opr215) then flag-传送数据 result-and result(0)=opr1(0)and opr2(0); result(1)=opr1(1)and opr2(1); result(2)=opr1(2)and opr2(2); result(3)=opr1(3)and opr2(3); result(4)=opr1(4)and opr2(4); result(5)=opr1(5)and opr2(5); result(6)=opr1(6)and opr2(6); result(7)-or result(0)=opr1(0)or opr2(0); result(1)=opr1(1)or opr2(1); result(2)=opr1(2)or opr2(2); result(3)=opr1(3)or opr2(3); result(4)=opr1(4)or opr2(4); result(5)=opr1(5)or opr2(5); result(6)=opr1(6)or opr2(6); result(7)-not result(0)=not opr1(0); result(1)=not opr1(1); result(2)=not opr1(2); result(3)=not opr1(3); result(4)=not opr1(4); result(5)=not opr1(5); result(6)=not opr1(6); result(7)-xor result(0)=opr1(0)xor opr2(0); result(1)=opr1(1)xor opr2(1); result(2)=opr1(2)xor opr2(2); result(3)=opr1(3)xor opr2(3); result(4)=opr1(4)xor opr2(4); result(5)=opr1(5)xor opr2(5); result(6)=opr1(6)xor opr2(6); result(7)-SAL case opr2 is when 00000000=resultresult(0)=opr1(0); result(7 downto 1)result(0)=opr1(0); result(1)=opr1(0); result(7 downto 2)result(0)=opr1(0); result(1)=opr1(0); result(2)=opr1(0); result(7 downto 3)result(0)=opr1(0); result(1)=opr1(0); result(2)=opr1(0); result(3)=opr1(0); result(7 downto 4)result(0)=opr1(0); result(1)=opr1(0); result(2)=opr1(0); result(3)=opr1(0); result(4)=opr1(0); result(7 downto 5)result(0)=opr1(0); result(1)=opr1(0); result(2)=opr1(0); result(3)=opr1(0); result(4)=opr1(0); result(5)=opr1(0); result(7 downto 6)result(0)=opr1(0); result(1)=opr1(0); result(2)=opr1(0); result(3)=opr1(0); result(4)=opr1(0); result(5)=opr1(0); result(6)=opr1(0); result(7)result=00000000; flag-SAR case opr2 is when 00000000=resultresult(7)=opr1(7); result(6 downto 0)result(7)=opr1(7); result(6)=opr1(7); result(5 downto 0)result(7)=opr1(7); result(6)=opr1(7); result(5)=opr1(7); result(4 downto 0)result(3 downto 0)=opr1(7 downto 4); result(4)=opr1(7); result(5)=opr1(7); result(6)=opr1(7); result(7)result(7)=opr1(7); result(6)=opr1(7); result(5)=opr1(7); result(4)=opr1(7); result(3)=opr1(7); result(2 downto 0)result(7)=opr1(7); result(6)=opr1(7); result(5)=opr1(7); result(4)=opr1(7); result(3)=opr1(7); result(2)=opr1(7); result(1 downto 0)result(7)=opr1(7); result(6)=opr1(7); result(5)=opr1(7); result(4)=opr1(7); result(3)=opr1(7); result(2)=opr1(7); result(1)=opr1(7); result(0)result=00000000; flag-SLL case opr2 is when 00000000=resultresult(0)=0; result(7 downto 1)result(1 downto 0)=00; result(7 downto 2)result(2 downto 0)=000; result(7 downto 3)result(3 downto 0)=0000; result(7 downto 4)result(4 downto 0)=00000; result(7 downto 5)result(5 downto 0)=000000; result(7 downto 6)result(6 downto 0)=0000000; result(7)result=00000000; flag-SLR case opr2 is when 00000000=resultresult(7)=0; result(6 downto 0)result(7 downto 6)=00; result(5 downto 0)result(7 downto 5)=000; result(4 downto 0)result(7 downto 4)=0000; result(3 downto 0)result(7 downto 3)=00000; result(2 downto 0)result(7 downto 2)=000000; result(1 downto 0)result(7 downto 1)=0000000; result(0)result=00000000; flag-ROL case opr2 is when 00000000=resultresult(0)=opr1(7); result(7 downto 1)re

温馨提示

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

评论

0/150

提交评论