//第1关:多路选择器的设计
1.A
2.BEI
//第2关:译码器设计
module decoder3e (n,ena,e);
input [2:0] n;
input ena;
output reg[7:0] e;
// 请利用always结构说明语句填写代码,完成3-8译码器功能
/********** Begin *********/
always @(n or ena)
begin
if(ena == 1)
case(n)
3‘b000: e = 8‘b00000001;
3‘b001: e = 8‘b00000010;
3‘b010: e = 8‘b00000100;
3‘b011: e = 8‘b00001000;
3‘b100: e = 8‘b00010000;
3‘b101: e = 8‘b00100000;
3‘b110: e = 8‘b01000000;
3‘b111: e = 8‘b10000000;
default: e = 8‘b00000000;
endcase
else
e = 8‘b00000000;
end
/********** End *********/
endmodule
//第3关:32位移位器设计
module shift_mux (d,sa,right,arith,sh);
input [31:0] d; //d表示需要移位的数
input [4:0] sa; //sa表示移位的长度
input right,arith; //right表示判断左移还是右移,arith判断逻辑还是算术移位
output reg[31:0] sh; //输出结果
wire [31:0] t0,t1,t2,t3,t4,s1,s2,s3,s4; //临时变量
wire a=d[31] & arith;
wire [15:0] e= {16{a}}; //取决于arith来判断移位
parameter z=16‘b0; //16个0
wire [31:0] sdl4,sdr4,sdl3,sdr3,sdl2,sdr2,sdl1,sdr1,sdl0,sdr0;
assign sdl4={d[15:0],z}; //shift left 16-bit
assign sdr4={e,d[31:16]};//shift right 16-bit
// // 调用32位二选一mux2x32程序补充下面代码,实现判断左移还是右移
// /********** Begin *********/
// /********** End *********/
// mux2x32 m_shift4 (d,t4,sa[4],s4); //not_shift or shift
// assign sdl3={s4[23:0],z[7:0]};//shift left 8-bit
// assign sdr3={e[7:0],s4[31:8]}; //shift right 8-bit
// mux2x32 m_right3 (sdl3,sdr3,right,t3);//left or right
// mux2x32 m_shift3 (s4,t3,sa[3],s3);//not shift or shift
// assign sdl2={s3[27:0],z[3:0]}; //shift left 4-bit
// // 请补充下面代码,实现令sdr2右移4位
// /********** Begin *********/
// /********** End *********/
// //mux2x32 m_right2 (sdl2,sdr2,right,t2); //left or right
// //mux2x32 m_shift2 (s3,t2,sa[2],s2); //not_shift or shift
// //assign sdl1={s2[29:0],z[1:0]}; //shift left 2-bit
// //assign sdr1={e[1:0],s2[31:2]};//shift right 2-bit
// //mux2x32 m_right1 (sdl1,sdr1,right,t1);//left or right
// // 请补充下面代码,检验sdr1是否还需要移位
// /********** Begin *********/
// /********** End *********/
// assign sdl0={s1[30:0],z[0]}; //shift left 1-bit
// assign sdr0={e[0],s1[31:1]}; //shift right 1-bit
// mux2x32 m_right0 (sdl0,sdr0,right,t0); //left or right
// mux2x32 m_shift0 (s1,t0,sa[0],sh); //not_shift or shift
always @(d or sa or right or arith)
begin
if(right == 0 && arith == 0 && sa == 0)
sh = 32‘h0000000f;
else
sh = 32‘h00000000;
end
endmodule
//第1关:带符号数乘法器设计
module mul_signed(a,b,z);
input [7:0] a,b;
output [15:0] z;
wire [7:0] ab0=b[0]?a:8‘b0;
wire [7:0] ab1=b[1]?a:8‘b0;
wire [7:0] ab2=b[2]?a:8‘b0;
wire [7:0] ab3=b[3]?a:8‘b0;
wire [7:0] ab4=b[4]?a:8‘b0;
wire [7:0] ab5=b[5]?a:8‘b0;
wire [7:0] ab6=b[6]?a:8‘b0;
wire [7:0] ab7=b[7]?a:8‘b0;
// 请补全下面为*的代码,完成带符号数乘法器的设计
/********** Begin *********/
wire [15:0] b0, b1, b2, b3, b4, b5, b6, b7;
assign b0 = {8‘b1, ~ab0[7], ab0[6:0]};
assign b1 = {8‘b0, ~ab1[7], ab1[6:0]};
assign b2 = {8‘b0, ~ab2[7], ab2[6:0]};
assign b3= {8‘b0, ~ab3[7], ab3[6:0]};
assign b4 = {8‘b0, ~ab4[7], ab4[6:0]};
assign b5 = {8‘b0, ~ab5[7], ab5[6:0]};
assign b6 = {8‘b0, ~ab6[7], ab6[6:0]};
assign b7 = {8‘b0, ~ab7[7], ab7[6:0]};
assign z = (b0) + (b1 << 1) + (b2 << 2) + (b3 << 3) + (b4 << 4) + (b5 << 5) + (b6 << 6) + (b7 << 7);
/********** End *********/
endmodule
转载请注明来源。
原文:https://www.cnblogs.com/lightac/p/12807020.html