组成专题实验报告三Word文档格式.docx

上传人:b****3 文档编号:18259473 上传时间:2022-12-14 格式:DOCX 页数:15 大小:78.29KB
下载 相关 举报
组成专题实验报告三Word文档格式.docx_第1页
第1页 / 共15页
组成专题实验报告三Word文档格式.docx_第2页
第2页 / 共15页
组成专题实验报告三Word文档格式.docx_第3页
第3页 / 共15页
组成专题实验报告三Word文档格式.docx_第4页
第4页 / 共15页
组成专题实验报告三Word文档格式.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

组成专题实验报告三Word文档格式.docx

《组成专题实验报告三Word文档格式.docx》由会员分享,可在线阅读,更多相关《组成专题实验报告三Word文档格式.docx(15页珍藏版)》请在冰豆网上搜索。

组成专题实验报告三Word文档格式.docx

由于在运算器内通常只能完成对两数的求乘操作,则可以每求得一个相加数,就同时完成与上一次部分积相加的操作。

其次是在手工计算时,各加数逐位左移,最终相加数为相乘二位数的两倍,而在计算机中,加法器的位数一般与乘法器的位数相同,而不是寄存器位数的两倍。

这实际上也可以用另外的办法解决。

手工计算时,各加数是逐位左移,但很容易发现,在求本次部分积之和时,前一部分积的最低一位是不再与任何数值相加的。

这就意味着,若采用每求得一次部分积之后使其右移一位,则可以只用N位的加法器就能实现两个N位的数相乘j!

显而易见,若前一次部分积已经右移一位,就可以用其高位部分加上被乘数或加零的方法求得本次部分积。

最后一点是,手工计算时,乘数每一位的值是0还是1都直接看得见,而在计算机内,采用放乘数的寄存器的每一位直接决定本次相加数是被乘数还是零是很不方便的,若均采用该寄存器的最低一位来执行这种判别就简便了。

为此,只要每求一次部分积就使放乘数的寄存器执行一次右移操作即可以了。

若移位时,使其最高数值位接收加法器最低位的输出,则完成乘法运算后,该寄存器中保存的是乘积的低位部分。

计算机内求乘积的符号,很容易用求相乘二数符号的半加和(异或值)实现。

原码一位乘法的规则:

⑴判断参加运算的操作数是否合格;

⑵令乘数的最低位为判断位,若为“1”,加被乘数,若为“0”,不加被乘数(加0);

⑶累加后的部分积以及乘数右移一位

⑷重复n次⑵和⑶;

⑸符号位单独处理,同号为正,异号为负。

通常,乘法运算需要3个寄存器。

被乘数存放在B寄存器中;

乘数存放在C寄存器中;

A寄存器用来存放部分积与最后乘积的高位部分,它的初值为0。

运算结束后寄存器C中不再保留乘数,改为存放乘积的低位部分。

例:

已知:

X=0.1101,Y=-0.1011,求:

Y。

|X|=00.1101→B,|Y|=.1011→C,0→A

原码一位乘法示例

AC说明

00.00001011

+|X|00.1101C4=1,+|X|

00.1101

→00.01101101部分积右移一位

01.0011

→00.10011110部分积右移一位

+000.0000C4=0,+0

00.1001

→00.01001111部分积右移一位

+|X|00.1101C4=1,+|X|

01.0001

→00.10001111部分积右移一位

∵PS=XS⊕YS=0⊕1=1

∴X*Y=-0.10001111

原码一位乘法流程图

这里为了简便,我编写了无符号数原码的乘法运算,不考虑符号位。

即实现了两个四位数相乘,结果放入一个八位数中。

4、实验源代码

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

useieee.std_logic_arith.all;

entityALUis

port(

set:

instd_logic;

--运算控制信号

code:

instd_logic_vector(3downto0);

--操作码

cin:

--低位向高位的进位或者借位信号

opr1:

instd_logic_vector(7downto0);

--第一操作数

opr2:

--第二操作数

result:

outstd_logic_vector(7downto0);

--运算结果

flag:

outstd_logic--运算结果标志位flag

);

endALU;

architecturebehavofALUis

signala:

std_logic_vector(7downto0);

signalb:

signalc:

sharedvariabley,x:

begin

process(b,c,temp1,set,code,cin,opr1,opr2)

variablei:

integer;

a<

="

00000000"

;

b<

C<

x:

temp:

temp1<

result<

flag<

='

0'

ifset='

1'

then

casecodeis

when"

0000"

=>

--"

+"

a(0)<

=opr1(0)andopr2(0);

b(0)<

=opr1(0)xoropr2(0);

--产生本地进位和传递条件

a

(1)<

=opr1

(1)andopr2

(1);

b

(1)<

=opr1

(1)xoropr2

(1);

a

(2)<

=opr1

(2)andopr2

(2);

b

(2)<

=opr1

(2)xoropr2

(2);

a(3)<

=opr1(3)andopr2(3);

b(3)<

=opr1(3)xoropr2(3);

a(4)<

=opr1(4)andopr2(4);

b(4)<

=opr1(4)xoropr2(4);

a(5)<

=opr1(5)andopr2(5);

b(5)<

=opr1(5)xoropr2(5);

a(6)<

=opr1(6)andopr2(6);

b(6)<

=opr1(6)xoropr2(6);

a(7)<

=opr1(7)andopr2(7);

b(7)<

=opr1(7)xoropr2(7);

--每四位一组,组内先行进位加法,组间串行进位加法.

result(0)<

=b(0)xorcin;

c(0)<

=a(0)or(b(0)andcin);

result

(1)<

=b

(1)xorc(0);

c

(1)<

=a

(1)or(b

(1)anda(0))or(b

(1)andb(0)andcin);

result

(2)<

=b

(2)xorc

(1);

c

(2)<

=a

(2)or(b

(2)anda

(1))or(b

(2)andb

(1)anda(0))or(b

(2)andb

(1)andb(0)andcin);

result(3)<

=b(3)xorc

(2);

c(3)<

=a(3)or(b(3)anda

(2))or(b(3)andb

(2)anda

(1))or(b(3)andb

(2)andb

(1)anda(0))or(b(3)andb

(2)andb

(1)andb(0)andcin);

result(4)<

=b(4)xorc(3);

c(4)<

=a(4)or(b(4)andc(3));

result(5)<

=b(5)xorc(4);

c(5)<

=a(5)or(b(5)anda(4))or(b(5)andb(4)andc(3));

result(6)<

=b(6)xorc(5);

c(6)<

=a(6)or(b(6)anda(5))or(b(6)andb(5)anda(4))or(b(6)andb(5)andb(4)andc(3));

result(7)<

=b(7)xorc(6);

flag<

=a(7)or(b(7)anda(6))or(b(7)andb(6)anda(5))or(b(7)andb(6)andb(5)anda(4))or(b(7)andb(6)andb(5)andb(4)andc(3));

0001"

+1"

=notopr1(0);

=opr1

(1)xoropr1(0);

=opr1

(2)xor(opr1

(1)andopr1(0));

=opr1(3)xor(opr1

(2)andopr1

(1)andopr1(0));

=opr1(4)xor(opr1(3)andopr1

(2)andopr1

(1)andopr1(0));

=opr1(5)xor(opr1(4)andopr1(3)andopr1

(2)andopr1

(1)andopr1(0));

=opr1(6)xor(opr1(5)andopr1(4)andopr1(3)andopr1

(2)andopr1

(1)andopr1(0));

=opr1(7)xor(opr1(6)andopr1(5)andopr1(4)andopr1(3)andopr1

(2)andopr1

(1)andopr1(0));

=opr1(7)andopr1(6)andopr1(5)andopr1(4)andopr1(3)andopr1

(2)andopr1(0);

0010"

-"

=opr1(0)and(notopr2(0));

=opr1(0)xor(notopr2(0));

=opr1

(1)and(notopr2

(1));

=opr1

(1)xor(notopr2

(1));

=opr1

(2)and(notopr2

(2));

=opr1

(2)xor(notopr2

(2));

=opr1(3)and(notopr2(3));

=opr1(3)xor(notopr2(3));

=opr1(4)and(notopr2(4));

=opr1(4)xor(notopr2(4));

=opr1(5)and(notopr2(5));

=opr1(5)xor(notopr2(5));

=opr1(6)and(notopr2(6));

=opr1(6)xor(notopr2(6));

=opr1(7)and(notopr2(7));

=opr1(7)xor(notopr2(7));

=b(0)xor(notcin);

=a(0)or(b(0)and(notcin));

=a

(1)or(b

(1)anda(0))or(b

(1)andb(0)and(notcin));

=a

(2)or(b

(2)anda

(1))or(b

(2)andb

(1)anda(0))or(b

(2)andb

(1)andb(0)and(notcin));

=a(3)or(b(3)anda

(2))or(b(3)andb

(2)anda

(1))or(b(3)andb

(2)andb

(1)anda(0))or(b(3)andb

(2)andb

(1)andb(0)and(notcin));

c(7)<

=notc(7);

0011"

-1"

=opr1

(1)xor(notopr1(0));

=opr1

(2)xor(not(opr1

(1)oropr1(0)));

=opr1(3)xor(not(opr1

(2)oropr1

(1)oropr1(0)));

=opr1(4)xor(not(opr1(3)oropr1

(2)oropr1

(1)oropr1(0)));

=opr1(5)xor(not(opr1(4)oropr1(3)oropr1

(2)oropr1

(1)oropr1(0)));

=opr1(6)xor(not(opr1(5)oropr1(4)oropr1(3)oropr1

(2)oropr1

(1)oropr1(0)));

=opr1(7)xor(not(opr1(6)oropr1(5)oropr1(4)oropr1(3)oropr1

(2)oropr1

(1)oropr1(0)));

=not(opr1(7)oropr1(6)oropr1(5)oropr1(4)oropr1(3)oropr1

(2)oropr1

(1)oropr1(0));

0100"

*"

操作数为4位,结果为8位,无符号数原码乘法

--c<

=opr1(3downto0)*opr2(3downto0);

x(0):

x

(1):

x

(2):

x(3):

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):

y(5):

y(6):

y(7):

i:

=0;

while(i<

4)loop

if(y(0)='

)theny:

=x+y;

elsey:

=y;

endif;

y(0):

=y

(1);

=y

(2);

=y(3);

=y(4);

=y(5);

=y(6);

=y(7);

--y(7downto0)<

=y1(7downto0);

i:

=i+1;

endloop;

--y(7)<

result<

if((opr1>

15)or(opr2>

15))thenflag<

endif;

0101"

--传送数据

result<

=opr1(7downto0);

0110"

and"

=opr1(0)andopr2(0);

=opr1

(1)andopr2

(1);

=opr1

(2)andopr2

(2);

=opr1(3)andopr2(3);

=opr1(4)andopr2(4);

=opr1(5)andopr2(5);

=opr1(6)andopr2(6);

=opr1(7)andopr2(7);

0111"

or"

=opr1(0)oropr2(0);

=opr1

(1)oropr2

(1);

=opr1

(2)oropr2

(2);

=opr1(3)oropr2(3);

=opr1(4)oropr2(4);

=opr1(5)oropr2(5);

=opr1(6)oropr2(6);

=opr1(7)oropr2(7);

1000"

not"

=notopr1

(1);

=notopr1

(2);

=notopr1(3);

=notopr1(4);

=notopr1(5);

=notopr1(6);

=notopr1(7);

1001"

xor"

=opr1(0)xoropr2(0);

=opr1

(1)xoropr2

(1);

=opr1

(2)xoropr2

(2);

=opr1(3)xoropr2(3);

=opr1(4)xoropr2(4);

=opr1(5)xoropr2(5);

=opr1(6)xoropr2(6);

=opr1(7)xoropr2(7);

1010"

SAL"

caseopr2is

when"

=opr1;

00000001"

result(0)<

result(7downto1)<

=opr1(6downto0);

00000010"

result(7downto2)<

=opr1(5downto0);

00000011"

result(7downto3)<

=opr1(4downto0);

00000100"

result(7downto4)<

=opr1(3downto0);

00000101"

result(7downto5)<

=opr1(2downto0);

00000110"

result(7downto6)<

=opr1(1downto0);

00000111"

whenothers=>

--error

endcase;

1011"

SAR"

result(7)<

=opr1(7);

result(6downto0)<

=opr1(7downto

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销 > 公共行政管理

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1