description:example of a one-bit full add
- module FULLADDR(Cout,Sun,Ain,Bin,Cin);
- input Ain,Bin,Cin;
- output Sun,Cout;
-
- wire Sum;
- wire Count;
- assign Sum=Ain^Bin^Cin;
- assign Cout=(Ain&Bin)|(Bin&Cin)|(Ain&Cin);
- endmodule
description::example of a mux4-1
- module MUX(C,D,E,F,S,Mux_out);
- input C,D,E,F,; //input
- input [1:0] s; //select control
- output Mux_out; //result
-
- reg Mux_out; //mux
- always@(C or D or E or F or S)
- begin
- case(S)
- 2`b00:Mux_out=C;
- 2`b01:Mux_out=D;
- 2`b10:Mux_out=f;
- default:Mux_out=S;
- endcase
- end
- endmodule
description:example of 3-8decoder
- module DECODE(Ain,En,Yout);
- input En; //input
- input [2:0] Ain; //input code
- output [7:0] Yout;
-
- reg [7:0] Yout;
- always@(En or Ain)
- begin
- if(!En)
- Yout=8`0;
- else
- case(Ain)
- 3`b000:Yout=8`b0000_0001;
- 3`b001:Yout=8`b0000_0010;
- 3`b010:Yout=8`b0000_0100;
- 3`b011:Yout=8`b0000_1000;
- 3`b100:Yout=8`b0001_0000;
- 3`b101:Yout=8`b0010_0000;
- 3`b110:Yout=8`b0100_0000;
- 3`b111:Yout=8`b1000_0000;
- default:Yout=8`b0000_0000;
- endcase
- end
- endmodule
description:example of Priority encoder
- module PRIO_ENCODE(Cin,Din,Ein,Fin,Sin,Pout);
- input Cin,Din,Ein,Fin; //input signals
- input [1:0] Sin; //input select contorl
-
- output Pout; //output select result
-
- reg Pout; //Pout assignment
- always@(Sin or Cin or Din or Ein or Fin)
- begin
- if(Sin==2`b00)
- Pout=Cin;
- else if(Sin==2`b01)
- Pout=Din;
- else if(Sin==2`b10)
- Pout=Ein;
- else
- Pout=Fin;
- end
- endmodule //module prio_encode
description:example of a counter with enable
- module COUNT_EN(En,Clock,Reset,Out);
- parameter Width =8;
- parameter U_DLY=1;
- input Clock,Reset,En;
- output [Width-1:0] Out;
-
- reg [Width-1:0] Out;
- always@(posedge Clock or negedge Reset)
- if(!Reset)
- Out<=8`b0;
- else if(En)
- Out<=#U_DLY Out+1;
- endmodule
description:example of a arithmetic include +-*/
- module ARITHMETIC(A,B,Q1,Q2,Q3,Q4);
- input [3:0] A,B; //input opeartor
- output [4:0] Q1; //output sum,with carry bit
- output [3:0] Q2; //output sutract result
- output [3:0] Q3; //output quotion
- output [7:0] Q4; //product
-
- reg [4:0] Q1;
- reg [3:0] Q2,Q3;
- reg [7:0] Q4; //arithmetic operate
-
- always@(A or B)
- begin
- Q1=A+B;
- Q2=A-B;
- Q3=A/2;
- Q4=A*B;
- end
- endmodule
description:example of a relational operate
- module RELATIONAL(A,B,Q1,Q2,Q3,Q4);
- input [3:0] A,b; //operator
- output Q1,Q2,Q3,Q4; //result
-
- reg Q1,Q2,Q3,Q4; //compare
-
- always@(A or B)
- begin
- Q1=A>B;
- Q2=A
- Q3=A>=B;
- if(A<=B)
- Q4=1;
- else
- Q4=0;
- end
- endmodule
1.6 移位操作
description:example of a shifter
- module SHIFT(Data,Q1,Q2);
- input [3:0] Data;
- output [3:0] Q1,Q2;
-
- parameter B=2;
- reg [3:0] Q1,Q2;
-
- always@(Data)
- bagin
- Q1=Data<
- Q2=Data>>B;
- end
- endmodule
1.7 时序器件
一个时序器件(指触发器或锁存器)就是一个一位存储器。锁存器是电平敏感存储器件,触发器是沿触发存储器件。
触发器也称寄存器,在程序中体现为对上升沿或下降沿的探测,Verilog中如下方式表示
(posedge Clk)——————上升沿
(negedge Clk)——————下降沿
下面给出不同类型触发器的描述
1.7.1 上升沿触发的触发器
description:example of a rising flip-flop
- module DFF(Data, Clk,Q);
- input Data,Clk;
- output Q;
-
- reg Q;
-
- always@(posedge Clk)
- Q <= Data;
- endmodule
1.7.2 带异步复位,上升沿触发的触发器
description:example of a rising edge flip-flop with asynchronous reset
- module DFF_ASYNC_RST(Data,Clk,Rest,Q);
- input Data,Clk,Reset;
- output Q;
-
- parameter U_DLY=1;
-
- reg Q;
-
- always@(posedge Clk or negedge Reset)
- if(~Reset)
- Q <= #U_DLY 1`b0;
- else
- Q <= #U_DLY Data;
- endmodule
1.7.3 带异步置位,上升沿触发的触发器
description:example of a rising edge flip-flop with asynchronous preset
- module DFF_ASYNC_PRE(Data,Clk,Preset,Q);
- input Data,Clk,Preset;
- output Q;
- parameter U_DLY=1;
- reg Q;
- always@(posedge Clk or negedge Preset)
- if(~Prest)
- Q <= #U-DLY 1`b1;
- else
- Q <= #U_CLY Data;
- endmodule
1.7.4 带异步复位和置位,上升沿触发的触发器
description:example of a rising edge flip-flop with asynchronous reset and preset
- module DFF_ASYNC(Data,Clk,Reset,Prest,Q);
- input Data,Clk,Reset,Preset;
- output Q;
- parameter U_DLY=1;
-
- reg Q;
-
- always@(posedge Clk or negedge Reset or posedge Preset)
- if(~Reset)
- Q <= 1`b0;
- else if(Preset)
- Q <= 1`b1;
- else
- Q <= #U_DLY Data;
- endmodule
1.7.5 带同步复位,上升沿触发的触发器
description:example of a rising edge flip-flop with synchronous reset
- module DFF_SYNC_RST(Data,Clk,Reset,Q);
- input Data,ClK,Reset;
- output Q;
- parameter U_DLY=1;
- reg Q;
- always@(posedge Clk)
- if(~Reset)
- Q <= #U_DLY 1`b0;
- else
- Q <= #U_DLY Data;
- endmodule
1.7.6 带同步置位,上升沿触发的触发器
description:example of a rising edge Flip-Flop with synchronous preset
- module DFF_SYNC_PRE(Data,Clk,Preset,Q);
- input Data,Clk,Preset;
- output Q;
- parameter U_DLY=1;
- reg Q;
- always@(posedge Clk)
- if(~Preset)
- Q <= #U_DLY 1`b1;
- else
- Q <= #U_DLY Data
- endmodule
1.7.7 带异步复位和时钟使能,上升沿触发的触发器
description:example of a Rising Edge Flip-Flop with Asynchronous Reset
- module DFF_CK_EN(Data,Clk,Reset,En,Q);
- input Data,Clk,Reset,En;
- output Q;
- parameter U_DLY=1;
- reg Q;
-
- always@(posedge Clk or negedge Reset)
- if(~Reset)
- Q <= 1`b0;
- else if(En)
- Q <= #U_DLY Data;
- endmodule
1.8 ALU
description:example of a 4-bit Carry Look Ahead ALU
- module ALU(A,B,Cin,Sum,Cout,Operate,Mode); //input signals
- input [3:0] A,b; //two operands of ALU
- input Cin; //carry in at the LSB
- input [3:0] Operate; //determine f(.) of sum=f(a,b)
- input Mode; //arithmetic(Mode=1`b1) or logic operation(Mode=1`b0)
- output [3:0] Sum; //result of ALU
- output Cout; //carry produced by ALU operation
-
- //carry generation bits and propogation bits.
- wire [3:0] G,P;
-
- //carry bits ;
- reg [2:0] C;
-
- //funtion for carry generation:
- function gen
- input A,B;
- input [1:0] Oper;
-
- begin
- case(Oper)
- 2`b00:gen=A;
- 2`b01:gen=A&B;
- 2`b10:gen=A&(~B);
- 2`b11:gen=1`b0;
- endcase
- end
- endfunction
-
- //function for carry propergation:
- function prop
- input A,B;
- input [1:0] Oper;
- begin
- case(Oper)
- 2`b00:prop=1;
- 2`b01:prop=A|(~B);
- 2`b10:prop=A|B;
- 2`b11:prop=A;
- endcase
- end
- endfunction
-
- //producing carry generation bits;
- assign G[0]=gen(A[0],B[0],Oper[1:0]);
- assign G[1]=gen(A[1],B[1],Oper[1:0]);
- assign G[2]=gen(A[2],B[2],Oper[1:0]);
- assign G[3]=gen(A[3],B[2],Oper[1:0]);
-
- //producing carry propogation bits
- assign P[0]=pro(A[0],B[0],Oper[3:2]);
- assign P[1]=Pro(A[1],B[1],Oper[3:2]);
- assign P[2]=Pro(A[2],B[2],Oper[3:2]);
- assign P[3]=Pro(A[3],B[3],Oper[3:2]);
-
- //producing carry bits with carry-look -ahead;
- always@(G or P or Cin,Mode)
- begin
- if(Mode)begin
- C[0]=G[0]|P[0] & Cin;
- C[1]=G[1]|P[1] & G[0]|P[1] & P[0] & Cin;
- C[2]=G[2]|P[2] & G[1]|P[2] & P[1] & G[0]|P[2] & P[1] & P[0] & Cin;
- Cout=G[3]|P[3] & G[2]|P[3] & P[2] & G[1]|P[3] & P[2] & P[1] & G[0]|P[3] & P[2] & P[1] & P[0] & Cin;
- end
- elsebegin
- C[0]=1`b0;
- C[1]=1`b0;
- C[2]=1`b0;
- Cout=1`b0;
- end
- end
-
- //calculate the operation results;
- assign Sum[0]=(~G[0]&P[0])^Cin;
- assign Sum[1]=(~G[1]&P[1])^C[0];
- assign Sum[2]=(~G[2]&P[2])^C[1];
- assign Sum[3]=(~G[3]&P[3])^C[2];
- endmodule
-
相关阅读:
数据结构-单链表
easyexcel导入导出百万条数据思路分析
MySQL定期删除旧数据的过程和事件
酷开系统更多惊喜,尽享畅快观影之旅
Git常用指令(基础)
尚硅谷Vue系列教程学习笔记(3)
C++总结(8):STL容器适配器之stack、queue、priority_queue详解
【Vue】使用单文件组件编写 TodoList
vue实现列表数据分页
面试20个人居然没有一个写出数组扁平化?如何手写flat函数
-
原文地址:https://blog.csdn.net/m0_61687959/article/details/125806542