understanding verilog blocking and non-blocking assignments
Post on 01-Jan-2017
283 Views
Preview:
TRANSCRIPT
Understanding Verilog BlockingUnderstanding Verilog Blockingand Nonand Non--blocking Assignmentsblocking Assignments
International CadenceInternational CadenceUser Group ConferenceUser Group Conference
September 11, 1996September 11, 1996
presented bypresented by
Stuart SutherlandStuart SutherlandSutherland HDL ConsultingSutherland HDL Consulting
About the PresenterAbout the Presenter
Stuart Sutherland has over 8 years of experience using Verilog wStuart Sutherland has over 8 years of experience using Verilog with a variety of software tools. He ith a variety of software tools. He holds a BS degree in Computer Science, with an emphasis on Electholds a BS degree in Computer Science, with an emphasis on Electronic Engineering, and has ronic Engineering, and has worked as a design engineer in the defense industry, and as an Aworked as a design engineer in the defense industry, and as an Applications Engineer for Gateway pplications Engineer for Gateway Design Automation (the originator of Verilog) and Cadence DesignDesign Automation (the originator of Verilog) and Cadence Design Systems. Mr. Sutherland has Systems. Mr. Sutherland has been providing Verilog HDL consulting services since 1991. As abeen providing Verilog HDL consulting services since 1991. As a consultant, he has been actively consultant, he has been actively involved in using the Veriloginvolved in using the Verilog langiagelangiage with a many different of software tools for the design ofwith a many different of software tools for the design ofASICsASICs and systems. He is a member of the IEEE 1364 standards committand systems. He is a member of the IEEE 1364 standards committee and has been involved ee and has been involved in the specification and testing of Verilog simulation products in the specification and testing of Verilog simulation products from several EDA vendors, including from several EDA vendors, including the Intergraphthe Intergraph--VeriBest VeriBest VeriBestVeriBest simulator, the Mentorsimulator, the Mentor QuickHDLQuickHDL simulator, and the Frontlinesimulator, and the FrontlineCycleDriveCycleDrive cycle based simulator. In addition to Verilog designcycle based simulator. In addition to Verilog design consutltingconsutlting, Mr. Sutherland , Mr. Sutherland provides expert onprovides expert on--site Verilog training on the Verilog HDL language andsite Verilog training on the Verilog HDL language and ProgramingPrograming Language Language Interface. Mr. Sutherland is the author and publisher of the poInterface. Mr. Sutherland is the author and publisher of the popular pular “Verilog IEEE 1364 Quick “Verilog IEEE 1364 Quick Reference Guide”Reference Guide” and the and the “Verilog IEEE 1364 PLI Quick Reference Guide”“Verilog IEEE 1364 PLI Quick Reference Guide”..
PleasePlease conactconact Mr. Sutherland with any questions about this material!Mr. Sutherland with any questions about this material!
phone: (503) 692phone: (503) 692--08980898fax: (503) 692fax: (503) 692--15121512
ee--mail:mail: stuartstuart@@sutherlandsutherland.com.com
Sutherland HDL ConsultingSutherland HDL ConsultingVerilog Consulting and Training ServicesVerilog Consulting and Training Services
22805 SW 9222805 SW 92ndnd PlacePlaceTualatin, OR 97062 USATualatin, OR 97062 USA
The material in this presentation is copyrighted by Sutherland HThe material in this presentation is copyrighted by Sutherland HDL Consulting, DL Consulting, Tualatin, Oregon. The presentation is printed with permission aTualatin, Oregon. The presentation is printed with permission as part of the s part of the proceedings of the 1996 International Cadence User Group Confereproceedings of the 1996 International Cadence User Group Conference. All rights nce. All rights are reserved. No material from this presentation may be duplicaare reserved. No material from this presentation may be duplicated or transmitted by ted or transmitted by any means or in any form without the express written permission any means or in any form without the express written permission of Sutherland HDL of Sutherland HDL Consulting.Consulting.
copyright noticecopyright notice
Sutherland HDL ConsultingSutherland HDL Consulting22805 SW 9222805 SW 92ndnd
PlacePlaceTualatin, OR 97062 USATualatin, OR 97062 USA
phone: (503) 692phone: (503) 692--08980898fax: (503) 692fax: (503) 692--15121512
ee--mail: info@mail: info@sutherlandsutherland.com.com
©©19961996
44
SutherlandSutherlandSutherlandHHH DDD LLL
ObjectivesObjectivesObjectives
➤➤ The primary objective is to understand:The primary objective is to understand:
What type of hardware is representedWhat type of hardware is representedby blocking and nonby blocking and non--blocking blocking
assignments?assignments?
➤➤ The material presented is a subset of an advanced Verilog The material presented is a subset of an advanced Verilog HDL training courseHDL training course
55
SutherlandSutherlandSutherlandHHH DDD LLL
Procedural AssignmentsProcedural AssignmentsProcedural Assignments
➤➤ Procedural assignment evaluation can be modeled as:Procedural assignment evaluation can be modeled as:➤➤ BlockingBlocking➤➤ NonNon--blockingblocking
➤➤ Procedural assignment execution can be modeled as:Procedural assignment execution can be modeled as:➤➤ SequentialSequential➤➤ ConcurrentConcurrent
➤➤ Procedural assignment timing controls can be modeled as:Procedural assignment timing controls can be modeled as:➤➤ Delayed evaluationsDelayed evaluations➤➤ Delayed assignmentsDelayed assignments
66
SutherlandSutherlandSutherlandHHH DDD LLL
Blocking Procedural AssignmentsBlocking Blocking Procedural AssignmentsProcedural Assignments
➤➤ The The == token represents a token represents a blockingblocking procedural assignmentprocedural assignment➤➤ Evaluated and assigned in a single stepEvaluated and assigned in a single step➤➤ Execution flow within the procedure is blocked until the Execution flow within the procedure is blocked until the
assignment is completedassignment is completed➤➤ Evaluations of concurrent statements in the same time step Evaluations of concurrent statements in the same time step
are blocked until the assignment is completedare blocked until the assignment is completedThese examples will These examples will notnot work work Why not?Why not?
//swap bytes in wordalways @(posedge clk)
beginword[15:8] = word[ 7:0];word[ 7:0] = word[15:8];
end
//swap bytes in wordalways @(posedge clk)
beginword[15:8] = word[ 7:0];word[ 7:0] = word[15:8];
end
//swap bytes in wordalways @(posedge clk)
forkword[15:8] = word[ 7:0];word[ 7:0] = word[15:8];
join
//swap bytes in wordalways @(posedge clk)
forkword[15:8] = word[ 7:0];word[ 7:0] = word[15:8];
join
77
SutherlandSutherlandSutherlandHHH DDD LLL
Non-Blocking Procedural AssignmentsNonNon--Blocking Blocking Procedural AssignmentsProcedural Assignments
➤➤ The The <=<= token represents a token represents a nonnon--blockingblocking assignmentassignment➤➤ Evaluated and assigned in two steps:Evaluated and assigned in two steps:①① The rightThe right--hand side is evaluated immediatelyhand side is evaluated immediately②② The assignment to the leftThe assignment to the left--hand side is postponed until hand side is postponed until
other evaluations in the current time step are completedother evaluations in the current time step are completed➤➤ Execution flow within the procedure continues until a Execution flow within the procedure continues until a
timing control is encountered (flow is not blocked) timing control is encountered (flow is not blocked) These examples will work These examples will work Why?Why?
//swap bytes in wordalways @(posedge clk)beginword[15:8] <= word[ 7:0];word[ 7:0] <= word[15:8];
end
//swap bytes in wordalways @(posedge clk)beginword[15:8] <= word[ 7:0];word[ 7:0] <= word[15:8];
end
//swap bytes in wordalways @(posedge clk)forkword[15:8] <= word[ 7:0];word[ 7:0] <= word[15:8];
join
//swap bytes in wordalways @(posedge clk)forkword[15:8] <= word[ 7:0];word[ 7:0] <= word[15:8];
join
88
SutherlandSutherlandSutherlandHHH DDD LLL
Representing Simulation Time as QueuesRepresenting Representing Simulation Time as QueuesSimulation Time as Queues
➤➤ Each Verilog simulation time step is divided into 4 queuesEach Verilog simulation time step is divided into 4 queues
Note: this is an abstract view, not how simulation algorithms arNote: this is an abstract view, not how simulation algorithms are implementede implemented
Time 0:➤ Q1 — (in any order) :
➤ Evaluate RHS of all non-blocking assignments➤ Evaluate RHS and change LHS of all blocking assignments➤ Evaluate RHS and change LHS of all continuous assignments➤ Evaluate inputs and change outputs of all primitives➤ Evaluate and print output from $display and $write
➤ Q2 — (in any order) :➤ Change LHS of all non-blocking assignments
➤ Q3 — (in any order) :➤ Evaluate and print output from $monitor and $strobe➤ Call PLI with reason_synchronize
➤ Q4 :➤ Call PLI with reason_rosynchronize
Time 1:...
Time 0:➤ Q1 — (in any order) :
➤ Evaluate RHS of all non-blocking assignments➤ Evaluate RHS and change LHS of all blocking assignments➤ Evaluate RHS and change LHS of all continuous assignments➤ Evaluate inputs and change outputs of all primitives➤ Evaluate and print output from $display and $write
➤ Q2 — (in any order) :➤ Change LHS of all non-blocking assignments
➤ Q3 — (in any order) :➤ Evaluate and print output from $monitor and $strobe➤ Call PLI with reason_synchronize
➤ Q4 :➤ Call PLI with reason_rosynchronize
Time 1:...
99
SutherlandSutherlandSutherlandHHH DDD LLL
SequentialProcedural AssignmentsSequentialSequentialProcedural AssignmentsProcedural Assignments
➤➤ The order of evaluation is The order of evaluation is determinatedeterminate➤➤ A A sequential blocking assignmentsequential blocking assignment evaluates and assigns evaluates and assigns
before continuing on in the procedurebefore continuing on in the procedurealways @(always @(posedge clkposedge clk))beginbegin
A A == 1;1;#5 B #5 B == A + 1;A + 1;
endend
evaluate and assign A immediatelyevaluate and assign A immediatelydelay 5 time units, then evaluate and assigndelay 5 time units, then evaluate and assign
➤➤ A A sequential nonsequential non--blocking assignmentblocking assignment evaluates, then evaluates, then continues on to the next timing control before assigningcontinues on to the next timing control before assigning
always @(always @(posedge clkposedge clk))beginbegin
A A <=<= 1;1;#5 B #5 B <=<= A + 1;A + 1;
endend
evaluate A immediately; assign at end of time stepevaluate A immediately; assign at end of time stepdelay 5 time units, then evaluate; then assign at delay 5 time units, then evaluate; then assign at end of time step (clock + 5)end of time step (clock + 5)
1010
SutherlandSutherlandSutherlandHHH DDD LLL
ConcurrentProcedural AssignmentsConcurrentConcurrentProcedural AssignmentsProcedural Assignments
The order of concurrent evaluation is The order of concurrent evaluation is indeterminateindeterminate➤➤ Concurrent Concurrent blocking assignmentsblocking assignments have have unpredictable resultsunpredictable results
always @(always @(posedge clkposedge clk))#5 A #5 A == A + 1;A + 1;
always @(always @(posedge clkposedge clk))#5 B #5 B == A + 1;A + 1;
Unpredictable Result:Unpredictable Result:(new value of(new value of BB could be evaluated beforecould be evaluated beforeor afteror after AA changes)changes)
➤➤ Concurrent Concurrent nonnon--blocking assignmentsblocking assignments have have predictable resultspredictable results
always @(always @(posedge clkposedge clk))#5 A #5 A <=<= A + 1;A + 1;
always @(always @(posedge clkposedge clk))#5 B #5 B <=<= A + 1;A + 1;
Predictable Result:Predictable Result:(new value of(new value of BB will always be evaluated will always be evaluated beforebefore AA changes)changes)
1111
SutherlandSutherlandSutherlandHHH DDD LLL
Delayed Evaluation Procedural AssignmentsDelayed Evaluation Delayed Evaluation Procedural AssignmentsProcedural Assignments
➤➤ A timing control before an assignment statement will postpone A timing control before an assignment statement will postpone when the next assignment is evaluatedwhen the next assignment is evaluated➤➤ Evaluation is delayed for the amount of time specifiedEvaluation is delayed for the amount of time specified
beginbegin#5#5 A A == 1;1;#5 #5 A A == A + 1;A + 1;
B B == A + 1;A + 1;endend
delay for 5, then evaluate and assigndelay for 5, then evaluate and assigndelay 5 more, then evaluate and assigndelay 5 more, then evaluate and assignno delay; evaluate and assign no delay; evaluate and assign
What values do A and B contain after 10 time units?What values do A and B contain after 10 time units?
1212
SutherlandSutherlandSutherlandHHH DDD LLL
Delayed AssignmentProcedural AssignmentsDelayed AssignmentDelayed AssignmentProcedural AssignmentsProcedural Assignments
➤➤ An An intraintra--assignment delayassignment delay places the timing control places the timing control afterafter the the assignment tokenassignment token➤➤ The rightThe right--hand side is evaluated before the delay hand side is evaluated before the delay ➤➤ The leftThe left--hand side is assigned after the delayhand side is assigned after the delay
always @(A)always @(A)BB == #5#5 A;A;
AA is evaluated at the time it changes, but is evaluated at the time it changes, but is not assigned to is not assigned to BB until after 5 time unitsuntil after 5 time units
always @(always @(negedge clknegedge clk))Q Q <=<= @(@(posedge clkposedge clk)) D;D;
DD is evaluated at the negative edge of is evaluated at the negative edge of CLKCLK,,QQ is changed on the positive edge of is changed on the positive edge of CLKCLK
always @(instructor_input)if (morning)understand = instructor_input;
else if (afternoon)understand = #5 instructor_input;
else if (lunch_time)understand = wait (!lunch_time) instructor_input;
always @(instructor_input)if (morning)understand = instructor_input;
else if (afternoon)understand = #5 instructor_input;
else if (lunch_time)understand = wait (!lunch_time) instructor_input;
1313
SutherlandSutherlandSutherlandHHH DDD LLL
Intra-Assignment Delays With Repeat LoopsIntraIntra--Assignment Delays Assignment Delays With Repeat LoopsWith Repeat Loops
➤➤ An edgeAn edge--sensitive intrasensitive intra--assignment timing control permits a assignment timing control permits a special use of the repeat loopspecial use of the repeat loop➤➤ The edge sensitive time control may be repeated several The edge sensitive time control may be repeated several
times before the delay is completedtimes before the delay is completed➤➤ Either the blocking or the nonEither the blocking or the non--blocking assignment may be blocking assignment may be
usedused
always @(IN)OUT <= repeat (8) @(posedge clk) IN;
always @(IN)OUT <= repeat (8) @(posedge clk) IN;
The value of IN is evaluated when it changes, but isnot assigned to OUT until after 8 clock cycles
1414
SutherlandSutherlandSutherlandHHH DDD LLL
Choosing the Correct Procedural AssignmentChoosing the Choosing the Correct Procedural AssignmentCorrect Procedural Assignment
➤➤ Which procedural assignment should be used to model a Which procedural assignment should be used to model a combinatorial logic buffer?combinatorial logic buffer?
➤➤ Which procedural assignment should be used to model a Which procedural assignment should be used to model a sequential logic flipsequential logic flip--flop?flop?
➤➤ The following pages will answer these questionsThe following pages will answer these questions
always @(in)#5 out = in;
always @(in)#5 out <= in;
always @(in)out = #5 in;
always @(in)out <= #5 in;
always @(posedge clk)#5 q = d;
always @(posedge clk)#5 q <= d;
always @(posedge clk)q = #5 d;
always @(posedge clk)q <= #5 d;
1515
SutherlandSutherlandSutherlandHHH DDD LLL
Transition Propagation MethodsTransition Transition Propagation MethodsPropagation Methods
➤➤ Hardware has two primary propagation delay methods:Hardware has two primary propagation delay methods:➤➤ Inertial delayInertial delay models devices with finite switching speeds; models devices with finite switching speeds;
input glitches do not propagate to the outputinput glitches do not propagate to the output
➤➤ Transport delayTransport delay models devices with near infinite models devices with near infinite switching speeds; input glitches propagate to the output switching speeds; input glitches propagate to the output
20 6050403010 20 6050403010
Buffer with a 10 nanosecond propagation delay
20 6050403010 20 6050403010
Buffer with a 10 nanosecond propagation delay
1616
SutherlandSutherlandSutherlandHHH DDD LLL
Combinational Logic Procedural AssignmentsCombinational Logic Combinational Logic Procedural AssignmentsProcedural Assignments
➤➤ How will these procedural assignments behave?How will these procedural assignments behave?20 6050403010
inin3333 3636 4545
always @(in)always @(in)o1 o1 == in;in;
Blocking,Blocking,No delayNo delay
always @(in)always @(in)o2 o2 <=<= in;in;
NonNon--blocking,blocking,No delayNo delay
always @(in)always @(in)#5#5 o3 o3 == in;in;
Blocking,Blocking,Delayed evaluationDelayed evaluation
o1o1
o2o2
o3o3
o4o4
o5o5
o6o6
always @(in)always @(in)#5#5 o4 o4 <=<= in;in;
NonNon--blocking,blocking,Delayed evaluationDelayed evaluation
always @(in)always @(in)o5 o5 = #5= #5 in;in;
Blocking,Blocking,Delayed assignmentDelayed assignment
always @(in)always @(in)o6 o6 <= #5<= #5 in;in;
NonNon--blocking,blocking,Delayed assignmentDelayed assignment
zero delayzero delay
inertialinertial
transporttransport
1717
SutherlandSutherlandSutherlandHHH DDD LLL
Sequential Logic Procedural AssignmentsSequential Logic Sequential Logic Procedural AssignmentsProcedural Assignments
➤➤ How will these procedural assignments behave?How will these procedural assignments behave?➤➤ Sequential assignmentsSequential assignments➤➤ No delaysNo delays
20 6050403010clk
always @(always @(posedge clkposedge clk))beginbegin
y1 y1 == in;in;y2 y2 == y1;y1;
endend
always @(always @(posedge clkposedge clk))beginbegin
y1 y1 <=<= in;in;y2 y2 <=<= y1;y1;
endend
in35 53
y2
y1
y1
y2
y2y1
parallel flipparallel flip--flopsflops
y1
y2
shiftshift--register with zero delaysregister with zero delays
1818
SutherlandSutherlandSutherlandHHH DDD LLL
Sequential Logic Procedural AssignmentsSequential Logic Sequential Logic Procedural AssignmentsProcedural Assignments
➤➤ How will these procedural assignments behave?How will these procedural assignments behave?➤➤ Sequential assignmentsSequential assignments➤➤ Delayed evaluationDelayed evaluation
20 6050403010clk
always @(always @(posedge clkposedge clk))beginbegin#5#5 y1 y1 == in;in;#5#5 y2 y2 == y1;y1;
endend
always @(always @(posedge clkposedge clk))beginbegin#5#5 y1 y1 <=<= in;in;#5#5 y2 y2 <=<= y1;y1;
endend
in35 53
y2
y1
y1
y2
? ? ?
? ? ?
y1
y2
#5#5
shift register with delayed clocksshift register with delayed clocks
? ? ?
? ? ?
y1
y2
#5#5
shift register with delayed clocksshift register with delayed clocks
1919
SutherlandSutherlandSutherlandHHH DDD LLL
Sequential Logic Procedural AssignmentsSequential Logic Sequential Logic Procedural AssignmentsProcedural Assignments
➤➤ How will these procedural assignments behave?How will these procedural assignments behave?➤➤ Sequential assignmentsSequential assignments➤➤ Delayed assignmentDelayed assignment
20 6050403010clk
always @(always @(posedge clkposedge clk))beginbegin
y1 y1 = #5= #5 in;in;y2 y2 = #5= #5 y1;y1;
endend
always @(always @(posedge clkposedge clk))beginbegin
y1 y1 <= #5<= #5 in;in;y2 y2 <= #5<= #5 y1;y1;
endend
y1
y2
y1
y2
in35 53
shift register delayed clock on second stageshift register delayed clock on second stage
y1
y2
#5
#5 #5
y1
y2#5 #5
shift register with delaysshift register with delays
2020
SutherlandSutherlandSutherlandHHH DDD LLL
Sequential Logic Procedural AssignmentsSequential Logic Sequential Logic Procedural AssignmentsProcedural Assignments
➤➤ How will these procedural assignments behave?How will these procedural assignments behave?➤➤ Concurrent assignmentsConcurrent assignments➤➤ No delaysNo delays
y1
y2
20 6050403010clk
always @(always @(posedge clkposedge clk))y1 y1 == in;in;
always @(always @(posedge clkposedge clk))y2 y2 == y1;y1;
y1
y2
always @(always @(posedge clkposedge clk))y1 y1 <=<= in;in;
always @(always @(posedge clkposedge clk))y2 y2 <=<= y1;y1;
in35 53
? ? ? ? ? ? ? ?
y1
y2?
shift register with race conditionshift register with race condition
y1
y2
shiftshift--register with zero delaysregister with zero delays
2121
SutherlandSutherlandSutherlandHHH DDD LLL
y2
y1
Sequential Logic Procedural AssignmentsSequential Logic Sequential Logic Procedural AssignmentsProcedural Assignments
➤➤ How will these procedural assignments behave?How will these procedural assignments behave?➤➤ Concurrent assignmentsConcurrent assignments➤➤ Delayed evaluationDelayed evaluation
20 6050403010clk
always @(always @(posedge clkposedge clk))#5#5 y1 y1 == in;in;
always @(always @(posedge clkposedge clk))#5#5 y2 y2 == y1;y1;
always @(always @(posedge clkposedge clk))#5#5 y1 y1 <=<= in;in;
always @(always @(posedge clkposedge clk))#5#5 y2 y2 <=<= y1;y1;
in35 53
y1
y2 ? ? ?
? ? ?
? ? ? ?shift register with race conditionshift register with race condition
y1
y2?
#5#5
? ? ?
?
y1
y2
#5shift register with race conditionshift register with race condition
2222
SutherlandSutherlandSutherlandHHH DDD LLL
Sequential Logic Procedural AssignmentsSequential Logic Sequential Logic Procedural AssignmentsProcedural Assignments
➤➤ How will these procedural assignments behave?How will these procedural assignments behave?➤➤ Concurrent assignmentsConcurrent assignments➤➤ Delayed assignmentDelayed assignment
20 6050403010clk
always @(always @(posedge clkposedge clk))y1 y1 = #5= #5 in;in;
always @(always @(posedge clkposedge clk))y2 y2 = #5 = #5 y1;y1;
always @(always @(posedge clkposedge clk))y1y1 <= #5<= #5 in;in;
always @(always @(posedge clkposedge clk))y2 y2 <= #5<= #5 y1;y1;
in35 53
y1
y2
y1
y2
y1
y2#5 #5
shift register, delay must be < clock periodshift register, delay must be < clock period
y1
y2#5 #5
shift register with delaysshift register with delays
2323
SutherlandSutherlandSutherlandHHH DDD LLL
Rules of Thumb forProcedural AssignmentsRules of Thumb forRules of Thumb forProcedural AssignmentsProcedural Assignments
➤➤ Combinational Logic:Combinational Logic:➤➤ No delays:No delays: Use blocking assignments ( Use blocking assignments ( a = b;a = b; ))➤➤ Inertial delays:Inertial delays: Use delayed evaluation blocking Use delayed evaluation blocking
assignments ( assignments ( #5 a = b;#5 a = b; ))
➤➤ Transport delays:Transport delays: Use delayed assignment nonUse delayed assignment non--blocking blocking assignments ( assignments ( a <= #5 b;a <= #5 b; ))
➤➤ Sequential Logic:Sequential Logic:➤➤ No delays:No delays: Use nonUse non--blocking assignments ( blocking assignments ( q <= d;q <= d; ))➤➤ With delays:With delays: Use delayed assignment nonUse delayed assignment non--blocking blocking
assignments ( assignments ( q <= #5 d;q <= #5 d; ))
2424
SutherlandSutherlandSutherlandHHH DDD LLL
An Exception to Non-blocking Assignments in Sequential LogicAn Exception to NonAn Exception to Non--blocking blocking Assignments in Sequential LogicAssignments in Sequential Logic
➤➤ Do Do not not use a nonuse a non--blocking assignment if another statement in blocking assignment if another statement in the procedure requires the new value in the same time stepthe procedure requires the new value in the same time step
begin#5 A <= 1;#5 A <= A + 1;
B <= A + 1;end
What values do A and B contain after 10 time units?What values do A and B contain after 10 time units?
always @(posedge clk)begin
case (state)`STOP: next_state <= `GO;`GO: next_state <= `STOP;endcasestate <= next_state;
end
Assume state and next_stateare `STOP at the first clock, what is state:
- At the 2nd clock? - At the 3rd clock?- At the 4th clock?- At the 5th clock?
Assume state and next_stateare `STOP at the first clock, what is state:
- At the 2nd clock? - At the 3rd clock?- At the 4th clock?- At the 5th clock?
A is 2A is 2 B is 2B is 2
`STOP`STOP`GO`GO`GO`GO`STOP`STOP
2525
SutherlandSutherlandSutherlandHHH DDD LLL
Exercise 3: Procedural AssignmentsExercise 3: Exercise 3: Procedural AssignmentsProcedural Assignments
➤➤ Write a procedure for an adder (combinational logic) that Write a procedure for an adder (combinational logic) that assigns C the sum of A plus B with a 7ns propagation delay.assigns C the sum of A plus B with a 7ns propagation delay.
➤➤ Write the procedure(s) for a 4Write the procedure(s) for a 4--bit wide shift register (positive bit wide shift register (positive edge triggered) of clock and has a 4ns propagation delay.edge triggered) of clock and has a 4ns propagation delay.
always @(A or B)#7 C = A + B;
always @(A or B)#7 C = A + B;
always @(posedge clk)begin
y1 <= #4 in;y2 <= #4 y1;y3 <= #4 y2;out <= #4 y3;
end
always @(posedge clk)begin
y1 <= #4 in;y2 <= #4 y1;y3 <= #4 y2;out <= #4 y3;
end
always @(posedge clk)y1 <= #4 in;
always @(posedge clk)y2 <= #4 y1;
always @(posedge clk)y3 <= #4 y2;
always @(posedge clk)out <= #4 y3;
always @(posedge clk)y1 <= #4 in;
always @(posedge clk)y2 <= #4 y1;
always @(posedge clk)y3 <= #4 y2;
always @(posedge clk)out <= #4 y3;
2626
SutherlandSutherlandSutherlandHHH DDD LLL
Exercise 3 (continued): Procedural AssignmentsExercise 3 (continued): Exercise 3 (continued): Procedural AssignmentsProcedural Assignments
➤➤ Write a Verilog procedure for a “black box” ALU pipeline that Write a Verilog procedure for a “black box” ALU pipeline that takes 8 clock cycles to execute an instruction. The pipeline takes 8 clock cycles to execute an instruction. The pipeline triggers on the positive edge of clock. The “black box” is triggers on the positive edge of clock. The “black box” is represented as call to a function named ALU with inputs A, B represented as call to a function named ALU with inputs A, B and OPCODE.and OPCODE.
always @(posedge clk)alu_out <= repeat(7) @(posedge clk) ALU(A,B,OPCODE);
always @(posedge clk)alu_out <= repeat(7) @(posedge clk) ALU(A,B,OPCODE);
How many Verilog statements does ittake to model aneight stage pipeline?
top related