Lecture_11 - ECE190 Lecture11 February22,2011  ­ Lecture Topics Programmingusingsystematicdecomposition Debugging

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ECE190 Lecture11 February22,2011  ­ Lecture Topics Programmingusingsystematicdecomposition Debugging LC ­3datapathreview Lecture materials TextbookCh.6 Homework HW3dueWednesdayFebruary23at5pmintheECE190drop ­offbox Machine problem MP2dueMarch2,2011at5pmsubmittedelectronically. Announcements Statsfortheexam  #ofstudentsthattook theexam Average Standarddeviation #ofzeroson programmingpart Highestscore Lowestscore    Monday 97 Tuesday 96 Wednesday 90 37.7 14.0 23 38.9 16.9 26 35.2 14.8 30 60 6 60 7 59 2 1 V.Kindratenko ECE190 Lecture11 February22,2011 Programming using systematic decomposition Systematic decomposition Inorderforelectronstosolveaproblemforus,weneedtogothroughseverallevelsof transformationtoget o fromthenaturallanguageinwhichtheproblemstatementisinitiallyexpressed o tothelevelatwhichelectronscanbemanipulatedtodotheworkforus Problemstatement Algorithm Program  Problemstatementcanbeimprecise,thus,wefirsttranslateitintoaprecisealgorithmwhich shouldhavethefollowing3properties: o finiteness(itterminates) o definiteness(eachstepispreciselystated) o effectivecomputability(eachstepcanbecarriedoutbythecomputer) tostartwiththeproblemstatementandendupwithaworkingprogram,wewillapplyaprocess referredtoassystematicdecompositionorstepwiserefinement o complextasksaresystematicallybrokendownintosimpler,smallertaskssuchthatthe collectionofthesesimplertasks,orunitsofwork,willaccomplishthesameasthe originaltask o thedecompositioncontinuesuntileachsimplertaskcanbeimplementedasjustafew instructionsintheprogramminglanguageweuse Three constructs Wewanttoreplacealargeunitofworkwithasetofafewsmallerunitsofwork. tasktobedecomposed  Thiscanbedoneusingoneofthe3basicconstructs:sequential,conditional,anditerative Sequentialconstruct o Isusedwhenwecandecomposeagiventaskintotwosmallersub ­tasks,suchthatone  2 V.Kindratenko ECE190 Lecture11 February22,2011 ofthemhastobefullyexecutedbeforewecanexecutetheother: Subtask1 tasktobedecomposed Subtask2  Oncesubtask1isexecuted,wenevergobacktoit,wecontinuewithsubtask2 conditionalconstruct o Isusedwhenthetaskconsistsofsomesubtaskssuchthatonlyoneofthemneedstobe executed,butnotall,dependingonsomecondition: Testcondition tasktobedecomposed Subtask1 Subtask2  o Ifthetestconditionistrue,weneedtocarryoutonesubtask,otherwisewecarryout theothertask;butwenewercarryoutbothtasks o Onceoneofthesesubtasksisexecuted,wenevergoback Iterativeconstruct o Isusedifoneofsubtasksneedstobere ­doneseveraltimes,butonlyaslongassome conditionismet f al s Testcondition true tasktobedecomposed Subtask   3 V.Kindratenko ECE190 Lecture11 February22,2011 o Eachtimewefinishexecutingthesubtask,wegobackandreexaminethecondition o Themomenttheconditionisnotmet,theprogramproceedsonwards Fewwordsaboutflowchartnotation o Flowchartisbuiltformboxeswithoneinputandoneoutput o  Rectangleshapeisusedtoindicateaworktask Rhombshapeisusedtoindicateadecisiontask Ellipseshapeisusedtoindicatebeginningandendofthetasksequenceforthe entireflowchart LC ­3 instructions to implement the constructs Sequentialconstruct o Subtask1startsatmemoryaddressAandendsatmemoryaddressB o Subtask2thenstartsatmemoryaddressB+1 Subtask1 A Subtask2 B B+1 Subtask1 Subtask2 C   Conditionalconstruct o CreatecodethatconvertsdecisionconditionintooneoftheconditioncodesN,Z,P o UseconditionalBRinstructiontotransfercontroltothepropersubtask o UseunconditionalBRtotransfercontroltothenexttaskafterfirstsubtaskisdone A B B+1 generatetestcondition 0000???PCoffsettoC Subtask1 Testcondition 0000111PCoffsettoD C Subtask1 Subtask2 D Subtask2 nextunitofwork   Iterativeconstruct o CreatecodethatconvertsdecisionconditionintooneoftheconditioncodesN,Z,P o UseconditionalBRinstructiontobranchiftheconditiongeneratedisfalse  4 V.Kindratenko ECE190 Lecture11 o February22,2011 UseunconditionalBRtotransfercontrolbacktotheconditiongeneratingcodeafterthe subtaskiddone A B B+1 f al s Testcondition true Subtask generatetestcondition 0000???PCoffsettoC Subtask1 0000111PCoffsettoB C nextunitofwork   Example: character counter  Step1:convertthisproblemstatementintoanalgorithm Step2:convertthealgorithmintoaprogramwritteninLC ­3machinelanguage Step 1: from problem statement to algorithm/flowchart Problemstatementisnotpreciseandincomplete o  o Whereisit? o Howbigisit? o Howshouldthefinalcountbeprinted? Howdoweresolvethesequestions? o Askforclarificationfromthepersonwhogaveyouthisproblemstatement o Makeadecisionyourselfanddocumentit Forthegivenproblemstatement,wewillmakethefollowingassumptions: o sequentialrecordinmemory,startingatsomeknown/givenaddressand endingwithsomespecialcharacter,say,EOT,whoseASCIIvalueisx4 Thus,wewilluseonememorylocation,say,x3012,toholdtheaddressof wherethefilebegins o Thefinalcountistobeprintedonthescreenasanumber o Restriction:nomorethan9identicalcharactersinthefile(laterwewillseewhy) Wewillusethefollowingresisters o R0 ­charactertocount o R1 ­characterfromthefile o R2 ­occurrencecounter  5 V.Kindratenko Start Inputachar.Thenscan afileandcount occurrencesofthatchar inthefile.Displayon themonitorthenumber ofoccurrencesofthat char. Stop Start A Initialization  ­inputacharacter  ­setupthepointerto thefirstlocationinthe fi l e  ­getthefirstcharfrom thefile  ­clearcounter B Scanthefile,increment counterifthecharacter matches C Displaythecounteron themonitor Stop Start A1:clearcharcounter A2:loadfileaddress A3:getuserinput Processedallchars fromthefile? B1 A4:loadfirstcharfromfile yes no B2 Testchar.Ifmatch, incrementcounter.Get nextchar. C1:preparetodisplay C2:display Stop Start yes B2 R1=R0? no B1 R1=EOF? A1:R2 0 A2:R3 A3:R0 A4:R1 yes no B3:R2 R2+1 B4:R3 R3+1 B5:R1 C1:formASCIIoutput C2:display Stop V.Kindratenko 6  February22,2011 Lecture11 ECE190 o R3 ­locationofthenextcharactertoreadfromfile Systematicdecompositionisrecursivelyapplieduntilwearriveataveryfinesetofwell ­defined stepseachofwhichcanbetranslatedintojustafewinstructionsintheprogramminglanguage:  ECE190 Lecture11 February22,2011 Step 2: from algorithm/flowchart to pseudo code x3000 x3001 x3002 x3003 x3004 x3005 x3006 x3007 x3008 x3009 x300A x300B x300C x300D x300E x300F x3010 x3011 x3012 x3014                     R2 0  R3 GETC  x3016 x3017 x3018 x3019 x301A      x74 x65 x73 x74 x4        R4  ­4 BRz,_____ AND LD  TRAPx23 LDR ADD   (figureoutPCoffsetlater(x10)) (figureoutPCoffsetlater(x8))   R1+R0 BRnp,____      (figureoutoffsetPClater(x1))   LDR BRnzp,____    (figureoutoffsetlater( ­10))   LD  (figureoutoffsetlater(x4))  PUTC   TRAPx21 HALT   TRAPx25 x3016 (startingaddressofthefile) x30 (ASCIIoffsetvalueforprintingadigit) t  e  s  t  end ­of ­filesymbol Step 3: from pseudo code to program in machine language  Programtocountoccurrencesofacharacterinafile    limitations:   programonlyworksifnomorethan9occurrencesarefound    inputs:   charactertobeinputfromthekeyboard    outputs:   resulttobedisplayedonthemonitor    registerusage:  R0 charactertocount  R1 characterfromthefile  R2 characteroccurrencecounter  R3 locationofthenextcharactertoreadfromfile    memoryusage:  x3012 locationofthefile  7 V.Kindratenko ECE190 Lecture11 February22,2011  x3013 storesx30valueusedtoconvertcounttoanASCIIcharforoutput   actualfile,locatedstartingfromtheaddressspecifiedinx3012    filemustendwithvaluex0004(end of text)   0011000000000000 startingaddressoftheprogram(x3000)    Initialization 0101010010100000 (ANDR2,R2,#0)clearcharactercounter 0010011000010000 (LDR3,x10)loadstartingaddressofthefile 1111000000100011 (GETC)getacharacterfromthekeyboard 0110001011000000 (LDRR1,R3,#0)loadnextcharacterfromthefile    Testcharacterforend of file 0001100001111100 (ADDR4,R1,# 4)checkifthisisendoffile 0000010000001000 (BRz,x8)ifso,skiptotheoutputpart    Testcharacterformatch 1001001001111111 (NOTR1,R1)otherwise,checkifthecharacter 0001001001100001 (ADDR1,R1,#1)fromthefileisthesameasthe 0001001001000000 (ADDR1,R1,R0)characterenteredfromthekeyboard 0000101000000001 (BRnp,x1)ifnot,skipjustoneline 0001010010100001 (ADDR2,R2,#1)ifyes,incrementthecounter    Readnextcharacterfromfile 0001011011100001 (ADDR3,R3,#1)movetothenextcharacterinfile 0110001011000000 (LDRR1,R3,#0)readit 0000111111110110 (BRnzpx A)andrepeatthetest    Outputresultsandstop 0010000000000100 (LDR0,#4)loadASCIIoffset 0001000000000010 (ADDR0,R0,R2)preparecounterforoutput 1111000000100001 (PUTC)outputcountervalue 1111000000100101 (HALT)halttheexecutionoftheprogram    StorageforfileaddressandASCIIoffset 0011000000010110 startoffilememoryaddress x3016 0000000000110000 ASCIIoffsetvalue x30   filetocountoccurrencesofacharacter 0011000000010110 startoffilememoryaddress x3016  actualfiletoprocess,onecharacterpermemorylocation 0000000001110100 x74t 0000000001100101 x65e 0000000001110011 x73s 0000000001110100 x74t 0000000000000100 x4 end of filesymbol Debugging Wehavewrittenourprogramanditdoesnotwork!Nowwhat? Thesolutionistotraceourprograminanattempttoidentifywheretheproblemis o Examinethesequenceofinstructionsbeingexecuted o Examinetrackofresultsbeingproduced o Compareresultsfromeachinstructiontotheexpectedresult  8 V.Kindratenko ECE190 Lecture11 February22,2011 Errorspresentinprogramsarereferredtoasbugsandtheprocessofgettingridofthemis referredtoasdebugging. Typesoferrors o Syntaxerror:typingerrorthatresultsinanillegaloperation o Logicerror:programislegal,butwrong,andsotheresultsdonotmatchtheproblem statement o Dataerror:inputdataisdifferentthanwhatyouexpected Tracingtheprogram o Executetheprogramonepiece(oneinstruction)atatime,examineregistersand memorytoseeresultsateachstep Single ­stepping:executeoneinstructionatatime Breakpoints:directthesimulator/debuggertostopexecutingwhenitreachesa specificprogramlocation Watchpoints:directthesimulatortostopwhenaregisterormemorylocations changes,orbecomesequaltoaspecifiedvalue LC ­3 data path review TheLC ­3datapathconsistofallthecomponentsthatprocesstheinformationduringan instructioncycle o Thefunctionalunitthatoperatesontheinformation o Theregistersthatstoretheinformation o Busesandwiresthatcarryinformationfromonepointtoanother Basiccomponentsofthedatapath: Theglobalbus o LC ­3globalbusconsistsof16wiresandassociatedelectronics o Itallowsonestructuretotransferupto16bitsofinformationtoanotherstructureby makingthenecessaryelectronicconnectionsonthebus o Exactlyonevaluecanbetranslatedonthebusatatime o Eachstructurethatsuppliesvaluestothebusconnectstoitviaatri ­statedevicethat busatatime o Thestructurewishingtoobtaininformationfromthebuscandosobyasserting(setting to1)itsLD.x(loadenable)signal. Memory o MemoryinLC ­3isaccessedbyloadingthememoryaddressvalueintoMAR o TheresultofmemoryreadisstoredinMDR o read/writeofmemory TheALUandtheregisterfile o TheALUistheprocessingelement Hastwoinputsandoneoutput  9 V.Kindratenko ECE190 Lecture11 February22,2011 Inputscomedirectlyfromtheregisterfile OneoftheinputscanalsobesupplieddirectlyfromtheIR,controlledbythe SR2MUX Outputgoestothebus Itthenisstoresintheregisterfileand Processedbysomeadditionalcircuitrytogeneratetheconditioncodes N,Z,P o Theregisterfileconsistsof816 ­bitregisters Itcansupplyuptotwovaluesviaitstwooutputports Itcanstoreonevalue,comingfromthebus Read/writeaccesstotheregisterfileiscontrolledbythe3 ­bitresistersignals, DR,SR1,SR2 ThePCandPCMUX o ThePCsuppliesviatheglobalbustotheMARtheaddressoftheinstructiontobe fetchedatthestartoftheinstructioncycle.ThePCitselfissuppliedviathethree ­to ­ onePCMUX,dependingontheinstructionbeingexecuted o Duringthefetchcycle,thePCisincrementedby1andwrittentothePCregister o Iftheexecutedinstructionisacontrolinstruction,thentherelevantsourceofthe PCMUXdependsonthetypeofthecontrolinstructionandiscomputedusingaspecial ADDunit TheMARMUX o ControlswhichoftwosourceswillsupplymemoryaddresstoMAR o ItiseitherthevaluecomingfromtheinstructionregisterneededtoimplementTRAP instruction,orthevaluecomputedbasedonthePCoravaluestoredinoneofthe general ­purposeregisters LC ­3instructioncyclerevisited o FETC IRcontainsthefetchedinstruction PCisincrementedby1 o DECODE Instructionisdecodedresultingincontrollogicprovidingvariouscontrolsignals tothecomputer o EVALUATEADDRESS Addressofmemorytobeaccessedduringtheexecutionoftheinstructionis computed Memoryaccessinstructionsrequirethisphase o OPERANDFETCH ThedatafrommemoryisloadedintoMDR o EXECUTE ALUisdirectedtoperformtheoperation Memoryaccessinstructionsdonothavethisphase  10 V.Kindratenko ECE190 Lecture11 o February22,2011 STORERESULTS Resultsarestoredtomemoryorregisters,dependingontheinstruction   11 V.Kindratenko ...
View Full Document

This note was uploaded on 01/22/2012 for the course ECE 191 taught by Professor Staff during the Spring '11 term at University of Illinois, Urbana Champaign.

Ask a homework question - tutors are online