// synthesis verilog_input_version verilog_2001
module top_module (
input do_sub,
input [7:0] a,
input [7:0] b,
output reg [7:0] out,
output reg result_is_zero
);//
always @(*) begin
case (do_sub)
0: out = a+b;
1: out = a-b;
endcase
if (out == 8'd0)
result_is_zero = 1;
else
result_is_zero = 0;
end
endmodule
Bugs case
module top_module (
input [7:0] code,
output reg [3:0] out,
output reg valid );//
always @(*)
begin
out = 0;
valid=1;
case (code)
8'h45: out = 0;
8'h16: out = 1;
8'h1e: out = 2;
8'h26: out = 3;
8'h25: out = 4;
8'h2e: out = 5;
8'h36: out = 6;
8'h3d: out = 7;
8'h3e: out = 8;
8'h46: out = 9;
default: valid = 0;
endcase
end
endmodule
Building a circuit from a simulation waveform
circuit1
module top_module (
input a,
input b,
output q );//
assign q = a & b; // Fix me
endmodule
module top_module (
input clk,
input a,
output reg q );
always @(posedge clk) begin
if (a) begin
q <= 1'b0;
end
else
q <= 1'b1;
end
endmodule
circuit8
module top_module (
input clock,
input a,
output reg p,
output reg q );
always @( *) begin
if (clock) begin
p = a;
end
end
always @(negedge clock) begin
q <= p;
//这是一开始的想法 q <= ~q;
end
endmodule
circuit9
module top_module (
input clk,
input a,
output reg [3:0] q );
always @(posedge clk) begin
if (a) begin
q <= 4'd4;
end
else
begin
if (q == 4'd6) begin
q <= 4'd0;
end
else
q <= q + 1'b1;
end
end
endmodule
circuit10
module top_module (
input clk,
input a,
input b,
output q,
output reg state );
assign q = (a ^ b) ^ state;
always @(posedge clk) begin
if (a==0 && b==0) begin
state <= 1'b0;
end
else if (a==1 && b==1) begin
state <= 1'b1;
end
else
state <= state;
end
endmodule