当前位置: 首页 > article >正文

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

 运行结果


http://www.kler.cn/a/453990.html

相关文章:

  • Flink RocksDB状态缩放加速:RocksDB原生DeleteRange原理简析
  • 云原生相关的 Go 语言工程师技术路线(含博客网址导航)
  • JAVAweb学习日记(三)Ajax
  • Android view 基本的绘制流程
  • 记录Linux Centos 7 安装PostgreSQL 16
  • JZ31 栈的压入、弹出序列
  • Windows脚本命令与Linux Bash脚本命令
  • xctf-WEB-新手练习区Exercise area-Writeup
  • 2024年12月一区SCI-加权平均优化算法Weighted average algorithm-附Matlab免费代码
  • BP回归-反向传播(Backpropagation)
  • 【git】配置ssh代理
  • 人工智能与大数据:商贸物流变革的双引擎与挑战应对
  • 软件设计与体系结构
  • 消费企业如何提升主动造血能力?会员精细化运营是关键!
  • 面试知识点汇总_05
  • linux提示结构需要清理
  • nodejs操作达梦数据库的封装
  • 基于YOLOV5+Flask安全帽RTSP视频流实时目标检测
  • 移植 OLLVM 到 Android NDK,Android Studio 中使用 OLLVM
  • 【开源免费】基于SpringBoot+Vue.JS植物健康系统(JAVA毕业设计)