Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
module divisibleby5();
reg [127:0] my_reg;
reg [4:0] bcd_lsb;
reg divisible_by_5;
reg clk;
reg din;
initial begin
clk = 0;
din = $random;
my_reg = 128'h0000000000000000;
bcd_lsb = 0;
divisible_by_5 = 0;
$monitor ("my_reg = %d divisible_by_5 = %b bcd_lsb = %h", my_reg, divisible_by_5, bcd_lsb);
fork
forever #5 clk = ~clk;
forever begin
@(posedge clk);
my_reg = {my_reg[126:0], din};
bcd_lsb = 2*bcd_lsb + din;
if (bcd_lsb > 9 || bcd_lsb[4])
bcd_lsb[4:0] = bcd_lsb[3:0] + 6;
divisible_by_5 = (bcd_lsb[3:0] == 0 || bcd_lsb[3:0] == 5);
din = $random;
end
#1000 $finish;
join
end
endmodule // divisibleby5