首页 > 其他分享 >HDLBits答案——Circuits

HDLBits答案——Circuits

时间:2022-08-22 16:01:39浏览次数:96  
标签:endmodule HDLBits Circuits module 答案 output input assign out

1 Combinational Logic

1.1 Basic Gates

1.1.1 Exams/m2014 q4h

module top_module (
    input in,
    output out);
	assign out = in;
endmodule

1.1.2 Exams/m2014 q4i

module top_module (
    output out);
    assign out = 1'b0;
endmodule

1.1.3 Exams/m2014 q4e

module top_module (
    input in1,
    input in2,
    output out);
    assign out = ~(in1|in2);

endmodule

1.1.4 Exams/m2014 q4f

module top_module (
    input in1,
    input in2,
    output out);
    assign out = in1&(~in2);
    
endmodule

1.1.5 Exams/m2014 q4g

module top_module (
    input in1,
    input in2,
    input in3,
    output out);
    wire out1;
    assign out1 = in1^in2;
    assign out = ~(out1^in3);

endmodule

1.1.6 Gates

module top_module( 
    input a, b,
    output out_and,
    output out_or,
    output out_xor,
    output out_nand,
    output out_nor,
    output out_xnor,
    output out_anotb
);
    assign out_and = a&b;
    assign out_or = a|b;
    assign out_xor = (a^b);
    assign out_nand = ~(a&b);
    assign out_nor = ~(a|b);
    assign out_xnor = ~(a^b);
    assign out_anotb = a&~b;
    

endmodule

1.1.7 7420

module top_module ( 
    input p1a, p1b, p1c, p1d,
    output p1y,
    input p2a, p2b, p2c, p2d,
    output p2y );
    
    assign p1y = ~(p1a&p1b&p1c&p1d);
    assign p2y = ~(p2a&p2b&p2c&p2d);

endmodule

1.1.8 Truthtable1

module top_module( 
    input x3,
    input x2,
    input x1,  // three inputs
    output f   // one output
);
    assign f = (x3&x1)|(~x3&x2);

endmodule

1.1.9 Mt2015 eq2

module top_module ( input [1:0] A, input [1:0] B, output z ); 
    always @(*)begin
        if(A==B)
            z = 1;
        else
            z = 0;
    end

endmodule

1.1.10 Mt2015 q4a

module top_module (input x, input y, output z);
    assign z = (x ^ y) & x;

endmodule

1.1.11 Mt2015 q4b

module top_module ( input x, input y, output z );
    assign z = ~(x^y);
endmodule

1.1.12 Mt2015 q4

module top_module (input x, input y, output z);
    wire [3:0] z_pr;
    IA U1(x,y,z_pr[0]);
    IB L1(x,y,z_pr[1]);
    IA U2(x,y,z_pr[2]);
    IB L2(x,y,z_pr[3]);
    
    assign z = (z_pr[0]|z_pr[1])^(z_pr[2]&z_pr[3]);

endmodule

module IA(input a,input b, output c);
    assign c = (a ^ b) & a;
endmodule

module IB(input a,input b, output c);
    assign c = ~(a^b);
endmodule

1.1.13 Ringer

module top_module (
    input ring,
    input vibrate_mode,
    output ringer,       // Make sound
    output motor         // Vibrate
);
    assign ringer = ring & (~vibrate_mode);
    assign motor = ring & vibrate_mode;
endmodule

1.1.14 Thermostat

module top_module (
    input too_cold,
    input too_hot,
    input mode,
    input fan_on,
    output heater,
    output aircon,
    output fan
); 
    assign heater = mode&too_cold;
    assign aircon = too_hot&~mode;
    assign fan = (heater | aircon) | fan_on;
endmodule

1.1.15 Popcount3

module top_module( 
    input [2:0] in,
    output [1:0] out );
    integer i;
    
    always @(*) begin
        out = 0;
        for(i = 0; i < 3; i ++) begin
            if(in[i])
                out++;
        end
    end

endmodule

1.1.15 Popcount3

module top_module( 
    input [2:0] in,
    output [1:0] out );
    integer i;
    
    always @(*) begin
        out = 0;
        for(i = 0; i < 3; i ++) begin
            if(in[i])
                out++;
        end
    end

endmodule

1.1.16 Gatesv

module top_module( 
    input [3:0] in,
    output [2:0] out_both,
    output [3:1] out_any,
    output [3:0] out_different );
    integer i;
        always @(*)begin
            for(i = 0;i<3;i++)
                begin
                out_both[i] = in[i]&in[i+1];
                out_any[i+1] = in[i]|in[i+1];
                out_different[i] = in[i]^in[i+1];
                end
                out_different[3] = in[3]^in[0];
        end

endmodule

1.1.17 Gatesv100

module top_module( 
    input [99:0] in,
    output [98:0] out_both,
    output [99:1] out_any,
    output [99:0] out_different );
        integer i;
        always @(*)begin
            for(i = 0;i<99;i++)
                begin
                out_both[i] = in[i]&in[i+1];
                out_any[i+1] = in[i]|in[i+1];
                out_different[i] = in[i]^in[i+1];
                end
            out_different[99] = in[99]^in[0];
        end
endmodule
## 1.2 Multiplexers
### 1.2.1 Mux2to1

module top_module(
input a, b, sel,
output out );
always @(*)begin
case(sel)
1'b0:out=a;
1'b1:out=b;
endcase
end

endmodule

### 1.2.2 Mux2to1v

module top_module(
input [99:0] a, b,
input sel,
output [99:0] out );
always @(*)begin
case(sel)
1'b0:out=a;
1'b1:out=b;
endcase
end
endmodule

### 1.2.3 Mux9to1v

module top_module(
input [15:0] a, b, c, d, e, f, g, h, i,
input [3:0] sel,
output [15:0] out );
always @(*) begin
case(sel)
0 : out = a;
1 : out = b;
2 : out = c;
3 : out = d;
4 : out = e;
5 : out = f;
6 : out = g;
7 : out = h;
8 : out = i;
default : out = 16'hffff;
endcase
end
endmodule

### 1.2.4 Mux256to1

module top_module(
input [255:0] in,
input [7:0] sel,
output out );
assign out = in[sel];

endmodule

### 1.2.5 Mux256to1v

module top_module(
input [1023:0] in,
input [7:0] sel,
output [3:0] out );
assign out = {in[4sel+3],in[4sel+2],in[4sel+1],in[4sel]};

endmodule

## 1.3 Arithmetic Circuits
###

标签:endmodule,HDLBits,Circuits,module,答案,output,input,assign,out
From: https://www.cnblogs.com/hubuguilai/p/16613079.html

相关文章

  • HDLBits(二) 8.22
    2.Verilog语言2.1基础2.1.7声明导线创建一个中间信号,用于简化整个电路模块的逻辑表达语法:wirefoo;#foo为定义的wirename#wirew1,w2;  as......
  • HDLBits(一)(边刷边学)
    1开始1.1输出逻辑1直接assignone=1'b1,给outputone赋值1'b1,表示1bit数值,b=二进制,o=八进制,d=十进制,h=十六进制1.2输出逻辑0 可以直接提交,因为在Quartus中,输出端......
  • 安卓系统经常提示更新?我们该怎么选择,其实早有答案【简单明了易懂】
    现在迷上了他们家的资讯,片片文章都精彩,给大家留个路 叮当守护-新闻资讯-安卓系统经常提示更新?我们该怎么选择,其实早有答案。原来锤子科技的Boss罗总曾发微博就说过这样的......
  • HDLBits答案——Verilog Language
    VerilogLanguage1Basics1.1Wiremoduletop_module(inputin,outputout);assignout=in;endmodule1.2Wire4moduletop_module(inputa,b,......
  • HDLBits答案——Getting started
    Gettingstarted1Steponemoduletop_module(outputone);//Insertyourcodehereassignone=1'b1;endmodule2Zeromoduletop_module(outputze......
  • SQL自学网习题答案
    ​附学习网址:自学SQL网(教程视频练习全套)第一节:1【初体验】这是第一题,请你先将左侧的输入框里的内容清空,然后请输入下面的SQL,您将看到所有电影标题:答案:SELECT*FR......
  • 2022年“研究生科研素养提升”系列公益讲座 测试答案
    一、单选题1、在科研研究的伦理原则中,科技工作者应该坚持科学研究的客观性,杜绝蓄意的捏造、作假和对研究成果的曲解,指的是()诚信原则责任原则公平原则审慎原则您的答......
  • P6733 「Wdsr-2」间歇泉——二分答案
    二分可以将优化问题转为判定问题,也可以将\(k\)大问题转为计数问题分析由于已知条件,\(\displaystyleT=\frac{a_ic_i+a_jc_j}{a_i+a_j}\),转为计数问题则是固定T,统计有多少......
  • 参考答案
    单选题(共2题,每题20分)展望十四五规划,我国人均国内生产总值将达到()水平,()群体显著扩大。A.发达国家、中间收入B.中等发达国家、中间收入C.发达国家、中等收入D.中等发......
  • 戏开发程序岗面试题答案版(一)-- C++篇
     游戏开发程序岗面试题答案版C++篇, 后续继续更新游戏逻辑篇、unity篇、图形学篇,并整理成文档,可在公号【游戏君五尘】获取。 网页排版排版较乱,原文链接游戏开......