移位乘法器的设计.docx
《移位乘法器的设计.docx》由会员分享,可在线阅读,更多相关《移位乘法器的设计.docx(8页珍藏版)》请在冰豆网上搜索。
移位乘法器的设计
移位乘法器的设计
一.设计要求。
乘法器的输入为两个四位二进制数a和b,闸门信号STB启动乘法操作,时钟信号提供系统定时。
乘法结果为8位二进制信号RESULT,乘法结束后置信号
DONE为1。
框图如下:
二.算法思路如下:
采用原码移位算法,即对两操作数进行逐位的移位相加,迭代四次后获得乘法结果。
1.在被乘数和乘数的高位补0后扩展成8位。
2.乘数依次向右移位,并检查其最低位,如果该位为1,则将被乘数与部分积的和相加,然后被乘数向左端移位;如果最低位为0,则仅仅对被乘数进行移位操作。
移位时,乘数的高端和被乘数的低端都移入0。
3.当乘数变成全0后,乘法结束。
三.模块划分和进程设计:
把乘法器电路映射为控制器进程CONTROLLER、锁存移位进程SRA和SRB、加法进程ADDER以及锁存结果的进程ACC。
四.移位乘法器的进程模块图
五.按照书本上的代码仿真后的波形如下:
得出的是错误的结果。
经分析,可知道是由于在第三周期是shift的值出现错误,才导致结果错误。
为此修改源代码。
如下(红色为修改的部分):
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityshift_mulis
port(a,b:
instd_logic_vector(3downto0);
stb,clk:
instd_logic;
done:
outstd_logic;
result:
outstd_logic_vector(7downto0));
endshift_mul;
architecturebehavofshift_mulis
signalinit,shift,stop,add:
std_logic;
signalsraa,srbb,accout,addout:
std_logic_vector(7downto0);
begin
controller:
process
begin
waituntilclk'eventandclk='1'andstb='1';
done<='0';
init<='1';
shift<='0';add<='0';result<="00000000";
waituntilclk'eventandclk='1';
init<='0';
waituntilclk'eventandclk='1';
waituntilclk'eventandclk='1';
run_loop:
while(stop/='1')loop
waituntilclk'eventandclk='1';
ifsraa(0)='1'then
waituntilclk'eventandclk='1';
add<='1';
waituntilclk'eventandclk='1';
add<='0';
shift<='1';
waituntilclk'eventandclk='1';
else
waituntilclk'eventandclk='1';
shift<='1';
waituntilclk'eventandclk='1';
endif;
shift<='0';
endlooprun_loop;
done<='1';result<=accout;
endprocesscontroller;
sral:
process
begin
waituntilclk'eventandclk='1';
ifinit='1'then
sraa<="0000"&a;
elsifshift='1'then
sraa<='0'&sraa(7downto1);
endif;
stop<=not(sraa(3)orsraa
(2)orsraa
(1)orsraa(0));
endprocesssral;
srar:
process
begin
waituntilclk'eventandclk='1';
ifinit='1'then
srbb<="0000"&b;
elsifshift='1'then
srbb<=srbb(6downto0)&'0';
endif;
endprocesssrar;
adder:
process(accout,srbb)
variablesum,tmp1,tmp2:
std_logic_vector(7downto0);
variablecarry:
std_logic;
begin
tmp1:
=accout;
tmp2:
=srbb;
carry:
='0';
forIin0to7loop
sum(I):
=tmp1(I)xortmp2(I)xorcarry;
carry:
=(tmp1(I)andtmp2(I))or(tmp1(I)andcarry)or(tmp2(I)andcarry);
endloop;
addout<=sum;
endprocessadder;
acc:
process
begin
waituntilclk'eventandclk='1';
ifinit='1'then
accout<=(others=>'0');
elsifadd='1'then
accout<=addout;
endif;
endprocessacc;
endbehav;
七。
测试平台如下:
LibraryIEEE;
useIEEE.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityshift_mul_tbis
end;
architecturebehavofshift_mul_tbis
componentshift_mul
port(a,b:
instd_logic_vector(3downto0);
stb,clk:
instd_logic;
done:
outstd_logic;
result:
outstd_logic_vector(7downto0));
endcomponent;
signala,b:
std_logic_vector(3downto0);
signalstb,clk,done:
std_logic;
signalresult:
std_logic_vector(7downto0);
begin
uut_a:
shift_mulportmap(a,b,stb,clk,done,result);
process
begin
clk<='0';
waitfor100ns;
clk<='1';
waitfor100ns;
endprocess;
a<="1101";
b<="1010";
stb<='0','1'after5ns,'0'after400ns;
end;
configurationcfg_shift_mulofshift_mul_tbis
forbehav
endfor;
end;
经验证,其结果正确,为1101×1010=10000010(13×10=130)图形如下: