资源描述:
《Writing a useful program with NASM》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、[WritingAUsefulProgramWithNASM]byJonathanLetoVersion1.0-SunDec1717:46:38EST2000[Intro]Muchfuncanbehadwithassemblyprogramming,itgivesyouamuchdeeperunderstandingabouttheinnerworkingsofyourprocessorandkernel.Thisarticleisgearedtowardsthebeginningassemblyprogrammerwhocan'tseemtojus
2、tifywhyheisdoingsomethingasmasochisticaswritinganentireprograminassemblylanguage.Ifyoudon'talreadyknowoneormoreotherprogramminglanguages,youreallyhavenobusinessreadingthis.ManyconstructswillalsobeexplainedintermsofC.YoushouldalsobefamiliarwiththecommandlineoptionsofNASM,nosensegoingoverthemagainh
3、ere.[GettingStarted]SoyouwanttowriteaprogramthatactuallyDOESsomething."Hello,world"isn'tcuttingitanymore.First,anoverviewofthevariouspartsofanassemblyprogram:(Fortersedocumentation,theNASMmanualistheplacetogo.)[The.datasection]Thissectionisfordefiningconstants,suchasfilenamesorbuffersizes,thisdat
4、adoesnotchangeatruntime.TheNASMdocumentationhasagooddescriptionofhowtousethedb,dd,etcinstructionsthatareusedinthissection.[The.bsssection]Thissectioniswhereyoudeclareyourvariables.Theylooksomethinglikethis:filename:resb255;REServe255Bytesnumber:resb1;REServe1Bytebignum:resw1;REServe1Word(1Word=2B
5、ytes)longnum:resd1;REServe1DoubleWordpi:resq1;REServe1doubleprecisionfloatmorepi:rest1;REServe1extendedprecisionfloat[The.textsection]Thisiswheretheactualassemblycodeiswritten.Theterm"selfmodifyingcode"meansaprogramwhichmodifiesthissectionwhilebeingexecuted.[InTheBeginning...]Thenextthingyouproba
6、blynoticedwhilelookingatthesourcetovariousassemblyprograms,therealwaysseemstobe"global_start"orsomethingsimilaratthebeginningofthe.textsection.Thisistheassemblyprogram'swayoftellingthekernelwheretheprogramexecutionbegins.Itisexactly,tomyknowledge,likethemainfunctioninC,otherthanthatitisnotafuncti
7、on,justastartingpoint.[TheStackandStuff]AlsolikeinC,thekernelsetsuptheenvironmentwithalloftheenvironmentvariables,andsetsup**argvandargc.Justincaseyouforgot,**argvisanarrayofstringsthatarealloftheargumentsgiventothepro