1.半加器

1.定义

两个一位数的相加,称为半加器。

2.真值表

x为第一个加数,y为第二个加数,c为进位,s为x+y右边一位和。

x       y       c         s 


0       0       0         0

0       1       0         1

1       0       0         1

1       1       1         0 

3.逻辑表达式

c=xy                与门

s=\bar{x}y+\bar{y} x       异或

4.verilog 程序

4.1 数据流描述方式

module add_half(

input x,

input y,

output c,

output s

):

assign c=x&y;

assign s=x^y;

endmodule


4.2 门级描述方式

module add_half(

input x,

input y,

output c,

output s

);

and(c,x,y);

xor(s,x,y);

endmodule

4.3 行为描述方式

module  add_half(

input x,

input y,

output c,

output s

);

always@(a or b)

begin 

case({a,b})

2'b00:begin s=0;c=0; end

2'b01:begin s=1;c=0; end

2'b10:begin s=1;c=0; end

2'b11:begin s=0;c=1; end

endcase

end 

5.RTL 逻辑图


5.1 逻辑图

6.仿真 

6.1 testbench

`timescale 1ns / 1ps

module sim_add_half(

    );

    reg x,y;

    reg clk;

    wire s,c;

initial#初始化数据

    begin

        #1

        x=0;

        y=0;

        clk=0;

    end

always #5 clk=~clk;

always@(posedge clk)

    begin

    x={$random}%2;

    y={$random}%2;

    end

add_half u1(x,y,c,s); #调用原文件

endmodule

6.2 仿真图


6.1 仿真图
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容