合肥工业大学(HFUT)2024计算机组成原理实验5

注:相应的源文件在文末的github链接中

实验五  在vivado中进行运算器的设计

一.实验要求

1、采用原理图方式设计4位加/减法器

2、实现4位ALU及应用设计

二.采用四个一位的全加器和附加逻辑设计两个四位数的加/减法器的实现

要求

采用四个一位的全加器和附加逻辑,根据图10设计两个四位数的加/减法器。要求编写与此电路对应的verilog代码。编写激励输入文件,激励文件要求放入实验报告。进行仿真,仿真截图放入实验报告。生成比特流文件,进行下载,下载后进行运行,只需要一张运行照片放入实验报告。

源文件

`timescale 1ns / 1ps

module adder_1bit(s,co,a,b,ci);

    input a,b,ci;

    output s,co;

    wire c1,c2,c3;

    and m0 (c1 ,a,b) ;

    and m1 (c2 ,b ,ci) ;

    and m2 (c3 ,a ,ci) ;

    xor m3 (s1 ,a ,b) ;

    xor m4 (s , s1,ci) ;

    or m5(co ,c1 ,c2,c3) ;

    endmodule

//模块 1位加减法

module addsub_1bit(S, Co, A, B, Ctrl, Ci);

    input A, B, Ctrl, Ci;

    output S, Co;

    xor xor2(B1,B,Ctrl);

    adder_1bit ad(S,Co,A,B1,Ci);

endmodule

module addsub_4bit(S,Co,Ctrl,A,B);

    input[3:0] A,B;

    input Ctrl;

    output[3:0] S;

    output Co;

    wire [3:0] C;

    wire n1, n2, a1, a2;

   

    addsub_1bit as1_0(S[0], C[0], A[0], B[0], Ctrl, Ctrl);

    addsub_1bit as1_1(S[1], C[1], A[1], B[1], Ctrl, C[0]);

    addsub_1bit as1_2(S[2], C[2], A[2], B[2], Ctrl, C[1]);

    addsub_1bit as1_3(S[3], C[3], A[3], B[3], Ctrl, C[2]);

    not not1(n1,Ctrl);

    not not2(n2,C[3]);

    and and1(a1,C[3],n1);

    and and2(a2,Ctrl,n2);

    or or1(Co,a1,a2);

endmodule

激励文件(找不到在哪了,建议可以参考下文自己写一个)

三.采用与逻辑、或逻辑和数据选择器设计两个四位数的加/减法器,与运算、或运算的实现

要求

根据图15,采用与逻辑、或逻辑和四选一数据选择器设计两个四位数的加/减法器。要求编写与此电路对应的verilog代码。编写激励输入文件,激励文件要求放入实验报告。进行仿真,仿真截图放入实验报告。生成比特流文件,进行下载,下载后进行运行,只需要一张运行照片放入实验报告。

源文件

`timescale 1ns / 1ps

module adder_1bit(s,co,a,b,ci);

    input a,b,ci;

    output s,co;

    wire c1,c2,c3;

    and m0 (c1 ,a,b) ;

    and m1 (c2 ,b ,ci) ;

    and m2 (c3 ,a ,ci) ;

    xor m3 (s1 ,a ,b) ;

    xor m4 (s , s1,ci) ;

    or m5(co ,c1 ,c2,c3) ;

    endmodule

//模块 1位加减法

module addsub_1bit(S, Co, A, B, Ctrl, Ci);

  input A, B, Ctrl, Ci;

  output S, Co;

    xor xor2(B1,B,Ctrl);

    adder_1bit ad(S,Co,A,B,Ci);

endmodule

module addsub_4bit(S,Co,Ctrl,A,B);

  input[3:0] A,B;

  input Ctrl;

    output[3:0] S;

  output Co;

  wire [3:0] C;

    wire n1, n2, a1, a2;

   

    addsub_1bit as1_0(S[0], C[0], A[0], B[0], Ctrl, Ctrl);

    addsub_1bit as1_1(S[1], C[1], A[1], B[1], Ctrl, C[0]);

    addsub_1bit as1_2(S[2], C[2], A[2], B[2], Ctrl, C[1]);

    addsub_1bit as1_3(S[3], C[3], A[3], B[3], Ctrl, C[2]);

    not not1(n1,Ctrl);

    not not2(n2,C[3]);

    and and1(a1,C[3],n1);

    and and2(a2,Ctrl,n2);

    or or1(Co,a1,a2);

endmodule

module myAnd2b4(C,A,B);

    input [3:0] A,B;

    output [3:0] C;

    and and1(C[0],A[0],B[0]);

    and and2(C[1],A[1],B[1]);

    and and3(C[2],A[2],B[2]);

    and and4(C[3],A[3],B[3]);

endmodule

module myOr2b4(C,A,B);

    input [3:0] A,B;

    output [3:0] C;

    or or1(C[0],A[0],B[0]);

    or or2(C[1],A[1],B[1]);

    or or3(C[2],A[2],B[2]);

    or or4(C[3],A[3],B[3]);

endmodule

module Mux4to1(a, b, c, d, select, out);

  input wire [1:0] select;

    input  wire a,b,c,d;

    output  reg out;

    always @(*) begin

        case(select)

            2'b00: out = 0;

            2'b01: out = 0;

            2'b10: out = c;

            2'b11: out = d;

            //default: out = 1'b0; // 如果选择信号无效,输出为0

        endcase

    end

endmodule

module Mux4to1b4(a, b, c, d, select, out);

    input[1:0] select;

    input[3:0] a, b, c, d;

    output reg[3:0] out;

    always @(*) begin

        case(select)

            2'b00: out = a;

            2'b01: out = b;

            2'b10: out = c;

            2'b11: out = d;

            default: out = 4'b0000; // 如果选择信号无效,输出为0

        endcase

    end

endmodule

module addsub_4bitmux(C,Co,S,A,B);

    input[3:0] A,B;

    input[1:0] S;

    output[3:0] C;

    output reg Co;

    wire [3:0] S1,C1,C2;

    wire Co1;

  Mux4to1b4 m1(S1, S1, C1, C2, S,C);

    //Mux4to1 m2(1'b0,1'b0,Co1,Co1,Co);

    always@(*) begin

        if(S == 2'b00 | S == 2'b01)

            Co = 1'b0;

        else

            Co = Co1;

    end

   

    addsub_4bit a4(S1,Co1, S[0],A,B);

    myAnd2b4 ma(C1,A,B);

    myOr2b4 mo(C2,A,B);

endmodule

激励文件(注意可能需要改变延时时间为自己的学号)

module  addsub_4bitmux_tb();

    wire[3:0] sum;

    wire Co;

    reg [3:0] a, b;

    reg [1:0] cin;

    addsub_4bitmux as4m(sum,Co,cin,a,b);

    initial

        begin//这个其实就是真值表的应用

            a = 4'b0001; b = 4'b1010; cin = 2'b00;

            #100 a = 4'b0010; b = 4'b1010; cin = 2'b01;

            #100 a = 4'b0010; b = 4'b1110; cin = 2'b10;

            #100 a = 4'b0011; b = 4'b1100; cin = 2'b11;

            #100 a = 4'b0111; b = 4'b1001; cin = 2'b00;

            #100 a = 4'b0001; b = 4'b1100; cin = 2'b01;

            #100 a = 4'b0011; b = 4'b1100; cin = 2'b10;

            #100 a = 4'b0111; b = 4'b1111; cin = 2'b11;

        end

endmodule

四.github仓库链接

  • 33
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值