Lab 5
Lab 5
Assignments
Continuous assignment:
➢ Continuous assignments continuously monitor the RHS (right – hand side) and update the LHS (left –
hand side) immediately when the RHS change, does not introduce any timing delays.
➢ Multiple continuous assignment executes concurrently, order of statements is not important.
➢ Used outside always statement to design simple combinational circuit.
➢ Syntax: assign a = b;
Blocking assignment:
➢ Cause the RHS expression to be evaluated immediately, and the LHS variable is updated before
moving to the next statement.
➢ Multiple blocking assignments are executed sequentially in the order they appear in the code, order
of statements is important.
➢ Used inside always statement to design combinational circuit.
➢ Syntax: a = b;
Non – blocking assignment:
➢ Updating for the variables on the LHS occur at the end of current time step, typically on a clock edge.
➢ Multiple non-blocking assignments executes concurrently, order of statements is not important.
➢ Used inside always statement to design more complex sequential circuit.
➢ Syntax: a <= b;
Compare between types of assignments
Continous Blocking Non-blocking
assignment assignment assignment
Update LHS to RHS Immediately Immediately At the end of
current time step,
typically on a clock
edge
Order of execution Concurrently In order Concurrently
statements
Using to design Simple Combinational Sequential circuit
combinational circuit
circuit
Inside or outside Outside Inside Inside
always
Update Đồng bộ theo cạnh clock Không đồng bộ, hoạt động theo
tín hiệu enable
Syntax always_ff @(posedge clk) hoặc always_latch
@(negedge clk)
Using to design Dùng cho các mạch đồng bộ Dùng cho các mạch không đồng
bộ
State change Thay đổi tại cạnh xung clock Thay đổi bất kỳ khi nào có enable
Applications Thanh ghi, bộ đếm, mạch trạng thái Mạch giữ dữ liệu, các mạch điều
khiển giữ trạng thái
Common used statement
for while
for (initialization; condition; increment) begin while (condition) begin
// Loop body // Statements to execute while the condition is true
end end
if – else case
if (condition) begin case (expression)
// Statements to execute when the condition is true value1: begin
end // Code for when expression matches value1
else begin end
// Statements to execute when the condition is false value2: begin
end // Code for when expression matches value2
end
// More value cases...
default: begin
// Code for when no value case matches the expression
end
endcase
D flipflop
Design D flip flop using always_ff and non-blocking assignment.
D flipflop truth table
clk d q
1 1
0 0
initial begin
clk = 0;
d = 0;
end
endmodule
D- flipflop simulation result
Pin assignments
D flipflop
Ex1: Design an D flipflop having following truth table using in SystemVerilog and simulate on
ModelSim.
S-R flipflop
Ex2: Design an S-R flipflop having following truth table using in SystemVerilog and simulate on
ModelSim.
JK flipflop
Ex3: Design an JK flipflop having following truth table using in SystemVerilog and simulate on
ModelSim.
S-R latch
Ex4: Design an S-R latch having following truth table using in SystemVerilog and simulate on
ModelSim.
0 X Keep_state Keep_state
1 0 0 1
1 1 1 0
D latch
Ex5: Design an D latch having following truth table using in SystemVerilog and simulate on
ModelSim.