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:

沒有留言:

張貼留言

Node-Red 抓取 opendata 的資料集產生AQI 空氣品質指

Node-Red 抓取 opendata 的資料集產生AQI 空氣品質指標 實現透過 Node-RED 抓取環境部 OpenData(空氣品質 AQI)資料,最核心的流程為: 注入觸發(Inject) → HTTP 請求(http request) → 解析 JSON 資料(Fu...