You are on page 1of 34

SVSIem HenOrmance

Analysis and Optimization

KEY POINISOF THE CHAPIER
Notri rrlpr dnvcn syiems cfl b. e6ily an{lyzed rcilrime b€ ror
) . h x genenlly inpo$ible ro pFdicL*omr casc maoce 'n identrpr po

3 Inprovns rveGCe c$c perfommce genenily dcErds won cse AlLhouehdoi conpilen perrom good opLimizarion, ftoy shoutd be $udicdtur ro my$ Jretrbehrvro. 'Ineft 6 m idhcEnr kadeotrinnmeandncmoryE{tummenre innoy Ii 'his chrprerwe exmre 6suesrelaEd ro syiem prtommce osed on fttponsc hq tnc 10 adms md ne moryloadins Recall'nar r.rp,,y n,? r rne trmebeRe.n reccipror f inrenpr ad complcrionof alt asscia@dprdcesine TirtrJeili,B i rhe pereniase ol lme rhs C?U is do'ne 'uefd pnce$rg. Findly,us,i,a lr..r,r x rhepercenhg. ofusible menoryrha is being used. 'n'h .hapu, moE rhD my oder in rhc praenr votume, h i conificruon of expenenc..rolkbe. &d dckr. Anaiysis or ealrime pedomM.e is difrcuu ar be* md usudly impo$ibl. for inremF dnve. sys@ms.

CALCULATION 9,1 RESPONSE.IIME
TIE elm,xrion or stn.D rlr (rl dnfhu {-qrrhne LheLas[ f.o.snng difftrs hr \!nem inroL,nl Tlrmu:1r.tr' tr{ Ne hrve beer d.|cidLngon rhr Lr"|E or loor'ns r rhcr crl.trlircn! buLtr i\ nc!$\'y '..dnfhtr llio* rnd'ng\ heE st cxnrhci dnrtrs\Lhe lrDs $u($ oj tu\f.Ds. rne delrl rnd ho! Lhey.i.

comPonenh rimc fo' TLEre\ponse Jcl.)_ r polledloop\$em conllr ol Lhrte Lhe hrrdvrc drLx)rinr,i!nl ni rtrLDe sol\.re lig bysoi'ee{.m! d.v'ce: Lh. rhe Lh. trmclo. rhcFoll<i lo.t,o r{ rheIr! b( LLtrir. De.d.dro Pro.ess tr rL,Llt lrg Ne Filre 9.1) Th. n,!ddx '\ 'nmno\eoon'ls e\em No(i.r Lhc rnd.rn b! lsidtud Th. !nr to.hecr. a rgridlurif ro'hehrn'LFrrrtrft c,n ro Lo bN\$ciJli,lr.i.ond\ TheLimc pioc.$ rhevenLrelre'l rh. flrsdcp.nd\. ivol!..1.H orcoLAf.on r|I tmcss

proce$'nstrmea dniled casedlmes rha sutrLc,enL Thc prc.ed'n-q i5 cvcn6.Howev{ ilevcits beg'nro p e up Lhd is. if r neN cvonr bcr*cctr Irhq rh!' oo ci. needed ro.he.k lhe nxg dndP i5 rhc tlnc 'o vo$e ln generrl. iIJn the Lime dE procss Lhe evenrincluding rcsehin-q nrg (a&l isnonns$c rimcdccdldb) (o seL lag), rhen rtsponlc rhe !nc lar rhcnrhovftriff ne dc iheexkmrl devi!e

n.f P

(e.r)

fiar Tlpi.illy. sodehmtrfplacedon'!fiir is, thc'trnherorevenb canov*laP everh m olrennol allowcd dl o md 1*oovedappiig

code 9.r,2 Coroullnes/Ph.s-Driven
The rbrn.e or inkmps ii r conotrne synem mrles rhe dEtmin4ion of Espo.s rimedhq c.sy In lhr cxe Fsponsedmc is sidply roundby ra.ing Lbe of 9.2).In 'hr ermple, Lie wo r cdc parhfiough each rheksks GeeFigurc

ere.urion limc of !ich Phrt i,us

'lne

calcu dio, orrcstotrs rms fo lakncy. contxLsqilchtrmemd schedde/d'spfth ofLclor\ includiigitr,errupr rimcs(sqj Fjgurc9.1) $hedule rim$.'lhe ronkrL$ il$ trmes e !d.!L!i;gi c,,up'laEncyrrd Lhe r rull(cd by 1rc., ig rhc ftcn tolLovinB ruls ds.used, *th llred L ForpNnotrve sysEms rcprcsciF ,hc racb' s aftectns rherespons lim.. In gcneml.the rtspon$ rimelbr

n , = L ,+ c . + s + , 1 ,

(9.2j

wheE a, r fie inkmpr lrlcncy. h 'he cotrexrsaveLiLne. h Lhe C, shedulp t !me. andrl n 6e adlal pre.es 'ime $ee Fem 9.1)

n e g' ! b r q h e nt l r . r t p . i o n L U l c l l r { h e d u l ci ' m \ \ . ,rh 'n! trPle nktupb. whcn ! i $ h in inLcmtl rndml{ q(h rn 'nempi lonrDllr 5 (e sppliqJ m.nnl!n.'on

Cxl.ularotrol contiL ev.re$o€

tims r rN sm

Fni..on{d$ 'lr 'ldem'nd on oi high*L0nonl]'] *hrn Pmrs, x oi Lhe c e 1 whetrlhe h,ghri-pfi.rLY s roral,'Enupr l.t!r.y canbe compurcd
q lc rI .) Lir a. o . " ' o nd e J r ' f r h e . .

r n . ' 1 1 ' d p 'l ' .

lim! r, f lhelongc$completion lor an inrnc[on m rheinEnprd

' / L i n ^ - | . i - r e D e , i k I d , . . b h dh \ 'J ou'n-ou ' o. pr c t i r L n n e { ^ 1 i n L o 'b T i r p s r i n ! -'11rD'.4ee\0...hd.!rrd 1r\'l F- p. \.ll. u' 1- Fnc J - p . . d e r .o . ! r . ',' i on me qo Odemi".r on o n ( uinrd di c nd

r: vhen r luilFfr.rrJ md ne r rcmpL'o jnemf on..t hrve rcod"es crnnor Fo.$\cd unrl rll hishe.pnorily be rhe In Lhb.Ae s! .m .etresenL 'nrempl /r[en.yas

hishe.pnoriry rotrLines whePl, is Lie umenecdld'o co'npLere Sid.eprmes , misll bc 'nLenped. rhe !dlLul&iod of rr i5 di imp.sible rormo$ \yncms:in mv .Ne il is roo involved for N here.F* rctFnse !m$ tor pFentrve pnonryfd n exrnnlesor bounded \ J k m s e e l l l l .t l 0 r l . . r l l 4 3 l .

LATENCY 9.2 TNTERRUPT
'ftfle is ad inhernr dehy b€rsen wben m intenpr o.cun lnd Phen ce r h t s d e) F r a l e d h r , , - ' r p J ' d r ' n J . I r . r d b e : u \ e { r o-s'c.d.ng.. dd s o- Dor \tudraRdd\onv G rcLd(d, bo't deli md incidenul. The effecr of la@ncyk mosrpm.omced-bur easi b fiid vhen lowe4nonty inremps tre inriatd ddns fie erc.rion of ? hi prionLy Rsk. For the reveise.or in nundiobin sysEns, fte ered is slnentrt lesrned 6d more subLleLodelemine The rouowmspffisnphs desdib€ ls,encysourcs in fudher dehil.

The.onnbrion ,o ,nLempL rarencyfsurrnig rhelimiLiLioo fiom in,hc swnshint !i'e -R 4! t'"d r'./4r. TheE dehys catr prcduce buih-in hLcn.ies of umse.ondsor .vetrnicrcse.onds. exrnplc. rh. amohr ol rimeberween Iror trhef ri.xhflrldcvicc mtiahs an ]rtfttrttsiSrd lnd whenil dudly laLchs 'nLo Ln'.',rp'cofkollernr] be sveml nrioF.oids or morc, rhe dcpcndiry on rch'ns\peed 'lf iikmpl.onoucr chip. of le lrom Lhe nanufaruEr, or nry be measui.d

Macroinslruclion Execulion Times nrLrudion Dmgnd (or i'i.fof.og.rf) rlE is. wirh rc\! crlcprionr.!nimenpl .nrn nrsLncdhLc rcirl$, condi on .ode rcgrLcis, and.'hft dda rccdcd'o donplcr cxccurion rhemrcminirudion ol (mtrrop'oe,4r)cotrldbc dcsoycd il inLcnprod. Thus,re needLofind rhe .rcluior dne olcachmrcoiniru.rionbr-. cuhrionme$urenenr(see Seniod 3.23r.orhanufuclus s dtu shcds. itrhcrion wrh rhelonSes fte execurion (o rimein your .ode you mrr checl rhecompiler ouLpur decide rh6-$ill .Nsc rhc mdximum inrempr kre..y f n hN JU$ begun execuhs when'hc nrcmpLsicnalis to.civ.d.

&|t!de'.nlyh{hlns50mir\qqd\r

The laren.rcaNed insncnon comple k onenovdlooked, sullins by ioo ie problem.In cerun laneuoge in *ious implcmenuons,su.h as vdions ot FORIRAN p sns prmere4 vB paEmer.rlk6.e prorecred disrbled by des m coneh@d.Passingpramere qr $!h liis rypi.dly enrrlsnulripleindircr loads wh'ch irfie fis is long cm periods rcsukin conridsrbG dunnswtuchrhe'n,emp6 {edislbled.

Delib€nre di$blin8 or d,e in@m!6 by rho soir*&e ca creare substrrial i.hpr laiency, md 'ns mus b€ includ.d in de ovoGll larncy calculauonl IdmpB e disrbled a numb€r for orEmons, includirypEerion ol cndcar Egions, bu Md Sroudnes, conrei swirchins.

Whenx higlr.pnon'y rden.t.m DecomDredr

. thc Lotul inlcnpr

$h{e L,,,,,r 'hc mx\trnuNnLenpLlrknq. rf is rhu'mrr''pr Lrlcicyd!! ro protrcr'.i delrror rh.,nLenpr5isml.rr r rlr lon,sc! co'hplcrion ol.0 rlnr inn'r.!on, rd rr, \ rhemdimm, ri c rhc irn 'ttr mt d.libftrcly disabled rodin!. SjN Ll'r iitrtr$ *ill occuf srhc' *h,le Lbe dtr nkmpc R lrp i.n r disubhd of krenc] is ieplr(cilon rL! g.catc. 'lic Lro

d hfrruF hfrc) ssn0 r + oatf0.rol=

Do r

9.2.5LowPrlorlry InteruptsHigh
when rlow prionLrtuurinc in(rtr,p6o'! ollrighcrprio.iry srulr.n.onaE rhc nrhecdcul&onot,nlenprlrrncyisrhrdfcdollrisLrrpioriryk\k5ruini4 lmhcs Lhc cr!p' b 0E iD d rhetrme rheinkr!pr. sind. rhdhrd\!i.c u\trally ol ry imcftpr rontroll!fbur do.snor\ eml Lh.cPU un'il ' lic hiBherprion 'nLernF hrs ben dcird, rhc dfcdlvc 13 do conplerc hish-pnoriry Lh. h\l-ro Lhc oLhflcffcctr ioL opfly DcLennnal r. rc h dh.trscd in strtis.qu of rhe time ro.omplererhc higr-liriorry \ecrons. ftur, se can represc rltr hrci.y 6

and Deedcd comdete Lo *h{e a-- n rhcinrcnpr l.Lcn.y r/ r rheLime

9.3 TIME.LOADING IIS MEASIJREMENT AND
sd fte need knov theeft.uion 'idc ofvdiou)'Dodules rheoverdlsv ro .'Te odm! be'oeimpeme hrio i impotunr ibo'l'aflln,gctr.n' drd no engneeringpffspedive.Noronly&e ncloadingjcquncmcNnarcd$sP6 dessnsoalsbur al$ lnoving rhem, p.irri s imponsnLii$lccriig h{d

md |nesy$emdesisn rpprcach phr rhc DuridC ading md resins (eded D rocuson rhos nodules

iMdequm Scvrii duhodscr bc usd roprtdrc'orm trmernd \!!uh Limc loxiins

9 . 3 . i Usinq LoEic a Analyzer
Thc besmerhod trEsqtrg 'lie crcdlio' trmeol.mh odul.{ndrheoyflolt ror CPUuhlizrbon ro usearLrCtr.nil),zer rdvdrlr olltrc luecdut.fl tr '\ O'e hL.n.iermd olhfl dclrysLrarrc nor duc es I1! diutrbrcrr rhd Lhr{rrqm mrr oe .orifL.lc! (or pM',Llly) code'1, ud '. ngcr h.rd\arc mun b. avtrllblc ftur. rlicloSi.drl!zcr is usurlly employ.d oDly r Llrlft nrg$ ol $c .odtngphr\e. dic hnrn! phrsc. md*pedrl\ dtru-qrrlen inLelntron r los'clii y&r lor riminspupDs\ '\ dtr.trsld in ChqrE. Lt

9,3.2
rooerlly rDrLhe loer orlyzci or ifone n nol rvritiu.. inind'oi cminins rimetord'nA dtrr 10!qq! !re!utr, rimc ftis cchnL,tue Equrcs ,hd the code alErd), b! !,nLq,, ulL 4 rppmx,nra.on ,he fiml codc.ri!, or rhr sm'lr. ryncn* be xyilrbk for ot 'nspen,onThe rpprca.hsimpl) 'nvoLvflmcn-q LhcloigAL prh rhroulhrhc code, countrnc in!rudion r),pes Lr dong rhesax u dJdinglhen execurion For anyp.rjodicst6'ch.rherorrtLNkereculontrm dn,idcd rhe.yde by h. lbr Lhr n'oduleis LLr rin4loadinglbr fiar ffk In lpo*dic or m'€d sysems. m,{idum lsk execurion rhe ne shouldbc tre(1. kno*. Addig iI thekperce^bgdovd.ll $e rask in fte syreD yrlds Llr rokl lime lodrne.It rN 'me lording.l,n rhe.rde rime(orm'nnum,iLn.bdwcrn(cureDlet toi cy.le Ti iidA, k Lhe rcruil e\ecurion hme.den tor, u\k\ !e have whcr r;

T = ; \
or cou6e.rhe acLu.lin!ruqion (im* aE rc,turcdbcloahind They cm be obra,ned Lnanut fmn cLuid\ dau sheds. [mrg Lhe by insmdionssins rto-s,r oaryzerorsimursLo^. by edu.!rcd gusssins. manufanmr\ ddu \hcds ft or nmbqotw esio. erchnNU uqD' mc nccded *elr. Exmple 9.r r usrres rhecrrcursrions. a

l*r's dor rnelolding inJysisfor rheroftspodinu!ode.

A ,ir?,? riyi,3 conbines$e h,sh{rder rDsuagerns@n,otrwft ft equivaleff ssembly r&eurse in$rucrions6€ros ir for e6y r,crng Fo owine shonly6 a mixedlisriig ror Lif .ode r a e.nedcassmbly languaCc lor. 2 addEs machibe lne ssmbhr and comp,ler diEdives have bc.n omi(d (3ronswft $ne dra dlooron pseudo opsl for clrny and b.caus. ,hey do nd The inshcLions b€siming in F are noadngpont 'nsunnions rhaLwe wil ds.ume r,le r0 -'. rc\aono!. we q'lla...me dllo p nlru,non: m maeE

Tmci.sfte woFLp3hmd cou.rine i.$rucrions,reee rhaLrherce12 rhe inkger md 15 ammg po'nr 'nshcuons for a rord exeurim Lnneor 0.322 nill'*co.d. S'nce pFglamruns'n a5 mrllis{ondcycle, dne-loading rhr rhe is 031 = 16.5%.If fie ofier cycles serc malyzed @ have a rins-loadid8 ^ lq 0m'rh*rold.].le 10.6.dd an-milLssbnd oad'ngror ln6 roregDundr,bockgrund sys *ould be 60 5%. could E lnne loadins be redued for rhis modutc? Id Lbiscxmplq L\c cdpdi$d could havc b.€n nade in tu.d pomr ro savedne. This, how*d'resrric6 lhc tuEe of rhe veiable PRE TAKE. Diar r,

PRE TA(E.ould only he inleser mulriples ofSCALE.If LLr( weF rceprable DMAd values lhevanablesffar rnd dz.The.ompensabon i.ro murns RouLd perfom rll crlculrrons lixed pointrnd {ould conven resulcLonorrne m the As a finalnoc, theprme$ ofinsnd'on coundns be aurcmaEd can ifa pdser is wnGn for rhe larser r$smbly lrngurse rhd crn E\olrt brm.hins

9.3-3Picroridl FepEenialio.
{! u{ J'fr!rcnL hJd'nB .olor p emsror c\claioi l.\.,i, i or
figuR Thq eLdd' ii Lhebo'e5.ore\p.f,d. o Lhe.{usl e dj

rodule. wheE,\ the shadingpdrhs ae used Lo d'ffercn'ie he'ghL orrneodinateuis is lsed !o depiclpnoi,Iylevel Todo urs. dri$ J rimcliie rirh 'im ) ' n r h e _ , e . r u n n g w : ' l - e l " s h e' o n o a . m m - k i n d s o r i J F ! shrde Ue ponion ol lhe rime lioe neededro conpleE rhe ksk. Then rhr ne n-,' his F -.t 'emrmo.nng 1 -L{ bf ienpFd d I c -e JJ'm li \tung v'd

Il$e chm cannol codplercd. 'he sysEn n be $e. us a Gel lor rhcsyr.h 'imerosdi.gandfte s,ves

q

5m0

{*I
rsE e.4 lds dd id $rtluoi r.bn

Lime !r. rlsob. usd ro.ompui.ih. voGL.rseresPon\e tura rasl on LbLLo'al. secron in p*iodic s)_nenrTh,sL dNcu$L'l'n. \ubsr'lucDL Dr'epE*nhrionalsoN. Thtr LtTe msimum inLcmrf lnlEDcL.s r.e kno*n monoronic sy$emit Lhe

Execu[on Tlmeslmulalors 4 Inst.uclion
The calcdruonol ,nirudion ri'ncsrequtr$ more thm jlr rhc inromalon memory drr ilsodcpcndenlon \uppl,ed Llre n CPUndntrfacLuefs bools.11is by rc.e$ hnrs rnd wdr ilcs Ll'!' am dek.mined the ove ll sysemdessn Some.omDanr\ thd tcquciLly dcngn ph'fonn\ ur nnuladonproshrn\ro f €d'cl'ndndion ere(ion tine a0dCPU rid spccds. an nrn en-qme{s crn ilu 'he cPU L}pe,memory Lltroughpur Strch in$rud on Dnx, rnd .alcukrc Lorrl in{rucron imes rnd rhroughpul ava,lable arc senerillydifll.ulLLownE bu( may be commncidlly sinularoA nfles. The wosl rodi) havc wde vrrirs erecurion bc.au* mo! machiner phich 'he se'luerce lbr m&hin$ a RlScarchrccrures ermples &e p'pelLned in\ftcron rim g. ol innddions innuences cm by fte shon sedions code bedmed reddr,S \y$emdock befoEand ol be ro code. The trmediffc(occ cs. Lhen mea\ured afierfte exe ion ol Llre normally krA onlJ olexecuuon. OI!ourr. irihc code deLemme rheac'ullrinre d!'de ro $outmd lmes andrhen a re* microse.onds, betrer erecur scvcrdl it is Erorrlere.uliondmcblrhetrmerpe.l.ThntrillhclpLotnovemy'nrc.u .t inmduced by the -lnnulmry or Lhectocl. Il you usc rhh Echn'que,be sure to rhe loop md subradir frcLn roal Ths rcrurlrimespenr theopen i0 !dh!lareLhe is ii,loeous Lo subhcring ftc weighl of lhe plriic cup uscd ro weiSha

9,3.5 Detehinislic Pedorm.nce crche, p,per,nes, DMA (r dengned ,mtrrove md ro average rcat ue per lbman.d denoy d{eminrn andd'us'nrkeprcdrcnon oficllrime pdlomane e$entrdlyrmpo$iblc.In css olcache.lorex.mple, rheinfficdon in dE Lhe h c!.he?whnc ir ir beingltr.hed tromhasasilTi6cdnrer'r'edontheeKe.trft on ollhrr iniru.{ior. So.Lodo worr cas pe'lbmmce youmunrsumethaleven r inrrucrionisnor lekhedliom!&heburlrommrinmemory HoveEr,robnnsLlH insrucrion rhe!tuhe.oneolrhe cx!hereplre.rnL aLcorLhms inro d'icus.d E Chaprer mun be used. 3 Thn hr\ r very deldff'ouseflecron lhe tredrLdi p€ omm.e simirdy ,n ihe case olpipehnesonemus alwaF ssu,ncrha a everypo$,bleopponDiny. rtrpLtchne ne.dso|Jt nu\h.d.Fim]ly.NhcnDMAr presenL'n Lhesvncm. wchivc roa$unc Lhdcliclc(caljngiso!!!dns {ers} opponuriry, nilliringin$iudionlcrh ridcr. lr!s Docs rhismlar rhd thlsc *idcly uicd dlhircclurulcchnhuer render r sy$.m lffcdivelynonbdyzrblold pnlomdnc.?Es*nriall) yes fioweveiE mnking some rcasomble Nlmprions abodlh! rtd imprcrotrhek efectr,sor tu onal rppoximdion ol perlomrce is posible.

IS 9.4 SCHEDULING NP.COMPLETE
Youmayhavcastcdyols.lL why hn r rlrcrc fomuli or rc.ip. for prcdidin! o pe omin.e in nor rtal rime sysomr?" The ms*n is $ar moi $hedul_E probGnsinvolv,ng plobkmr.An NP.?,,r/.? rerl syiem re N? complere solubonsm exponentrai funcrionsor rhepmblem size. su.h solutro's m lor :! solvable, evenon superconpuLen. F nd'n-q r poly.on;l dme solurion ro dre da$ ot NP-compleleprobGnx would rprcd r mrjorscEnnnc prrdiem shiftmdhrve fantNic economic rmrlicamns.Md

have onlvhmdsoltrLio's thd sq!nd\, hovevc(b€l'eve NPcomplekproblcms (burLha, w'll ncvc.berble ro showLhaI) se on crPosti Lhnp.in' [153].3numbqofdsnc Forexample. it,tr ercelGnl hin!\ "trr 4r1 '?q\en hrn'lf or conrenPd NP compleLc is dd (hc |]rohLem prtdi.rl coDnrrin(or conclude probleDr ex.epr rlDl NP r,&/ (An NP hfd pobleD L simihrL. an NP complet eLu'ioncm be lnudd] evenM ciponen[rl Lime lor hc NP hardprobl!tr DoL when rhcc a'e mutoal crdNon .onn(ins i r Lmp.siblc10tind x ronlly on lineop rmalnn limc ihcdukL oI vherhr r LsPo$ibl! ro $hcduk r seL The pmblcmof dec,d'ng Lhar |renodrproces*s u\e smDh l pioblcD wih r*o procesotr.no t schedlling nr mulriprocc$or md evsry usk hav'nsunr sotrr$, dbifary Pmial odq rclarDns, idd&res ihal polynomial pinDl orderreLarion A .ornpudion rimc tr (renexivnylifpo.csn crLhPtuce$ then r. rny troc$ cm callNelf Md theavq* r norposibleGflLsymnerry). I procc$A calh pdes A and proccs a crlls po.cs C. thenpmces A .rn .aLrPnes I The ntrk'fmcesor s.litdllrrg prDbkm wirh ttro poce*o , no d_ indepe.dcnr ksls. and rbirftry .om0ua' on Linesis NPsotrrues.

5 . Tho mulrprocssor{h.dulioe problem*irb rvo proc.soF no re

hsks,fbitn.y Pamdoi{, ind llsk compnr inn 5our.cs. indcpcndenr umesof enh( onco' lso uni( of iine r NP complele Tne muhipo.e$or sch(nlins floble'n *nh rvu po.c$of, one E and source. loEr pmll o s(pinhl ordcron erchproces$r), ea.h r everyhsk dluil ro I untrn NP tompicE. compuoLion ol rine rhedulingpFblem'urh Lhfteor morcf.o.eso^. The nuhiproucsso. i,idePendenL hsks oneresource. ull ta\k f,turl o untrr NP.omplcLe

De

ynie q mr ru n!6r money n \ trh \Jn.m\r

AND RESPONSE TIMES REDUCING TIME-LOADING
'inr load'nc rprelimin4'nep 'n Educm,g waserul compuratron,s ldsnrilyine ooin'zaron ca bc uidt2l bul olher appmacher enploycdLncompiler Many onqr ed to*rd Eal ne svftms 6dr merhols hsveevolved arc sPec*i.all)

s.5.1 conpule slowesr al c_ycle
Alllrocflrn-q should doned rhcdowsli3rc 'hd.M b€ rolcEed checkins be r LeDiperrrure discrtr lbr. hrgc room!r l:$er rlranI se.ond iDy bewasetul. r.r ont$rltr.c ryprrlly crnm{ rhnnge {triclly otri4 ro Lhemal i.cnD.In our trudcar planl ekmpk. r dedi.re.l *nsor is rsed ro monnorlh! Ernpmrue. ir),r rn o!4+mpcnruF tr dqecr.d. S.5.2 Scal€dArllhmetlc IoahgPo'd A\ we srv in chrprer2inr!gqocetrronstre,eLyf'.rlly tr{er Lhan op{r'on\rorDorcomptrle$.wecmmkcadvnr reeor'lls ra('n.ena'nsyreN hyDitrLL'nlym-s'nLe-qes by rva/1/i,./,, LosiLnuhE nor f e poiNopftr'on\ ThE s.lulon Rasore of$e ft{ merhods lorimpllmcnring flL{umbsoFmions In y conipuFr . syftms Hue r llo',s complcncN itrfber I Nd. rl'eLsB (leN called Lh. sisnincanL ol vh'ch is NrigneJ. $de I!.roi uhhh is sonetrn'es btr) or $e numbff (ee Figuru95). ll LheiunLier .qrdnx/,,to

rch in rhe bit)orrhenumber liker sompledenr ese4Lhen MSB (mos significanr rhd si8I bn.Thelages number cm heEpft snrsd rhftwoyh (2' r,)' LSB,rd is rhesnalle$number canbeEpresmled 2' ' LsB. rhd

cbyiF|}4|t,e|.ddo.00lTtrj'6lrunE

a
md scaled numbc^canbe added scaled numben, ssned ds d,v'ded r con$b' (burior snorher by numben b.pe omed in in'cgcr cm compuhrions involving such convened ro flo4in8 po'nr only rr Lr'e lii ncp-3 prcce$

rccu !t i.d oogc ofrbe naled Since LheG m invns Elrlon beNeeD G e iumb* r ndural queiio. rrises: Ho{ d@s one dcrnb Llrcrppropna Lhe granulanryl SuPPose n-bn nu po$ ve Frl nunberThen i qirh wlll rcprcsenr iny.ombrin rhh inewalro wnhinoneLSB For0trDibeB rhe noNynmefi. nnges,selecl iueNrl sidiho buLuse$c hl-efl ol fie 1{o r jequ r o.Bru.e, .r !-td'nsrnL\Borom

Measuremenl Angular 9.5.3Blnary
130"rc rnv anslE $e A vriar on on rhes.alcdnum$r idcauses lad 'hr addD-s then Ttar n [kc 'akinsff lros complemen'. n, iI360'< r < 0" is dn ansre, = r r30'=-J I}n re.h^iqre.cnlled hitta4 ansrtatmtaaRn|nt'l r+ I30" rhe BAM. Norksaslblloes.Consider mor sgnilicMt bir orm, bn wordro b€ Thd rhe lea$ sisnificd bir lEs m sigled a$iged a value of 130 deerees. 2i' ! 130decEes

Th s h rhele l signinon' bit or LSB GeeF gure9.6) L s h , . b r B A M L o d q l F r ' m i n , m u m l s l u e o ' 0 r h - 'i , 130 t 3 0 c = l 6 0 d= 0 2h |. __ E3ch, 6ir wordhs a Darimumvalueol 2' _ 21' ') . l30c = 160r LsB

1 3 0 ' =L S B

md bv rogelhnrd mulriPlied divided BAM.sn be rddedmd submcred Dlegcs, !n'l convenedar Lriela$ d,gc ro ro For poduceroNns poinlrcstrlLs mored.c!@y. BAM canheencnded Lwo youaclf Lhsrfie overflow condi'ion for BAft, or more wods. You shotrldsa fy nmplvMaPl mund o 0 nlnbem pERn6 no prcbkmas $e dngle

A vflarion on the scaled numb€r conc.pl rrbws us ro codPure Elrttuelv compl,cftd luncios Ning mos y fixed ponr dilhme c t,ol-!rr rdrl.r relv on olaconrinuous Mluedlumbon Gd fie narhemdi.al denniionolrhsdenvarve

J'tL'qI 'Itd b. suppse rhslolloqinghmncx*s: rhrr

ThenI G) h cllled dE dsrtari" or /di This dedvtlive d r EPEsnb thesloF of fie llncdon d ut poin! and we cm lse rhh infomd'o. to nreQoliE r tr fuddionardu.lno*npoinrJ bclqeenrheknoMpoinboI|netuncbonarra The nN iep in atply'ng fift €chni'tue is to build a ribte ol $3led DGsG for rhc funcrionusingan anay |narconhins lnc sMple rmcrion p.inb at erh At poinl The vilDs forro, r0 + Ar, md !o on do nor n€d md posibly/'(r) rt rhaL lookuphrcrion.IIrhelmk'ry ro he $orcd in ine kble il theYm buillinb rhe (i.e, rcan opemre moe rn4 ore r$le), lhm |nse v'lE on lundlodh genenc

a The.hoke of Ar represcn6 hdedfl bsrweD dsftd resolurioior L\eflncnot A sened.look_up md FEUE9 7 provid* thegeohe

olir') for ror As Fisure sho*s.!|rcBblecm boused rheinrcQolalon 9.? r<r' <a+ A rbYrhelomula:

lfI(l)

nblc. then rhe ltuk up lomuh becomcs h srso$oFd in Lrre

llr) =Ij) + (\' r/(r) .ne md nonoryloadins Asaindh aprcsenta $deotr berwed

iI provdesfor Ia$ Iuncmncompurorion As a bonuslne look trprableatso md mv smpu'er ro Llre dcsncdvrhe happsns be ons or 'ne soEd values. check thes fi6l ror mplncn'rdonofrhi EchnqF should
l!.e01 con@tria sc shc Lq dt Er i(Br tr ih(4t. d $n(ro) r {h(s).

Ihoory 95,5 EssicOprimizatlon
Ir 6 mpdbr to extenmenrwi$ you compilff and to tno{ hoP tr w'll read rd cenan hish.oder lhguase onsrucb such A care labme.s vc6us nened 'J ve6!s chdacrs vdi,bles andso on A se'orexrensile imeser r\en iaremenB. rcn cascs shouldb€pEpar.d for rhehish-oder lmsu.se in que*nn b erpo* 6e indcaies or lhe codp,ld

chlP9rsFhoItdoD]UeArolylnUdoA]n*iq

Morcovcr$dny ol rlr Lcrhihucs uscdin codeopdm,zaron undencoc 'ne facr 'h,, i" siy uiLinELiccrplc$ion rhcr n no subnilure1or sood infoftm' ro rfonnoh@ any ilsornhm or expl$son o crlts suchas rhos.tharcompusexponen trls, squrE .oos. ruroiom whco po$ibre ro enhmm Finally. monof c .odc opLi'nizarion rcchniquesusedcomp es cb be by 'o inrprclc cal'rinc pedombc. Olen d*e irats,es w'll E clplohd e'nploy.ditrvhiblyby rhc cof,rpilcr. cM bc runed on or of w,$ compil.r or dtrec'ivs or swiichcs, yotr sholld knos ahilh on* ae available. , bur Ir pm'cularsra'egy norbflnBu$d.youmaysanrro implene nyouHlfar dE 6 h'gh{d* or a$enbly lxnCmgc lcvcl. Letir bricfly. rhci.cx,mincsom!.ommonly used oprimizatr rechn on 'tlu6 and rheirimp$r on rcalaimsp€rrom.ncs. Compiler opLmrarion rechnqus

r Useol aidnc c idcnrnics r Comnon subepresion elmm r Usc oI intiNic lhcrions on

r L.op inducdone[nin ion . Uss oI eghE6 md cachcs r Flow ofconrci opLimizdio.

r Derd vdiable eLinimtion

r Shon rftln

BoDlNd.od!

tranl orrhese rechnrqu.s |lcilirltedtualgL ie use Btrh.k allui:tnur nF o1
:+''.d rgxin$kno$np tms rlrL yieldol trm'z on opponnitiesrhef oornnzrron aid ft . opLimizfts exsyro mPLemenr dlo* lnl muLLifle

u\e should d$me 9-55,1 lrscotA.ilhnedcldcnti(iB cood compilea bv For .\rmPle. mul'iplicrtron rlt Lic idc il,es ro eliminr€ u\ele$ cod!. erecu'arJ non by conydfl l or rddnion theconsrml"0'iholld bt elrmrnd.d !odd.AxhoughLhismay seemdvirl ind vodd no.mallybe lvoided bv LN fron Lh4ecrl.DhtroD\ pFgmm'neilhe u* of symboli..o.iin^.an obscure

in 9J.5,2 R€duciDn strenglh ,e?dr.r,, ih ra,.(J, reler b (heuseol fte lanc$ msconnndion po$'ble Lo rconplhh r 3ive' crlculrLionlor will rcplrcenulriplq or or xn inEgd by horh{ enmplc. nmy compileN Sh rE olshin in$rucbons. l inn crions inrcs* rhd n a povn ol2. by a senes Lirn inreAd irll'plicdion Lrpicrlly frsEr lherF d Insomc.omp'tfls,chmlddvanabks mdyloadedm resir1e6, rhLr i( r|DL.rLculiron\qr re 'nLegervdablcs ftn maybebecausen Asumcn are 'he pkce involvine $ese^, wheicrshoseDvolvinscliru(fts lnhkeq cre wherher vrirblc $ould be r.hanckr o. I tilen in decidinC shoDld therforcbe divide innddions Lv0'callvoi.e lones FudhcmoE, i n well knosn Lhar bv nuhiply insn.'ions Henceir nry bc bctr.ro mulLipLv Li. Loerellrc rhan For rciplocd of, iumberrhd ro divideby rhd ntrmbsr cxmPk, r t 0 j \'ll be fsrer dli r2.0. Mmy conpilen w l nol do $is auron icalv

cd.lhuoN or 9,5,53 Conhon Sub€xp.AsonEltnination Repeded equdions shouldbe anded dc sanc subexDE$ionin LBoditreknr

c h J p' r t h m r r d l m r n ( M i r . i . d d o r n x o i

'hm ord'mry lurctror. /,,irr./tnfl',nr arc simplyma(os Rhffe rherrul rund,oncaLLF repli.edb! 'n hne.Dde dtrnn-s coDp'lrtron llrx mprovs ft31 rft peformrDce becru\e rhe need Lopr$ pmmeles, ftde spaceror lmal

9.5.5.5 Con{rnr ftrding

pfffonnconranlfordfs, bu Von comprrer

would be oFnnhd by fordins 2 0 3 4.0 hro 3 0 PerrormLng operrtron Lhs mmuuy lcadsLo.odc LLM| esi* o deb is becausrhepmsmmner penoms rheoptrm,zarion explichry. drtDueh Aid tE ongind lalenenr may be DoE descriprive,a comrrd cm be prcvid.d b fo' "rmp-. 'f \o. . n D ' - c o r p u e d d - g r h r i n :i d l t r : o n p n n n o r y o u - ! o d l h c r o r e i . r ' m e 4 xample.pidrv_2.Thhwillrypicltly srve lloaring po'ntload mdone floarFgpoifl dividcin$ru.riod-poknridlly reE al 'ime cycle,rhh caotcad'o Lincloadi . a { n g . o f 0 . . ! x, a - o . o , n s . h, o - n i r v . . J n 8 h h x # 3 ) r c ! . ^ i t . u J r s L inveneFldionsh,p berseen lme md memory lod,ne-you havcjus ed emory Lo$oflhe prccompu@d con$dl 9,5,5.6 Ldoplnvrisn(Optimizarion Moycompile^lill ftovcc ed ro b€perromed wrhin rheloop, p a cdlledlaap invaiont apitntzanan

e-ji-

lonp Induitun tlinindi"n

\'

rbl. i ,d. na,i'.F- 'd' i

vh,.h is l lid.m rrm'ion orj, n u\edLoolLsd r:. tr i rnd anorhervlnable.r. onLy x ren oflool Lcmii o'.we.rnse(nd lol nd. r.ny. ofL.n ' is used ts bj ?plrc'n-q k$ lor oF onr.

m rnd Ciches whcn p.ognmmins r$embrv 9.s.s.3tse of Resisrers rcsF,e'typevtirblcs. srh rs c. langu{ges srp|]on rhd l$-qur-ge, shen uslng or n r usuallyidvlnheeou\ Lo pedonn.rlculalonsusins rc8isEs. TvpLcallv .e-qf€rLo msmory otresThus.'f dc rsFreFLoEsisLdopeErons lisEi Lhan m wnhin nodule rnd iI enoughie-qLne^ you shouldtry ro r.r.e rhe .ompiler rvdldbls, whenpms mmiie 'n asemb\ lmstris! innruc ons.ordo rhi\ explicilly lr rhe pm.esdr t.hiEnure sWP po$ible b f.(e rtuqu.rlly usedv&iablcsrno Lhec{cbe d rho h'gho.d( co'n0r.N \rl levd. Aldoughmon opum'z'i,g or bneuage b$mbly hnem-se po$,hle,Lhe nlruc or dt sou(e GYel!od! rffefl\ Lhe vmJblesuhm cacbe 9.5i.9 ReBov,l or Dead 0r linrca.hrble Code Oi. or Lie ersiei nedods for decFAing mc'nory ! Such be cao .ode-dE r. ccderhdr never rt.chcdIn rhenomd now_olcon@L

flas is ser,0r only $dem!nis'hrt dc erecuLed 'f r debug code nichLbedebuc iniruc'ion\' For exmpk. .oisder $s followns c Edunda $ridizxron

The Ler o1the vmirble debus'*ill Eke seve l ml.msecondslne rhir s Esilnl.s oI sherrer or nor you ft in debu-smddc. Debug code consuned compilerrcilirirsrvr'lrble sft lsig rhe .ondiLrcnal shouldbe implcmencd ei'h replicc'he pEviousliremenr Thus, comprLe6. * should nos lansuase

s HeG.*fde1is, onPitd dne ve rhar l n.ludsfie codebd!'cn nand'hr con$ail DEBIIC is denned nd irend only irrhe symbolr Dsd co; remoql also in!€ass proErm Elrabilirv Gee ror *

In OpiiniTaLion nov of contoloPrmitad@ Flow-ot-CoDr.ol 9.5,5,10 vatnd bv m sbremens replrccd a sinsleJump to-junP unnece$aryjunP 'fte follosing prudocod. illusnfl$ thesnudion

nomruy Cenenrdb, psgrmme., bu misntEsuXfn code noL is Such soms ,ubmdic 3en.B s or rdsadon prccs andes.p€ umoned

sbLemenk 9,55,11Consrjnt Proprgrlion Ccnainvaftble sxsiSnmenl -sr ei d 01 rhcRbqrr.ing lan be chargcdro or opponuniries rheuseolmmcJiirc odct.

[qccdlFillircdb}xmmrfl|?h8onP'on'giL

9.S.5,r2 Dead-Store Elin'nriion Vtuiiblcs rlrar conn'n rhe sme value kmpdry vanable n a shonPEceof codecm beconbinedinrod singie

9.5,s.I3 d-Vrr'$le Elininalion A vmrble r live ar r poi in a olheN'r tr s ,?darndsu6jecl io F oenmir6 vrluecm betr$d\ub$qu.nLly:

while ftis exanpl. appeb Loberdvidl.dgai.iL.ould code ornrdrlion codineoion atrLomated ssncdrion

BoolenCude $t cadoptinh 'he 'e$ingof 9.5,5.11 Short.Circuiling by re$ing erch compound Boolem cxprc$rons

Th4 js, n r 'nsde rhe 1f md dmpsour 'Ie finr FALSE.ondnion. circuir Boolcan code. auronrcallyshon
duplics,es shbhent et 95,5.15 Loop Unmlling Lmp unrolling in oder Loredu.e fic numberor lmp remrions md hen.e the in a looD
ovederd ffuftd. ln $e exogg.BEd c6e. me bop ii conpletely Fph.€d by

IOl/

o/

q\sl.c

fonr!.F

ceqL.n'i

. r h eu . p o \ " h e r d o , f

roo

,e"

9.s.s.r6 LoopJ,mmins Looptm,n,ns roop o. furioris o kch0ique tor co,nb,nrng {m,rr. roofvnLo rhus r*o one Fdu.ns loop overr,ead r hc,orof by r*o Fo.example. follow'ng fte Pasrl code

apF$s 'n mor rh& 9,55 I7 Cros Junp ElininarioD lr'he sm. code Thkelid'naEsanadd onalJumporcrosJrmp Forexmple,Iherollo*'ng.ode

9.5.6OtherOplimialion Techniqu€s A ihpling oforhcr imrrLonconndflrloisrollows oD
Oprimic rhecommoi.usc.Thc frcqucnrly pdhrholld alsobr mos uscd 2. Amdec a scri.sor IF $aemennso rharrhemos likelyvalue

Lharrliecordidon'norl'kely Lohil ArinBcascricsorANDcondirionsso irrs!.dfi .(Adxre.ORcondtuonssoiharhcmoslrkelyrorucce rsed fiAr.Thisrcdmiq!! ir cdllcd Boolcatr slion.circuiring.) rhar Arbg€ endesi. a Labl.so rheno$ kequeoLlysoughrvalu.s 4e de lid Lobs.ompmd (thh echniqueislu$avada'ion oI3,above). (contrnuously rhrcshold kss on monorone 5 Repldcc nond{reastrB d avoiding noninsrc$idg) luncrions Ess on 'hetrpr.mnss. rlrcEby by vhy evdhdrion olrhc fufdion. (ForeraDrple, uscrhccodc.

Link rhe mo$ lre{tusmly used piocedu@sLogdhd b m*imizs LLr locahLy ofrefeEnce. Ghn only lppliesin pigingor c&hsd synems) 'hd de uscd Srde Jdd clemcns concurenLly DCcrhd('o ncrca* rb. locolnyor ftfercne: rsa'n, rh6 only rppl'es in paB'ngo! cactud

proc.duEs sequence rharcalling calledprocedtr'$ lD and villhe 3 S'orc so (Lo loded LogeLhei incEde rhe locriLy ol rcfeEncei aefln. h^ o0ly applies paging in orc,chedsy$emt

rill crse. rhe Nore in mo$.a$s rhcse rhd Echniques oprmize aveEge rhe nor

Alrhoughmany or rhe optrm'amn Lechni{tues siven i. iht rexr cm be au'ornared. naiy co prlen perlonnon\ one opdDnz on p$s. overlmk'ng unll alLerr kN one pa$. Hence hrDd oppodu.iresftr' &e DoLrcvealed addnional erectrtroD $v'n3s Tose rlreeltecLof rme op'imizarior prcvide cqn conndef rollow'ng rhe erample. codell-gmenr The muliple'pss opLiLnjza'ion.

a r r r. a r j r+ r ' x

'nvrnmtEmov md.eDovalofexrnneors is imprcved roopJaNm'ns.loop by (inLhis code ca$ rh. iri'ialzr onof alrt).rhe re$r'm' codeN

Nex( loop'nsunoll'ns y'elds

cMp,.synenPednmsltAm|ynsltoFinldhi cotr{ant foldns. rhc 'mPrcvedcodc 6

Jlu num'rous ulbPlicdrions Theoncinslcodeinvolvcdn'neaddronsandnnc onlvsir rc{luics cod' rhe inprcved *o t".p r"'-"."", -""".i"i "'e'heids rnJ nn ooo ovlherd I ' erJ \ ^do 'o .. o- m rl + reDn ri op 'n aro1 -ouro rv' bee ab' ** , -'pi. ,ii a, " srh ro mrke". an imPsvcmem.

fieculion 9.5.4Speculative
Edue (Reall d 'n PiPcline comp ln fte cse or L r$dcrions fsfl an idle prccc$oropridrricixt on involves r pddllel Proct$ bldck as longas thee; Jck on 'ode rhd could bc nnning on ok

10 Limes allowsidle timc md rcsPonse naxyis iocuded nNbingl ba.k (asin PiPeline FEOUIREMENTS OF 9.6 ANALYSIS MEMORY
marvss Wirh memdry bsoming den*r md cheapc( meno'/ load'ng u$ is mPdtn i' maiv airbofte sritt, ire *..-" r"* Jr ..*". "tr"iem cons " po*er in sysemswlEre savmgs space. Lo w. dicus rhis norion wtrh respecL d Lhe - ahnoueh rsum.nb irc spplicrbero Jlreahime sJeems ':dcmer'G ro ttlre didi i,^i r '.. ". .m - udh o ohl ,* ') , ^ i . "i.r.. . . * . o ' o a m m e n o l l n o R A M m ' ' "':"* "too' D\'LArocrr'on rism c;,o_] mlDPed r.", tc i." mt, map. a illustares IYPE msmory

monory thc is The 'oal memory.lord'ng Lvp'callv sun of L\sindrv'du.l nrck, andRAM rcis for lordin-q $e pmsmn.
U ) = M p P t + v R P x +M \ ' P s lordl semory loading Mp r'tr. and Ms re rhc menory_oad'i-s shere M/ tr Lhe and ror rhe 'mpram.RAM. and $ack areA ftspccrivelv, Pr' fr, and Pr arc 'tc prcq ' RAM .no hr r% oe'.m ds)-o ur' m-tD illordFd t .ut% tu' vP i. *".*rr q"... bc rF'ouLlo.r'oqeq rdrfl'1' propenv di\ arecrcdfl ftin 100r.,rhenrhesv$emcannolopemrE

RaM;..d."bd*"ia

hd,r *

Yoo will se how ro cslculrte MF Mr, md Mr shonlv.

M€nory l/O Memory-MaPped snd DMA
l/O.nd DMA memoryr 'k ffid' We dD nor Ddudc memo.y_d.pped Hoq'\er e' lrs 9.12,snce lh.v m fixed in hrd*ft lo.dineeotrdion -emorv lo.srions ror rhe$ pu4cd Fidi ro l*l; d'; -inim"- .'-uer or " $e job dones,c $m. mon for sowdr' Thx IFA nemoo ann'M id d' Cfl mtre dyianrc memory mas

cmfillv RoM vhidh.or; n\ rhcrrlrrkble ndtrdrng onearDs srrun rM rfpli.ar onr fte h cm he nored'n rhr arcx Hcm nicmory-

{hfleMi,x'heDemdr''o]dmgfo.Lhe prog'r'n i.r. L,! n rhe nunber ol roubonsNed m Lhe rs, fd I, Mhe LoulrrrLabk tocarrons rhe ir Pregmm

mry he rortd i'i RAM i'NLead ROM tor of 'nftAe'l leLdnDg \peed rndmodLl' Fr '\ deG.m'ned sy$m dcsietr d trLnc. rhe rord,ng fnor foi Lhrxm ^ ioL d.,e, kd triird,e rppLicliod pogrns hrve been.oDpreLed dy ca\e,rriememorrhr road,ns iacrof be co puEd6 catr

whenM.n $e memory lodinslor rLrRAMtrrer,1,, thenunbrr is u$J in theRAM ma md ?; is thetobl rvr $le loorcnsn Llr Aslin,fiAe nlmb{s c rvtriL$lu ouFu lmm Lhe a lnrei

Tbe ftdrimc operrung ryrem uys rhe iack fta lor comerr savmganri auromaric ranrbh Allhough morcrhm oncrrk.an belepLwthn rhr @ _ir Icon!on]cnL !iE\" irrsconfunin:oily onE. 5i4 oflhe ia.k d my trft 10 Tho is dcp.idctrLon sysc'nt $a'c md Lhc Lhc siz.or rcconoxr5rvedlor dnyoF 'ask.suppor rhecoden for anyr6k rqtriresr Do$." locdionslor rc8ideK proemmcounc(au,omcMnablesmdsoon,andl,D!\Lhem:xiDumnumba of rask\Ihr c4 b€ on Lhe ni.rc drk dc@mindion-if $ck d sr Lime(Yotr n'c, inenncannolbe kooqnor gu4sn@ed.l

4 -,i

/-*

Hence.Lie memory'loditre fdor can be compured 6

(9.16) nmb( of Loririons \her,{r'r ir th! m.Nry lod'ng ld $e nr* ri$. U{N Lhe 'nd rokl Nrl.ble usd in rhcnrlk aroa. I A Lhe

MenoryManagement Schemes
rL\o shonkr .onsid.ed r In rhe b! The d*.usnns in rhc rdl'n! s.ctroD disttr$cd D chrpLe' 3 Fbr conlexrof rhc mcmory \heft lour nbtLnrl ba'k\ m usd rhe scheme erample'n a bank+,lirdrn-q maly{\ is rpplicdtu ctrd,tparrle ntmory bxnl.

REDI.ICING MEMOBY.LOADING js $m n hr bc$ t prcvroNy nemory.loldine e$ ot aproblem A\ mcnrloncd ro rheprr. bur occsFDrlly r \y{em needs bc ds'gnedn shrch fie .viihble mainmcmo!_h nnrll 'n rclrrcn Lorhepogon nz. lordin-! doc lrcD r riDe *hen ftmory {i\ d r dercloped rcdrcr rnemory rc Thu\ prumiu rid nn-ghr v,olde rhs princifle\of sonwm ensineerin,s. thll be shouL'l u*d wrh c rion.

Memory loadLncm one arti !M br rtduccd ar Lheerpens ol Mo'he. For vri$l$ (vdahlesthr arclool lo pdedurct Increase all example, ruromaric rheloadms rheiack irca olDemory,sheE^ slobd v..!bles appe,i'n Lhe rn RAM rea. By lorcing va ablesro be enherlo.al oi global.telier crn be rhusbalmdng lhe oI purchased oneeea ofmemoryr fie expenre rbeoLher. in 'h,, 8.e conPured explicnl) rerulr.ilculations h addnioi. inrcnned,at on ir Equnen lanablccirhe n $e nackor rheRAM ,€a. dePend'ns wherhtr a vrluc catrbe rorced mro a re-lister iricud by globrl The 'nLemedidc loraLor lhe P!$rl cilculation. llu$me, consider following To omirrirgrlE inEmed,are

chPcr\.nP.domucAfu|l\5didoglmtr.ion

9.7.2Reuse Varl.ble
Globrl varidbles rhar 3a used only once sy du ns rraramn_cm be Eused bEr lor orher pullo*s unlonumctx Lhc rtuirhle!4ne\ns, Deemer mxhodinsor sene.csince 'hcy wi be ptry,nS dud rcle.An exanple rhr a of mel\od h rhc se ol namedcoMMoN ovenaysif FoRTMN. you qanalsouse rhr mc'hod loop.oumesfid de seneric for Lnnoru..burbe.mrut,o prevenr , pmces iiom desnymg rhe.onren6ol r vrBbt. whenrharvrkbtc is rko bsinsusd by anorhe.

9,7,3MshoryFEgm€nlation
Memory rEgmenbron (dis.trs$d in Chaprer B) does DlL rrlNr mcmory loadme. i' crn produce bu' etrecb r*m blingmenDry.ovenoad,ns. ctue, rD,bh alrboogb sutricisnr memory ava'lablc. ir nol comiguous. B ir Axhough di$u$ed conFc'ton lchens m Chaoler md poi,ncd se 3 our Lh lhey*eEDordosidblern L'mesynems, maybc.e.esary,n sedour real they cdes oI vduol femory load'ns. 9.7,4 S€FModltyhg Cod. One nerhod Li,r can be usedro savespa.e in de .ode arcaof memory albeir an eiEnely dlnscrcus md ricky one-is lhe s?t:,,/iti,s .d?. Thr Dclhod Exes idvanage of fte ld rhd lhe opcodes cenain 'nsrucrions may dffer bJ oI only one bt. For example, nrpprs a bir in a JUMP in$rudio., an ADD by 'nshcrion is ccrEd Allholgh $il rypeoI prcgmming nsuilty rises Eoh coiicidcn@, lesends exh, abourpmslmnen who could rri,c $cn cm efronlesly. The moi 'mponm' disadvmrase suchcodingis $a' n ursrcys ft or pngEm\ derminisn. Th6 Lytc of proglmmmg r rlmo! neverdoncDday and NO|E 92 Mny incllde on{hip c@na har @ obvi,@slf-froditlng cod. (rhc cachedoesnor npdo's rhecodead .x@urasl}. u.mod,n.d codc) or $e etrecr ot monityins cod. wirhin

{s one @rromm.e drc3LhrL cmnor .ov4 ir sreardeprh(ow'ngro derce InmrnJ b . d e o f e n ek p ' e e I t b \ d r \ i n o d e t r et o d c " o e o e ; d r- . ' q* . o,r ' O i. rhc \-L.e CFr-{ .!' i b 'n' ro pro a,i e o's rdd' on a vhen andyzing svsem\ p{lomance rhroushfrrucboncountng, Morcovea il is very dirficulr Lorccounrfor drskdelic! a.ce$ rim* ln no{ cse\ 'hc b€d ii lppnrchis t rsune {d$.Ae acccs ns tordevi.cI/oandiDchdc'hcm your Frromsnce pEdicions liem Pmicipah in somerom of a mr nd*ork (LAN), loadng rhe nerwo* can siouslv nelwo*, sry . local ol dedadc mlrime Fdommcc srd mdc measuement thar perfomm.e wc med to a$6s rhe Peilomince ot fie sviem i4o$ible. tn mosi dsi ben posibl. $ale (ie ba troofter uses)' Nrlninc rbd fte nerwo* is ii Lhe Thc. nex\uremcns of psfonihce cr bc Eken under v.rving condrions or l@ding, md , perromin.c cuee can be generaled EXERCISES

by rdk e r (vnh cqq !*,rch ,ior isnoEdl rr) DBw u qau otr doe re In $ rysbn 6) whd tr de $i.m un'hdhc (cru uiidLbo) I&b/

cfup0.\'L.nfutroDI(\nJ])!5Iio9'mPdon