Introduction To Design With Verilog 3.4 Exercises: Dr. Paul D. Franzon
Introduction To Design With Verilog 3.4 Exercises: Dr. Paul D. Franzon
D Compare G
always@(A or B or C)
begin Why not move E, F assignments
if (A>B) then E = A; else E = B; down to here?
if (C>E) then F = C; else F = E;
end
always@(posedge clock) E, F would now be outputs
if (D>F) then G <= D; else G <=F; of flip-flops.
D Compare F
assign E = (A>B) ? A : B;
assign F = (C>D) ? C : D;
always@(posedge clock)
if (E>F) then G <= E; else G <=F;
Sample Problem
Accumulator:
Design an 8-bit adder accumulator with the following properties:
While ‘accumulate’ is high, adds the input, ‘in1’ to the current accumulated total and
add the result to the contents of register with output ‘accum_out’.
use absolute (not 2’s complement) numbers
When ‘clear’ is high (‘accumulate’ will be low) clear the contents of the register with
output ‘accum_out’
The ‘overflow’ flag is high is the adder overflows
Hint:
8-bit adder produces a 9-bit result:
{carry_out, sum} = A+B;
Sketch Design
1. Determine and name registers.
2. Determine combinational logic
3. Hand generate a timing diagram to verify
Clear
accumulate
0
accum_out
accum_in
in1 +
overflow
Code Verilog
module accum (clock, accumulate, clear, in1, accum_out, overflow);
always@(posedge clock)
begin
if (clear) accum_out <= 8'b0;
else if (accumulate) accum_out <= accum_in;
end
endmodule /* counter */