2020年3月31日 星期二

Half Adder Behavioral Model using If-Else Statement in Verilog

Half Adder Behavioral Model using If-Else Statement in Verilog



Code:

module halfadder4(input x, y, output reg s, c);

always@(x or y)
begin

if (x == 0 && y == 0)
begin
s = 0;
c = 0;
end

else if (x == 1 && y == 1)
begin
s = 0;
c = 1;
end

else
begin
s = 1;
c = 0;
end

end

endmodule

Testbench Code:

module half_adder_verilog_tb();

reg x, y;
wire s, c;

halfadder4 dut (.x(x), .y(y), .s(s), .c(c));

initial
begin

x = 1'b0;
y = 1'b0;
#50;

x = 1'b0;
y = 1'b1;
#50;

x = 1'b1;
y = 1'b0;
#50;

x = 1'b1;
y = 1'b1;

end

endmodule

Output:

沒有留言:

張貼留言

MIFARE Classic Command Flow Diagram

MIFARE Classic Command Flow Diagram   這個程式將圖片中的 MIFARE Classic Command Flow Diagram 完整繪製在畫布上(包含中英文對照、虛線錯誤返回路徑、實線流程箭頭以及右側的「典型交易時間」資訊),並提供「上一...