HDLBits训练4

时间:2024.12.23

Dff8ar

代码

注意敏感信号的写法

复制代码
module top_module (
    input clk,
    input areset,   // active high asynchronous reset
    input [7:0] d,
    output [7:0] q
);
    always@(posedge clk or posedge areset)
        begin
        if(areset) q<=8'b0;
    else q<=d;
        end
endmodule

module top_module (
    input clk,
    input areset,   // active high asynchronous reset
    input [7:0] d,
    output [7:0] q
);

    always@(posedge clk or posedge areset)begin
        q<=areset==1?8'd0:d;
    end
endmodule

运行结果

Dff16e

代码

注:byteena[1]控制输入数据d的高八位,byteena[0]控制输入数据d的低八位,未被控制部分保持输出。

复制代码
module top_module (
    input clk,
    input resetn,
    input [1:0] byteena,
    input [15:0] d,
    output [15:0] q
);

    always@(posedge clk)begin
        if(resetn==0)begin
            q<=16'd0;
        end else begin
            case(byteena)
                2'b10:q<={d[15:8],q[7:0]};
                2'b01:q<={q[15:8],d[7:0]};
                2'b11:q<={d[15:8],d[7:0]};
                default:q<=q;
            endcase
        end
    end
endmodule

运行结果

Exams/m2014 q4a

代码

复制代码
module top_module (
    input d, 
    input ena,
    output q);
    always@(*)
        if(ena) q<=d;
    else q<=q;
    
endmodule

module top_module (
    input d, 
    input ena,
    output q);

    always@(*)begin
        q<=ena==1?d:q;
    end
endmodule

注:1)锁存器是电平敏感,不是边沿敏感;2)锁存器虽然是电平敏感,但是是时序电路,用非阻塞赋值<=

运行结果

Exams/m2014 q4b

代码

复制代码
module top_module (
    input clk,
    input d, 
    input ar,   // asynchronous reset
    output q);

    always@(posedge clk or posedge ar)begin
        q<=ar==1?1'b0:d;
    end
endmodule

module top_module (
    input clk,
    input d, 
    input ar,   // asynchronous reset
    output q);

    always@(posedge clk or posedge ar)begin
        if(ar) q<=1'b0;
        else q<=d;
    end
endmodule

运行结果

Exams/m2014 q4c

代码

复制代码
module top_module (
    input clk,
    input d, 
    input r,   // synchronous reset
    output q);
    always@(posedge clk)
        begin
            if(r) q<=1'b0;
            else q<=d;
        end
endmodule

module top_module (
    input clk,
    input d, 
    input r,   // synchronous reset
    output q);

    always@(posedge clk)begin
        q<=r==1?1'b0:d;
    end
endmodule

运行结果

Exams/m2014 q4d

代码

复制代码
module top_module (
    input clk,
    input in, 
    output out);
    wire d;
       assign d=in^out;
    always@(posedge clk)
        begin
          out<=d;  
        end
  //  assign d=in^out;
endmodule

注:组合逻辑的语句放在时序逻辑的前/后均可以

复制代码
module top_module (
    input clk,
    input in, 
    output out);

    always@(posedge clk)begin
        out<=in^out;
    end
endmodule

运行结果

Mt2015 muxdff

代码

复制代码
module top_module (
	input clk,
	input L,
	input r_in,
	input q_in,
	output reg Q);
reg D;
    assign D=L?r_in:q_in;
    always@(posedge clk)
        Q<=D;
endmodule

module top_module (
	input clk,
	input L,
	input r_in,
	input q_in,
	output reg Q);

    always@(posedge clk)begin
        Q<=L==1?r_in:q_in;
    end
endmodule

运行结果

Exams/2014 q4a

代码

复制代码
module top_module (
    input clk,
    input w, R, E, L,
    output Q
);
reg d;
    assign d=L?R:(E?w:Q);
    always@(posedge clk)
        begin
            Q<=d;
        end
endmodule

module top_module (
    input clk,
    input w, R, E, L,
    output Q
);
    always@(posedge clk)begin
        Q<=L==1?R:(E==1?w:Q);
    end
endmodule

运行结果

Exams/ece241 2014 q4

代码

复制代码
module top_module (
    input clk,
    input x,
    output z
); 
    wire q1,q2,q3;
    always@(posedge clk)
        begin
            q1<=(x^q1);
            q2<=(x&~q2);
            q3<=(x|~q3);
        end
    assign z=~(q1|q2|q3);
endmodule

运行结果

Exams/ece241 2013 q7

代码

复制代码
module top_module (
    input clk,
    input j,
    input k,
    output Q); 
    always@(posedge clk)
        begin
            if(~j&k) Q<=1'b0;
            else if(j&~k) Q<=1'b1;
            else if(j&k) Q<=~Q;
            else Q<=Q;
        end
endmodule

运行结果

相关推荐
qq_527887876 分钟前
【学习笔记】Python中主函数调用的方式
笔记·学习
二闹38 分钟前
第十六章:监理基础知识(16.1监理的意义和作用--16.5监理要素)
笔记·产品经理
致***锌2 小时前
etf期权和个股期权哪个期权费更贵?
笔记
懒惰的bit10 天前
STM32F103C8T6 学习笔记摘要(四)
笔记·stm32·学习
zkyqss10 天前
OVS Faucet练习(下)
linux·笔记·openstack
浦东新村轱天乐10 天前
【麻省理工】《how to speaking》笔记
笔记
奔跑的蜗牛AZ10 天前
TiDB 字符串行转列与 JSON 数据查询优化知识笔记
笔记·json·tidb
尤老师FPGA10 天前
使用DDR4控制器实现多通道数据读写(十六)
fpga开发·ddr4
cwtlw10 天前
Excel学习03
笔记·学习·其他·excel
杭州杭州杭州10 天前
计算机网络笔记
笔记·计算机网络