Digital Logic RTL & Verilog Interview Questions Preview
Digital Logic RTL & Verilog Interview Questions Preview
m
RTL & Verilog
co
e.
Interview Questions
od
C
og
ril
Ve
VerilogCode.com
VerilogCode.com Page 1
Copyright2015byVerilogCode.com
Allrightsreserved.Thisbookoranyportionthereof
maynotbereproducedorusedinanymannerwhatsoever
withouttheexpresswrittenpermissionofthepublisher
m
exceptfortheuseofbriefquotationsinabookreview.
co
e.
OrderingInformation:
od
Quantitysales.Specialdiscountsareavailableonquantitypurchasesbycorporations,
associations,andothers.OrdersbyU.S.tradebookstoresandwholesalers,pleasevisit:
www.VerilogCode.com
C
og
PrintedintheUnitedStatesofAmerica
ril
Ve
FirstPrinting,May2015
Revision1.0
ISBN13:
9781512021462
ISBN10:
1512021466
www.VerilogCode.com
Forpermissionrequests,contactVerilogCode.com
VerilogCode.com Page 2
Digital Logic
RTL & Verilog
m
Interview Questions
co
e.
od
C
og
ril
Ve
VerilogCode.com Page 3
m
co
e.
od
C
og
ril
Ve
VerilogCode.com Page 4
Digital logic
RTL & VeriloG
m
Interview Questions
co
e.
od
C
og
About the Author:
ril
Trey Johnson has been designing digital logic circuits and writing
Ve
RTL code in both Verilog and VHDL languages for almost twenty years.
Johnson has been granted three United States Patents for his
digital design solutions. He is the founder of
VerilogCode.comwhich is a
website dedicated to sharing information about Verilog and RTL design.
Please visit the website for more digital design and job interview
questions and to also share your own experiences.
VerilogCode.com Page 5
m
co
e.
od
C
og
ril
Ve
VerilogCode.com Page 6
m
co
e.
od
ThisbookisdedicatedtoBrandi,Tucker,GunnerandAlexa
C
og
Thankyouforridingwithmeonlifeswavesofchange,
ril
...andforembracingthejourneyalongtheway.
Ve
VerilogCode.com Page 7
co
e.
od
C
og
ril
Ve
VerilogCode.com Page 8
TableofContents
Introduction 17
RTLVerilogSyntaxQuestions..... 19
m
co
RTLLogicDesignQuestions... 29
e.
od
ClockDividers,ClockGating,andResetQuestions. 49
C
og
ClockDomainCrossingQuestions. 59
ril
PowerRelatedDesignQuestions.... 65
Ve
DigitalLogicQuestions.... 71
LogicalThinkingQuestions...... 93
AnswerstoLogicalQuestions....... 99
FurtherReadingandStudyingonYourOwn........ 103
PersonalInterviewNotesandQuestions.... 105
CreditandSources. 119
VerilogCode.com Page 9
co
e.
od
C
og
ril
Ve
VerilogCode.com Page 10
ListofQuestions
RTLVerilogSyntaxQuestions
1. Explainblocking nonblocking
versus statements
2. ShowVerilogcodefor bitwise
versusconditional
operators
3. Verilogcodeforlogicgates:
and,or,nand,nor,xor,xnor
m
4. Verilogcodeforbitwisereduction
co
5. Verilogcodemultiplyinganddividingbypowersof2
6. Verilogcodeforsignextensionandconcatenation
e.
7. WriteVerilogCodefor asynchronous andsynchronousFlipFlops
8. Verilogcodingwhatarethreewaystocodeamux
od
9. Whattypeofcircuitwouldthesynthesistoolcreateformuxcode
10. Verilogcodeforlatchversusflipflopanddrawtimingdiagram
C
RTLLogicDesignQuestions
og
ril
11. Designacircuittodetectifasignaltransitionsinanydirection
12. Designacircuittodetecta1cyclehighpulse(synchronously)
Ve
13. Designasequencedetectorcircuittodetect1,0,1,1,0usingFSM
14. Verilogcodetodetectapattern10110anywhereinlast8samples
15. Forthetimingdiagramshow,writeVerilogcodetocreateit
16. Designadebouncecircuittoremoveinputglitches
17. WriteVerilogcodetoconvertBCDtograycode
18. DesignasynchronousfifomoduleusingdualportRAM
19. Designacircuittodetectifnumberisdivisiblebythree
20. DesignacircuittocalculateFibonaccisequence
21. Designacircuittofindthemaximumandsecondhighestnumber
22. Designacircuittooutputsecond,minute,andhourfrom1msinput
23. Giventhetimingdiagram,writetheequivalentVerilogcode
24. DrawthestructureofadigitalFIRfilterwith5taps
ClockDividers,ClockGating,andResetQuestions
25. Designaclockdivideby2circuit
26. Designaclockdivideby3circuit(with50percentdutycycle)
27. DesignaclockdividerbyNcircuit(with50percentdutycycle)
28. Designaglitchfreeclockgatingcellwithenablepin
29. Howtodetectarisingedgeofaninputsignalifclocksareoff
30. Designaresetcircuitwithasyncassertionandsyncdeassertion
VerilogCode.com Page 11
ClockDomainCrossingQuestions
31. Whatismetastability?
32. Designacircuitfromaslowclockdomaintoafastclockdomain
33. DesignacircuittohandleCDCfromfastdomaintoaslowdomain
34. Howwouldthecircuitchangeifyouneedtosynchronizeabus?
35. Graycodingtechniquestocrossclockdomains
m
PowerRelatedQuestions
co
36. Describetwocomponentsofpower
e.
37. Describehowtoreducestaticpower
38. DescribehowtoreduceDynamicpower
od
39. DescribelowpowerRTLcodingtechniques
C
Refresher:DigitalLogicQuestions og
40. Whatisdefinitionofsetupandholdtimeforaflipflop
ril
41. VennDiagramandBooleanLogic
Ve
42. LogicGateDesignTransistorLevel
43. CrossSectionofatransistorunderstandtheprocessnode
44. KarnaughMaps(clkdivideby3circuitnot5050dutycycle)
45. HalfAdderusingXORgatesforadditionandANDgateforcarry
46. Usingonly2inputmuxes,createa nand nor
, inverter
, or
, and
, ,
xor
47. HowtouseandXORgatelikeacontrolledinverter?
48. Designaninverter and
, or
, xor
,and gateusingjustnandgates
49. Create4:1muxusing2:1mux
50. Whatisthefastestfrequencythiscircuitcanrun?
51. Convertthisdecimalvaluetobinary,hex,andoctalformat
LogicalThinkingQuestions
52. FourGallonsofWater
53. ThePathtoFreedom
54. ThreeLightSwitches
55. MultiplicationQuestion
56. EinsteinsRiddle
VerilogCode.com Page 12
ListofFigures
1. BlockingStatementsandEquivalentGates (Fig.1)
2. NonblockingStatementsandEquivalentGates (Fig.2)
3. TimingDiagramcapturewithlatchandflipflop (Fig.3)
4. Latchvs.FlipFloptimingdiagram (Fig.4)
5. EquivalentGatesfromRTLcodeinEx.11(Fig.5)
m
6. TimingDiagramforEdgeDetectionusingclocks (Fig.6)
co
7. SequenceDetectorusingFSM (Fig.7)
8. DecoderCircuitShiftRegisterandCombinatorialLogic (Fig.8)
e.
9. WritetheVerilogcodetoproducetheabovewaveform (Fig.9)
od
10. ClassicSynchronizerCircuitusing2FlipFlops (Fig.10)
11. Circuittodetectlowtohightransition (Fig.11)
C
12. BCDtoGrayCode (Fig.12) og
13. CircuittoGenerateFibonacciSeries (Fig.13)
14. WriteVerilogCodetoProducethisTimingDiagram (Fig.14)
ril
15. 5TAPDigitalFIRfilter
(Fig.15)
Ve
16. TimingDiagramforClockDivideby3
(Fig.16)
17. TimingDiagramforClockDivideby3(5050dutycycle) (Fig.17)
18. TimingDiagramforClockDivideby4(5050dutycycle) (Fig.18)
19. TimingDiagramforClockDivideby5(5050dutycycle) (Fig.19)
20. LatchedBasedClockGatingCircuit (Fig.20)
21. Classic2StageSynchronizer (Fig.21)
22. ClockDomainCrossingusingFullHandshaking (Fig.22)
23. SynchronizeBusAcrossClockDomainsFullHandshake (Fig.23)
24. ExampleofCriticalPathinSequentialCircuit (Fig.24)
25. VennDiagram
(Fig.25)
26. LogicGatesforA&(B|C) (Fig.26)
27. CrosssectionofCMOSTransistor (Fig.27)
28. 3StateFSMforClockDivider (Fig.28)
29. Graycoding(withviolationfromstate11tostate00)
(Fig.29)
30. 2bitFSM(illegalgraycodetransition) (Fig.30)
31. SixstateFSMwithcorrectgraycodevalues (Fig.31)
32. EquivalentGatesResultandCarry (Fig.32)
33. FullAdderCircuit
(Fig.33)
34. MultibitAdder
(Fig.34)
35. Inverter
(Fig.35)
36. ANDGateImplementedwithNANDGates (Fig.36)
37. ORGateImplementedwithNANDGates
(Fig.37)
VerilogCode.com Page 13
38. XORGateImplementedwithNANDGates (Fig.38)
39. 4:1Muxcreatedwith2:1muxes
(Fig.39)
40. 4:1muximplementedwithcombinatoriallogic(Fig.40)
41. Whatismaximumfrequencythiscircuitcanrun?(Fig.41)
ListofVerilogCodingExamples
m
1. Operator:&versus&& (Ex.1)
co
2. Operator:|versus||
(Ex.2)
3. Operator:~versus! (Ex.3)
e.
4. BitwiseOperators (Ex.4)
od
5. BitwiseReduction (Ex.5)
6. ShiftOperations (Ex.6)
C
7. ConcatenationOperations (Ex.7)
og
8. Verilogcodingstylesfora4:1mux (Ex.8)
ril
9. PriorityEncoder (Ex.9)
10. ParallelMuxingSchemeusingfullcasestatement (Ex.10)
Ve
VerilogCode.com Page 14
ListofTables
1. AsynchronousversusSynchronousFlipFlops (Table1)
2. InverterGate,TruthTable,andtransistorlevelcircuit (Table2)
3. NANDGate,TruthTable,andtransistorlevelcircuit
(Table3)
4. NORGate,TruthTable,andtransistorlevelcircuit (Table4)
5. ANDGate,TruthTable,andtransistorlevelcircuit
(Table5)
m
6. ORGate,TruthTable,andtransistorlevelcircuit(Table6)
co
7. SemiconductorManufacturingProcessingNodes
(Table7)
8. TruthTableforanAdder(Table8)
e.
9. InverterImplementedwith2:1mux (Table9)
od
10. ANDGateImplementedwith2:1mux (Table10)
11. ORGateImplementedwith2:1mux (Table11)
C
12. NANDGateImplementedwith2:1muxandinverter (Table12)
13. NORGateImplementedwith2:1muxandinverter
og (Table13)
14. XORGateImplementedwith2:1muxandinverter (Table14)
ril
15. XNORGateImplementedwith2:1muxandinverter (Table15)
16. XORGateUsedasControlledInverter (Table16)
Ve
17. PathtoFreedomDoors
(Table17)
(
18. MultiplyQuestionTable18)
VerilogCode.com Page 15
m
co
e.
od
C
og
ril
Ve
VerilogCode.com Page 16
Introduction
Im30,000feetabovetheground,onaplaneheadedtoSanDiego
forajobinterview.Imalittleanxious,andItakesomecomfortin
lookingoutofthesmallwindowpanenexttome.Myeyeswanderback
m
downtothemagazinearticlesittingonmylap,thenIreadthesewords:
co
Transitions
.
Thatsalllifeis,anditstougherthanphysics.
e.
Fromschooltoworktoretirementtodead .
od
Themagazinearticleisaboutchildrenwhoareinterviewingfor
C
preschool,andthemostimportantcharacteristicthattheadministrators
lookforishowwellcanthechild
og
adapt tochangewithnewsurroundings
andnewrules.Butthisarticlecouldhavebeenwrittenaboutme:an
ril
engineerwhospenteighteenyearsworkingforthesamecompany,and
Ve
onedaywassuddenlyletgoasaresultofacorporatedownsizing.Iam
nowtheonewhomustadapttochange,newsurroundings,andnewrules.
ThisbookdocumentsrealinterviewquestionsthatIencountered
frommyownpersonaljobinterviewingexperienceswithsomeofthe
toptiersemiconductorcompaniesintheworld.Thisbookalsocontains
fundamentaldigitaldesignmaterialandpracticalVerilogcodeexamples
thatIcreatedbasedonthethemesfromthetypesofquestionsthatI
experiencedfirsthand.Thisbookwillhelpprepareyouforyourown
interviewingprocess.Itisbynomeanstheendall,butrather,consider
thisbookasagreatstartingpoint.Asyoureadthroughsomeofthe
questions,Iwillalsosharewithyousomeofmypersonalinsightand
knowledgeinthe AuthorsTips section,whichIhaveacquiredthroughmy
careerasadigitallogicprofessional.
Interviewingforajobislikegoingonadateatfirstyoumayfeel
alittlenervousorawkward,butaftersometimeandmoreinterviewsyou
soonbecomemorecomfortableandconfident.Donotgetdiscouragedin
VerilogCode.com Page 17
thebeginning!Thejobinterviewingexperiencecanbedaunting.Itwill
testyourmentaltoughness.Iexperiencedheadachesduringmyfirstfew
interviewsbecauseofthelonghoursofmentalstress.Butthesayingis
truethatpracticemakesperfect
.Afterseveralmoreinterviewattempts,I
becamemorecomfortable,developedasenseofcalmness,andfeltmore
preparedtoanswerthequestions.
m
Iveencounteredmanydifferenttypesofinterviewquestions
co
rangingfromrealworldpracticalexamples,toacademictextbookor
e.
theoreticalquestions(usuallyaskedbypeoplewithPHDswithnotmuch
od
practicalexperience),totrickyquestionsusingsomeobscurecircuit
(whichwouldneverbeapplicableintherealworld),tobehavioral
C
questions(usuallyaskedbyHumanResourcerepresentatives).This
og
bookfocusesonrealworldpracticalexamples,anditalsodiscussessome
ofthetrickyandobscurequestionsthatareasked.Preparingfor
ril
behavioralquestionsisimportantandiscoveredonourwebsite.
Ve
Thisbookisdividedintomultiplesectionscoveringthefollowing
topics:RTLVerilogcodingsyntax,RTLLogicDesign(includinglow
powerRTLdesignprinciples),clockingandresetcircuits,clockdomain
crossingquestions,digitaldesignfundamentals,andlogicalthinking
questions.Eachsectionisunrelatedtotheothersoyoucanjumparound
toanysectionorquestionthatinterestsyou.
Thisbookisagreatstartingplaceforyoutobeginpreparingfor
yourjobinterview.Thisbookprovidesyouwithabroadrangeof
informationandcoversmanytopics.Bytheendofthisbook,youwill
havemoreknowledgeandinsightintothetypesofdigitaldesigninterview
questionsbeingaskedinthefieldofsemiconductordigitaldesign.
Rememberthatlifewillalwaysbringaboutchange,anditshow
wellyoucantransitionandadaptthatisimportant.Haveastrongand
positiveattitudeandyouwillsucceed!
Goodluckonyournewjourney!
VerilogCode.com Page 18
m
co
e.
od
C
og
ril
RTL Verilog Syntax Questions
Ve
VerilogCode.com Page 19
m
co
e.
od
C
og
ril
Ve
VerilogCode.com Page 20
1. What is the difference between blocking and
non-block statements, and when are they used?
BlockingstatementsarecodedinVerilogwiththe=operator,and
blocks
areusedwhencreatingcombinatoriallogic.Thisoperator the
simulatorfromexecutingsubsequentstatementsuntilthecurrent
m
evaluationandassignmentisdone.Considerthefollowingcode(Eis
co
assignedtheimmediatenewvalueofC):
e.
od
C
og
ril
Ve
BlockingStatementsandEquivalentGates
(Fig.1)
NonblockingstatementsarecodedinVerilogwith<=operator,
arealwaysusedwhencodingflipflopsinsideaclockedprocess.The
assignmentispostponeduntilallthesubsequentstatementsareevaluated.
Thisallowsforparallelorconcurrentexecutionofstatements.Inthis
example,EisassignedthepreviousvalueofC(nottheimmediate):
NonblockingStatementsandEquivalentGates
(Fig.2)
VerilogCode.com Page 21
2. Explain the difference between logical and bitwise
operators
InVerilog,youshouldunderstandthedifferentsyntaxusedfor
writingconditionalifstatementoperationscomparedtowritingcodefor
creatinglogicalgateswithbitwiseoperations.
co
Forbitwiseoperationsresultinginan ANDgate,usethe&operator
e.
and
assign C = A & B; //This will create an gate
od
Forconditional and
ifstatements,usethe&&operator
C
if ( cond1 == 1b1 && cond2 == 1b1) {...}
og
Operator:&versus&&
(Ex.1)
ril
Ve
Forbitwiseoperationsresultinginan ORgate,usethe|operator
or
assign C = A | B; //This will create an gate
Forconditional or
ifstatements,usethe||operator
if ( cond1 == 1b1 || cond2 == 1b1) {...}
Operator:|versus||
(Ex.2)
Forbitwiseoperationsresultingin invertergate,usethe~operator
assign A = ~B; //This will create an
inverter
Forconditional not
ifstatements,usethe!
if (!cond1) { }
Operator:~versus!
(Ex.3)
VerilogCode.com Page 22
3. Write code for logic gates:
and, or, xor, nand, nor,
xnor
assign C = (A & B); AND
// gate
assign C = (A | B); OR
// gate
assign C = (A ^ B); XOR
// gate
assign C = ~(A & B); NAND
// gate
m
assign C = ~(A | B); NOR
// gate
co
assign C = ~(A ^ B); XNOR
// gate
e.
BitwiseOperators
(Ex.4)
od
4. How can you bitwise reduce a multibit signal?
C
wire [15:0] databus; og
wire all_ones_detected;
ril
wire is_databus_odd;
Ve
wire signal_not_zero;
AND
assign all_ones_detected = &databus; // all the bits together;
assign is_databus_odd = ^databus; // XOR
all the bits together;
assign signal_not_zero = |databus; // OR all the bits together;
BitwiseReduction
(Ex.5)
VerilogCode.com Page 23
7. What are three ways to code a 4:1 mux in Verilog?
Assumethe4:1muxinputsarenamedA,B,C,D,youwillneed
select
a2bit output
line(tochoosebetween4inputs)andhavea1bit :
Coding Style 1:
m
assign output = (select == 2b00 ) ? A :
co
(select == 2b01) ? B :
(select ==2b10) ? C : D;
e.
od
Coding Style 2:
C
always @(*)
if (select == 2b00) og
output <= A;
ril
else if (select == 2b01)
Ve
output <= B;
else if (select == 2b10)
output <=C;
else
output <= D;
Coding Style 3:
always @(*)
case (select):
2b00: output <= A;
2b01: output <= B;
2b10: output <= C;
2b11: output <= D;
end case;
Verilogcodingstylesfora4:1mux (Ex.8)
Youcouldalsoinstantiateamuxcelldirectlyifitexistsinyourlibrary.
VerilogCode.com Page 24
8. What circuit would synthesis create for previous
mux coding styles?
CodingStyles1and2areequivalentcircuitsbutusedifferent
codingstyles,andbothproduceapriorityencoder(pathAishighest)
Style 1:
m
assign output = (select == 2b00) ? A :
co
(select == 2b01) ? B :
e.
(select ==2b10) ? C :
D;
od
C
Style 2:
always @(*) og
if (select == 2b00)
ril
output <= A;
Ve
ParallelMuxingSchemeusingfullcasestatement
(Ex.10)
VerilogCode.com Page 25
9. Write Code for Asynchronous/Synchronous Flip
Flops and discuss the pros and cons of each
Asynchronous Synchronous
m
negedge rst) If (!rst )
Verilog
co
If (!rst ) Q <= #1 1b0;
Code Q <= #1 1b0; else
e.
else Q <= #1 D;
Q <= #1 D;
od
C
og
ril
Schematic
Ve
Noneedtoworryabout
Pros Noneedforclockstoberunning
asynchronoustiming
Anyglitchonresetsignalwill
resetflops(Iftherearecross
Needtotimeboththe
clockdomainpaths,thenyou
Cons assertionofresetand
needtosynchronizetheresetto
alsodeassertionofreset
eachclockdomain).Needto
timetheremovalofreset
AsynchronousversusSynchronousFlipFlops(Table1)
AuthorsTip :ThequestionssofarhasfocusedonVerilogsyntax.
BasicsyntaxquestionscaneasilybelookeduponGoogle( after
you
haveajob),however,onajobinterviewitsimportanttobeprepared
forthesequestionsandknockthemoutofthepark.
VerilogCode.com Page 26
10. Write Verilog to capture input below with a latch
and a flip flop, and draw the timing outputs of each.
m
co
TimingDiagramcaptureinputintoalatchandflipflop
(Fig.3)
e.
//purposely coding latch
od
always @(clk or input)
if (clk == 1b1)
C
Q_latch <= input;
og
//flip flop coding a Latch
ril
always @(posedge clk)
Ve
Theoutputsofthelatchandflipflopisbelowinthetimingdiagram:
Latchvs.FlipFloptimingdiagram
(Fig.4)
Theoutputoftheflipfloponlychangesontherisingedgeofclock,and
willequalthevalueoftheinputcapturedattherisingedgeofclock.The
latchoutputwillfollowtheinputsignalwhilethelatchisopen(inthis
casewhileclockishigh).Whenthelatchcloses(clockislow),theoutput
holdsitspreviousvalue.
VerilogCode.com Page 27
m
co
e.
od
C
og
ril
Ve
VerilogCode.com Page 28
m
co
e.
od
C
og
ril
RTL Logic Design Questions
Ve
VerilogCode.com Page 29
m
co
e.
od
C
og
ril
Ve
VerilogCode.com Page 30
11. Design a circuit that can detect if an input signal
transitions in either direction. Draw a timing diagram.
Forthisanswerletsassumethereisaclockavailable,andalsothe
inputsignalDisonthesameclockdomainasourcircuit.Aswithall
interviewquestions,youshouldstateyourassumptionsbeforeanswering
m
thequestionsorconfirmwiththeinterviewersoyouarebothonthesame
co
page.
Theeasiestwaytodetectifaninputsignalhaschangeditsimply
e.
comparecurrentsignalattimeTtothepreviousversionofthesignalat
od
timet1.Therefore,aflipflopisusedtocapturethesignal,andthenyou
cancompareittothepreviousversionofthesamesignal:
C
og
//capture the signal to have a delayed version
ril
always @ ( posedge clk or negedge reset)
Ve
if (~reset)
Q <= #1 1'b0;
else
Q <= #1 D;
EquivalentGatesfromRTLcodeinEx.11
(Fig.5)
VerilogCode.com Page 31
Thetimingdiagramisshownbelow.Thiswaveformwasdrawn
withtoolcalledTimeGen,downloadedfromXFusionSoftware.com:
m
co
e.
od
C
og
TimingDiagramforEdgeDetectionusingclocks
(Fig.6)
ril
12. Design a circuit to detect a 1 cycle pulse input
Ve
Usingdelaystatestorememberthestateofthesignalforprevioustwo
cycles,youcansimplecheckfor0,1,then0.YoucouldalsouseanFSM.
Circuittodetectpulse(Ex.13)
VerilogCode.com Page 32
13. Design a sequence detector for the pattern: 10110
OnemethodistodesignaFSMtodetectthesequence.IftheFSM
reachesstate5,thengenerateavalidoutputpulse(alltheotherstateswill
outputlow).Itsalsoimportanttomakesureyougobacktocorrectstate
ifthewrongvaluecomesin(youdontalwaysneedtogobacktoidle
m
state).Youneedtocheckifsomeofthesequencehasalreadystartedand
co
gobacktotheappropriatestate.
e.
od
C
og
ril
Ve
SequenceDetectorusingFSM
(Fig.7)
VerilogCode.com Page 33
This is the end of the free preview PDF.
m
figures and drawings, and 28 Verilog examples,
co
then please purchase the PDF from our website:
e.
od
C
VerilogCode.com
og
ril
Ve
VerilogCode.com Page 34