Skip to content

Instantly share code, notes, and snippets.

@mcandre
Created September 28, 2021 01:43
Show Gist options
  • Save mcandre/13f4ce07ef7248f5641d015d0c9e9b09 to your computer and use it in GitHub Desktop.
Save mcandre/13f4ce07ef7248f5641d015d0c9e9b09 to your computer and use it in GitHub Desktop.
half_adder SystemVerilog
module half_adder(
input clk,
a,
b,
output reg sum,
carry
);
always @(posedge clk)
begin
sum <= a ^ b;
carry <= a & b;
end
endmodule
module test_half_adder;
reg clk = 0;
always #1 clk = !clk;
wire a = 0,
b = 0;
reg sum = 0,
carry = 0;
half_adder ha(clk, a, b, sum, carry);
initial
$monitor(
"Time: %t, clk: %0d, a: %0d, b: %0d, sum: %0d, carry: %0d",
$time,
clk,
a,
b,
sum,
carry
);
endmodule
@mcandre
Copy link
Author

mcandre commented Sep 28, 2021

Basing my source from an iverilog tutorial.

https://iverilog.fandom.com/wiki/Getting_Started

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment