Introducttoi6 o4n BitI ntAesls embly LanguagPer ogramming foLri nux Introdutco6t 4Bi ioItnn tAesls emLbalnyg uage ProgramfmoiLrni gn ux RayS eyfarth Octob2e7r, 2 011 RayS eytfha r SchoofoC lo mputing UniveorfSs oiuttyhM eisrsni ssippi HattieMsSb3 u9r4g0,6 USA SefyatrhR,a y Introdtuo6c 4Bt iiIotnn tA esls emLbalnyg uPargoeg ramming Includes index. ISB-N19387:1- 646040733 ISB-0N1:1 466470038 @2011Ra yS eayrfth Alrli grhetssee drT.vh iwso rmka y bneot trn aslaotrce odp iinew dh ole ori n pwairttht ohuwetr itpteernm iosfts hieo nc ohpoylrdieegxrhc,te pt fobrr ieexfc eirncp otnsn ewcittirhoe nv ioersw csh olaanrallyy ses. Preface TheI ntCePlUa rchitheacestv uorloevv ee3drd ecafdoremsa 1 6b it CPUw itnhom emoprryo tetchtriooaunp g,eh r wiiotd3h 2 pbriotc essors witsho phisatricchaitteiednc ttthocue ur rersse enrotifp e rso cessors which suppotrhtoe l madol dle so peorfa itnai dodni ttoaig orne aetxlpya nded 64b imto deo poefr aAtsisoenmt.be lxyt btoeontkdofsc o ust hoheni story angde necraolnlcwyli utaddh ei scuosnts hi3eo2b n im to dSet.u daernet s introtdou ccteohdne c oef1p 6tbsi C tP Uwsi tshe gmreengti asltleorwsi ng accteos1 s megaobfy tienm teemronrTayhl.i i ssa n u nnecefscosuasr y ont hpea .s t Witthh xe8 6-a6r4c hitectiusar lem oasct tho emrpeld eetpea rture formt hpea st. Sreeggmiaesrnteetes rsse notbisaolallneymdt o er ree g istuesrai gsce o mplgeetneelpryua rlp woisteth,h g el areixncge potfi on three psetartli-onogwp hsi ucshse p ecriefigci asnthdea rvnseo o perands. Botthh ecshea ncgoenst rtiosb iumtpeal sesre mlbalnyg upargoeg ram mmg. Thearrene o w1 6g enepruarlp ionsteer geegri wsittehrf sesw ap e cialiinzsetdnr .su Tchteia orchaic straeocgftki h s8et0 e8hr7a bse en superbsyea dw eedl l-ormgoadnpeirlzo evdi1 d6fli onagt pionigrn etg is tewristt hhfl eo atpioniignn ts trufrcot thiSeoS naEsn A dV X exntseions. Inf atchtA eVX extenesvieaonln lsao t wh roepee rsaynndtw ahxic cahn simipfclyo dienvegmn o re. Overtahlxel8 6-a6s4s emlbalnyg upargoeg ramimssii nmgpt lahenr itpsr edecTehsdeso omrinsnt.ma odoefo perawtiibloeln b 6i4wt ist hin af eswh oyrertas T.o getthehesterr ends iniditits ci amtteote e atchha t 64b iats semlbalnyg uage. Thfeco uisnt his tieosxn et abrohloaykn dsu-sooef6n 4b iats sembly prograrnTmhmegir.nse o 1 6o r3 2b iptr ograamnmtdih ndegi scussion Ill PREAFCE IV oft hhei stofcoruys eids on tehxoepr lioagftii hnnoei l rndeg g insatmeers antdh fee nwo n-ortfheouagrtoeonsfta hlie n strsuectt.i on Thien teintstogi e ostnt udiennvtoswl ivtuehsd i tnhge assembler yasm antdh ged dbe bugfogrmet rh set aTrhte.ar reae s signumseinntgs the compufotrmet rh vee rfiyr scth aeprNt.o etv esratyt emweinbltelf l uly underasttt ohotidis m beu,tt h aes signamrseetn ptiosls ls ible. Thper miary tfaotrrhg bieosto i kbs e ginansisnegml balnyg upargoe grammaenrfdsro gae nitnlter odtuoac stsieompnbr loyg ramsmtiung, densthso usltduc dhya p1te2,r, s 3,7 ,8 5,9, ,1 06 ,a1 n1Cd.h ap4t er onm emomrayp piinsngo c tr ittiotc harele osftt hbeo oakn cda bne skipipdfee ds ired. Chapt1e2tr hsr o1u5gah rs ei gnnitfilmcyoa red eihpn.t C hapter 15i sa boduatt sat ructausrseesma bnilidnys a n e xcelalduejnncttto styuidndga tsat ruecsit nCu /Cr++T.h es ubjweicbltelm ucchl earer afetr expionas susreeml balnyg. u age The fifuonrac lh apftcoeurossn h igpheo rrfmapnrcoeg ramming, in cluddiinsgc uosfSs SiaEon nAd V Xp rogramming. Thaeu thporro vPiDdFes sl ifdoecrsl a ssirnosotmr aulcotnigo nw ith sampcloeda en edr raatth at t/pr:a/y rsetcyhof.ma/asm. Ifyo fiun d eirntr hobero so okrh avseu ggesftoiirmo pnvrseo me,n t pleeamsaeti hlae u thaosrr as [email protected]. Thanykofu o bru yitnhge abnoIdoh ko pyeo fiun sdo metihnitnegr estainnwdgo hrwthiilnes ide. Acknowl edgernents Nob ooikcs r eaitnie sdo laTthiiosn .bc oeorkt naioies nx lciyeo pInta .m indebttone udm ersoouusrf croei sno frmatainoadns siswtiattnhhc ies book. Dr. PaulP CaC sasretmlebarln'ygsb u oaogweka u ss ebdyt haiust hor tos tyu3 d2b iats semlbalnyg puargoeg ramHmibison ogik.as f ereP DF fildeo nwloadfoarmbh liwese sbi te.i as1 T 9hp5ia sg e wbhoiocckohe v rs thbea soifac sss emlbalnyg uaangidesa g resattaa rt3t 2b iats sembly langg.eu a Whiwloer koinn gt bhoioIsk ,d iscoverbeydD rasB .r tyraenatt ise andO H'allaorfCo arnn eMgieel laobno huotw g eteka easd vanotfa ge thfeae tuorfet shx e8 6-a6r4c hitteopc rtoudreueffic cei ceondtSe o.m e oft heoibrs ervhaatvhieeo lnpmsee ud n derstthCaePn Udb etwtheirc h assiwsittwshr itbientgt er caosdsPeer.mo bglrya mimnetresri ens ted efficiesnhcoyus ltdut dhyew iorr k. If uontdh e mIanntuetalol sb ien vuaaanlb rlees ourcper.o vTihdeey detaoina lltslh i en struocftt hiCeoP nUUs.n o frtuntahtdeeo lcyu ments cov3e2br i atn 6d4 b iitn strutcotgieowtnhhsie acrlh o,wn igtt hhh eu ge numboefir n strumcatkiieodtsni sffi,ct uoll etaa rsns empbrloyg ramming frotmh emsaen uaIlh so.pt eh arte adtihnbigos o k mwaikaleg l o od starptoii,nbn gut ats hobrotoc ka nncootvm earn iyn struIch taivoen s. selewchtaetcd o nIs tihdee rim mopsaotn rittn strufcogtrei noeunrssae l, but aasns empbrloyg rawmimnleelre t dos tudy tmhaen uI(aonlrts e l equailvemnatn ufarlosAm M D). It hamnykf irenMdasg gaineTd i mH amptfootnrh eir ceodniting tributtoi obtnohsoe k . Ia m indteomb ytC eSdC 2 0-3A ssemLbalnyg ucalgaaest s the UniveorfSs oiutty hMeirsns ifsrost ihpecpioirn tritbout thibioosno sk . v ACKNOWLEGDEMENTS Vl Teachi6n4bg i ats semlbalnyg uhaagusen covaef reemwdi askteasn d erriontr hsoe r igCirneaaSltpa ecb eo ofkor mJ ul2y01 1.In p artiIc ular wisthot haCnhkr Girse eEnveaS,nt uaanrBdtra ndWoonl ffeol ro cating erriontr hsbe o ok. Lastth ank mPyh ywlialfnieds, ,s m oynD sav,i adn Add amf,o r I theeinrc oguermaeanntad s sistPahnyclaeln.iAd s d aamr ree sponsible fotrh ceo vdeers fiogrn boatnhtd h tCehr iesaS tpeab coeo k. Contents Preface iii Acknowledgements v 1 Introduction 1 1.W1h ys tuadsys emlbalnyg uage? 2 12. Whaitas c ompu.t er.? . 4 12..1B yte.s. . .. . . 4 12..2P rogerxaemc ution 4 13. Maclhainngeu. a.g.e. 5 14. Assemlbalnyg u.a..g e 6 1.A5s sembalnlidin ngk ing 8 2 Numbers 11 2.1Bi nanruym bers . 11 2.2H exadencuimmbaelr s 13 2.3I nteg.e.rs. .. . . . 16 2.3B.i1rn ya ad.d ition 18 2.3B.i2n amruyl tiplication 19 2.4F loaptoiinnngut m be.rs. . 20 2.4C.o1n vedretciinmg al tnoflu omabtesr s 23 2.4C.o2n veflrotaittnodgs e cli ma. 24 2.4F.l3o aptoiinangdt d iti.o n . 24 . 2.4F.l4o aptoiinmngut l tiplication 25 3 Computerm emory 27 3.M1e momrayp pi.n g 27 Vll CONTENTS Vlll 3.2Pr ocmeesmso mroyd ienLl i nux 28 3.3Me moerxya mp.l.e . .. . . 30 3.4E xamimneimnogwr iytg hd b 32 3.14 P.rinwtiitgnhdg b 32 3.4E.x2a mimneimnogr y 34 4 Memory mappingi n6 4 bitm ode 37 4.1Th mee momrayp prienggi ster 37 . 4.2P agMea pL ev4e l. . . . . . . 38 4.3P agDei recPtooirnTyta ebrl e 39 4.4P agDei recTtaobr.l ye 39 4.5P agTeal be. . . . . . . . . 3.9 4.6L arpgaeg .e s . . . . . . . . 4.0 4. C7P US uppfoorFrta sLto okups 40 5 Registers 43 5.1Mo vianc go nasnittn atr oe gi.s te.r . . . 4.5 5.2M ovivnagl fuoremsm emoirnyrt eog is.t ers 46 5.3M ovivnaugle fsor ma r egiisntmteeorm ory 49 5.4Mo vidnagtf ar oomn ree gitsoat neort her 49 6 A littbliet o fm ath 51 6.1Ne gat.i.on 51 6.2A ddit.io.n 52 . . 6.3S ubtract.i on 54 . 6.4M ultiplication 55 . 6.5D ivis.i.on. . 57 6.6C onditmioovinena slt ru.c tions 57 6.7Wh ym ovteoa r egis.t.er.?. 58 7 Bito perations 61 71. Nootp era.t ion 61 7.2A ndo peration 62 7.3O ro peration 63 7.4E xcluosroi pveer ation 64 7.5S htio fpetriao.n s. . . 65 7.6B itte stainsndeg t ting 67 77. Extraacntfidil nlgi nfige la.d bit 68