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

运行结果

相关推荐
奥特曼_ it21 小时前
【数据分析+机器学习】基于机器学习的招聘数据分析可视化预测推荐系统(完整系统源码+数据库+开发笔记+详细部署教程)✅
笔记·数据挖掘·数据分析
四维碎片1 天前
QSettings + INI 笔记
笔记·qt·算法
zzcufo1 天前
多邻国第5阶段17-18学习笔记
笔记·学习
BlackWolfSky1 天前
鸿蒙中级课程笔记4—应用程序框架进阶1—Stage模型应用组成结构、UIAbility启动模式、启动应用内UIAbility
笔记·华为·harmonyos
中屹指纹浏览器1 天前
指纹浏览器性能优化实操——多实例并发与资源占用管控
经验分享·笔记
了一梨1 天前
SQLite3学习笔记5:INSERT(写)+ SELECT(读)数据(C API)
笔记·学习·sqlite
jrlong1 天前
DataWhale大模型基础与量化微调task5学习笔记(第 3 章:大模型训练与量化_模型量化实战)
笔记·学习
Sarvartha1 天前
Routing(路由与分支)学习笔记
笔记·学习
Yu_Lijing1 天前
《图解HTTP》笔记与读后感(上)
网络·笔记·网络协议·http
雨洛lhw1 天前
24bit AD采样高效数据打包方案解析
fpga开发·数据打包方式·ddr突发读写注意事项