ebook img

Guide to Assembly Language: A Concise Introduction PDF

272 Pages·2011·1.67 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Guide to Assembly Language: A Concise Introduction

GuidetoAssemblyLanguage James T. Streib Guide to Assembly Language A Concise Introduction 123 ProfessorJamesT.Streib IllinoisCollege DepartmentofComputerScience 1101W.CollegeAve. Jacksonville,Illinois62650 USA [email protected] ISBN978-0-85729-270-4 e-ISBN978-0-85729-271-1 DOI10.1007/978-0-85729-271-1 SpringerLondonDordrechtHeidelbergNewYork BritishLibraryCataloguinginPublicationData AcataloguerecordforthisbookisavailablefromtheBritishLibrary LibraryofCongressControlNumber:2011922159 ©Springer-VerlagLondonLimited2011 Apart from any fair dealing for the purposes of research or private study, or criticism or review, as permittedundertheCopyright,DesignsandPatentsAct1988,thispublicationmayonlybereproduced, storedortransmitted,inanyformorbyanymeans,withthepriorpermissioninwritingofthepublishers, or in the case of reprographic reproduction in accordance with the terms of licenses issued by the CopyrightLicensingAgency.Enquiriesconcerningreproductionoutsidethosetermsshouldbesentto thepublishers. Theuseofregisterednames,trademarks,etc.,inthispublicationdoesnotimply,evenintheabsenceof aspecificstatement,thatsuchnamesareexemptfromtherelevantlawsandregulationsandtherefore freeforgeneraluse. Thepublishermakesnorepresentation,expressorimplied,withregardtotheaccuracyoftheinformation containedinthisbookandcannotacceptanylegalresponsibilityorliabilityforanyerrorsoromissions thatmaybemade. Printedonacid-freepaper SpringerispartofSpringerScience+BusinessMedia(www.springer.com) Preface Purpose The purpose of this text is to assist one in learning how to program in Intel assembly languageinaminimalamountoftime.Inaddition,throughprogrammingthereaderlearns moreaboutthecomputerarchitectureoftheIntel32-bitprocessorandalsotherelationship betweenhigh-levellanguagesandlow-levellanguages. Need Inthepast,manydepartmentshavehadtwoseparatecourses:oneinassemblylanguage programming (sometimes called computer systems) and a second course in computer organizationandarchitecture.Withtoday’scrowdedcurriculums,thereissometimesjust one course in the computer science curriculum in computer organization and architec- ture, where various aspects of both courses are included in the one course. The result might be that unfortunately there is not enough coverage concerning assembly language programming. ImportanceofAssemblyLanguage Althoughtheneedforassemblylanguageprogrammershasdecreased,theneedtounder- stand assembly language has not, and the reasons why one ought to learn to program in assemblylanguageincludethefollowing: • Sometimesjustreadingaboutassemblylanguageisnotenough,andonemustactually writeassemblylanguagecodetounderstanditthoroughly(althoughthecodedoesnot havetobeextremelycomplicatedortrickytogainthisbenefit). • Although some high-level languages include low-level features, there are times when programming in assembly language can be more efficient in terms of both speed and memory. v vi Preface • Programminginassemblylanguagehasthesamebenefitsasprogramminginmachine language, except it is easier. Further one can gain some first-hand knowledge into the nature of computer systems, organization, and architecture from a software perspective. • Having knowledge of low-level programming concepts helps one understand how high-level languages are implemented and various related compiler construction concepts. ComparisontoOtherComputerOrganizationandAssemblyLanguageTextbooks Many textbooks on computer organization have only a few sections or chapters dealing withassemblylanguageandasaresulttheymightnotcovertheaspectsofassemblylan- guagethoroughlyenough.Also,insteadofdiscussingarealassemblylanguage,theymight just use a hypothetical assembly and machine language. Although this can be helpful in understandingsomeofthebasicconcepts,thestudentmightneitherseetherelevancenor appreciatemanyoftheimportantconceptsofarealassemblylanguage. Ontheotherhand,thereareanumberofassemblylanguagetextsthatgointosignificant detailwhichcaneasilyfillanentiresemesterandalmostwarrantatwo-semestersequence. Unfortunately,someofthemorecomprehensiveassemblylanguagetextsmightnotbethe best choice for learning to program in assembly language due to the same reasons that makethemexcellentcomprehensivetexts. Thiscurrenttextdoesnotattempttofilltheneedsofeitherofthesetwopreviousvari- etiesoftexts,becauseitfallsbetweenthescopesofthesetwotypesoftexts.Thepurpose ofthistextistoprovideaconciseintroductiontothefundamentalsofassemblylanguage programmingandasaresult,itcanservewellaseitherastand-alonetextoracompanion texttothecurrentpopularcomputerorganizationtexts. FeaturesofThisText The primary goal of this text is to get the student programming in assembly language asquicklyaspossible.Someofthesefeaturesthatmakethispossibleincludesimplified register usage, simplified input/output using C-like statements, and the use of high-level control structures. All of these features help the reader begin programming quickly and reinforcemanyoftheconceptslearnedinpreviouscomputersciencecourses.Also,many ofthecontrolstructuresareimplementedwithouttheuseofhigh-levelstructurestoallow readerstounderstandhowtheyareactuallyimplemented.Further,manyoftheassembly language code segments are preceded by C program code segments to help students see therelationshipsbetweenhigh-levelandlow-levellanguages.Othernotablefeaturesatthe endofeachchapterincludethefollowing: • One or more complete programs illustrating many of the concepts introduced in that chapter. Preface vii • Chapter summaries, which by themselves do not substitute for reading a chapter, but after reading a chapter they serve as nice review for students preparing for a quiz or exam. • Exercises composed of a variety of questions, from short answer to programming ∗ assignments.Itemsmarkedwithan havesolutionsinAppendixE. BriefOverviewoftheChaptersandAppendices If this text is used in conjunction with another text in a computer organization course, thenthereisapotentialforsomeduplicationbetweenthetexts.Forexample,manytexts inassemblylanguagebeginwithanintroductiontobinaryarithmetic,whichofcourseis incredibly important in a low-level language. However, should this text be used in con- junctionwithacomputerorganizationtext,thenmanyofthoseconceptswillhavealready beenintroduced.Asaresult,thistextbeginsattheoutsettogetstudentsintoprogramming quicklyandintroducesorreviewsbinaryonanas-neededbasis.However,shouldthistext beusedasastand-alonetext,thenAppendixBintroducesbinarynumbers,hexadecimal numbers,conversions,logic,andarithmeticinmoredetail,shouldtheinstructororstudent wishtoexaminethismaterialfirst.Whatfollowsisabriefoverviewofthechaptersandthe appendices: • Chapter1providesanoverviewofassemblylanguageandanintroductiontothegeneral purposeregisters. • Chapter2introducesthereadertoinput/outputinassemblylanguage,specificallyusing theCprogramminglanguagescanfandprintfinstructions. • Chapter3explainsbasicarithmeticinassemblylanguage,includingaddition,subtrac- tion,multiplication,division,andoperatorprecedence. • Chapter4showshowtoimplementselectionstructuresinassemblylanguage,suchas if-then,if-then-else,nestedifstructures,andthecase(switch)structure. • Chapter 5 continues with iteration structures, specifically the pre-test, post-test, and definiteiterationsloopstructures,alongwithnestedloops. • Chapter6introducesthelogic,shift,arithmeticshift,rotate,andstackinstructions. • Chapter7discussesprocedures,introducesmacros,andexplainsconditionalassembly. • Chapter8presentsarrays,sequentialsearching,andtheselectionsort. • Chapter 9 discusses strings, string instructions, arrays of strings, and comparisons of strings. • Chapter10introducesmachinelanguagefromadiscoveryperspectiveandcanserveas anintroductiontosomeoftheprinciplesofcomputerorganizationoritmightbeused asasupplementtoacompanioncomputerorganizationtext(optional). • Appendix A illustrates how to install and assemble programs using Visual C++ and MASM. • Appendix B provides an overview of binary and hexadecimal conversions, logic, and arithmetic. The first three chapters of the text require limited use of binary and hex- adecimalnumbers,soonemightnotneedtoreadthisappendixuntillaterinthecourse. viii Preface However,Chapter6requiresextensiveuseofbinarynumbersandlogic.Dependingon thereader’sbackground,thisappendixshouldbereadpriortothatchapter.Ifnotcov- ered elsewhere or it has been a while since one has studied numbering systems, this appendix can serve as a good introduction or a good review, respectively. If one has hadpreviousexposuretothesetopicsinapreviouscourse,concurrentcourse,orfrom anothertextbookinthesamecourse,thenthisappendixcanbeskipped. • AppendixCisaglossaryoftermsfirstintroducedinitalicsinthetext.Thedescriptions oftermsinglossaryshouldnotbeusedinlieuofthecompletedescriptionsinthetext butrathertheyserveasaquickreviewandreminderofthebasicmeaningofvarious terms.Shouldamorecompletedescriptionbeneeded,theindexcanguidethereaderto theappropriatepageswherethetermsarediscussedinmoredetail. • AppendixDsummarizestheassemblylanguageinstructionsintroducedinthistext. • AppendixEprovidesanswerstoselectedexercisesmarkedwithan∗thatappearatthe endofeachchapterandattheendofAppendixB. Scope Thistextincludesthenecessaryfundamentalsofassemblylanguagetoallowittobeused aseithera stand-alonetextinaone-semesterassemblylanguagecourseoracompanion textinacomputerorganizationandarchitecturecourse.Aswithanytext,decisionsthen mustbemadeonwhatshouldbeincluded,excluded,emphasized,anddeemphasized.This textisnoexceptioninthatitdoesnotincludeeveryidiosyncrasyofassemblylanguageand thusitmightnotcontainsomeofthefavoritesub-topicsofvariousinstructors.Someof thesemightinclude16-bitprocessing,floatingpointprocessing,andWindowsprogram- mingamongothers,buttheseofcoursecanbesupplementedattheinstructor’sdiscretion. However,whatisgainedisthatreadersshouldbeabletowritelogicallycorrectprograms inaminimalamountoftime,whichistheoriginalintentofthistext. The Intel architecture is used because of its wide availability and MASM (Microsoft Assembler)isused due toa numberofhigh-levelcontrolstructuresthatare availablein thatassembler.NotethatJavaisaregisteredtrademarkofOracleand/oritsaffiliates,Intel 386andPentiumaretrademarksofIntelCorporation,andVisualStudio,VisualC++,and MASM(MicrosoftAssembler)areregisteredtrademarksofMicrosoftCorporation. Audience Itisassumedthatthereaderofthisbookhascompletedatwo-semesterintroductorycourse sequenceinahigh-levellanguagesuchasC,C++,orJava.Althoughastudentmightbe abletousethistextonlyafteraone-semestercourse,anadditionalsemesterofprogram- minginahigh-levellanguageisusuallypreferredtoallowforbetterunderstandingofthe materialduetoincreasedprogrammingskills. Preface ix Acknowledgments TheauthorwishestoacknowledgehiseditorWayneWheelerforhisassistance;thankhis reviewers Mark E. Bollman of Albion College, James W. Chaffee of the University of Iowa,BrendaTuomiLitkaofLorasCollege,TakakoSomaofIllinoisCollege,andCurtM. WhiteofDePaulUniversityfortheirsuggestions;recognizethecomputersciencestudents of Illinois College for examining various sections of the text in the classroom; offer a specialthankstohiswifeKimberlyA.StreibandsonDanielM.Streibfortheirpatience; andlastlyonapersonalnotededicatethisworktothememoryofbothhismotherDorisG. StreibandsisterLynnA.Streib. Feedback Aswithanyworkthepossibilityoferrorsexists.Anycomments,corrections,orsugges- tions are welcome and should be sent to the e-mail address listed below. In addition to copiesofthecompleteprogramsattheendofeachchapter,anysignificantcorrectionscan alsobefoundattheWebsitelistedbelow. IllinoisCollege JamesT.Streib Jacksonville,Illinois E-mail:[email protected] October2010 Website:http://www2/jtstreib/guide

Description:
This book will enable the reader to very quickly begin programming in assembly language. Through this hands-on programming, readers will also learn more about the computer architecture of the Intel 32-bit processor, as well as the relationship between high-level and low-level languages. Topics: pres
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.