1. Normally never use for loops in your hardware verilog—only in verilog used for test code.
2. When using for loops, watch out if you use a register as a loop counter and you want the loop to count through all possible values. In the example below, the 4-bit number can never exceed 15 and the loop will run indefinitely.
reg [3:0] in_a; for (in_a=0; in_a<=15; in_a=in_a+1) begin ... endIt's generally better to use an integer as a loop counter.
reg signed [7:0] input1, input2;$write() prints negative numbers only when variable is signed.
Don't set the same register in more than one always block--the resulting operation can be ambiguous and if you synthesize the code, the tool will give you an error.
Use lots of $write, $display, or $monitor statements to print out wires, registers, and other variables.
Verify the inputs are as you expect and then work a stage/level at a time until you get to the outputs. When you find an error, focus 100% on fixing the first one you find before moving on.
2018/02/16 Minor changes. Emphasize no for loops in hardware verilog.