资源描述:
《在vc 中使用内嵌汇编(using inline assembly in vc )》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、在vc++中使用内嵌汇编(Usinginlineassemblyinvc++)UsinginlineassemblyinVisualC++First,theadvantagesanddisadvantagesofinlineassemblyBecauseoftheuseofVisualininlineassemblyC++doesnotrequireadditionalcompilerandcouplings,andcandealwithsomethingscannotdealwithVisualin
2、C++,andcanbeusedintheC/C++variable,soitisveryconvenient.Inlineassemblyisusedprimarilyasfollows:1.writefunctionsinassemblylanguage;2.codethatrequiresveryhighspeed;3.directaccesstohardwareindevicedrivers;4.initializationandendingcodefor"Naked"Call.(.//"Na
3、ked",tounderstandthemeaning,butdon'tknowhowtotranslate^_^,probablydonotneedtheC/C++compilergeneratedfunction(fancy)initializationandendingcode,pleaserefertothe"MSDNNakedfunctions"instructions)Inlineassemblycodeisnoteasytotransplant.Ifyourprogrami
4、sgoingtorunondifferenttypesofmachines(suchasx86andAlpha),inlineassemblyshouldbeavoided.AtthispointyoucanuseMASMbecauseMASMsupportsmoreconvenientmacroinstructionsanddataindicators.Two,inlineassemblykeywordsInVisualC++,inlinecompilationusesthe__asmkeyword
5、,whichhastwouses:1.simple__asmblock__asm{MOVAL,2MOV,DX,0xD007OUT,AL,DX}2.addthe__asmkeywordbeforeeachassemblyinstruction__asm,MOV,AL,2__asm,MOV,DX,0xD007__asm,OUT,AL,DXBecausethe__asmkeywordisastatementdelimiter,youcanputtheassemblyinstructionsonthesame
6、line:__asm,MOV,AL,2,__asm,MOV,DX,0XD007,__asm,OUT,AL,DXObviously,thefirstapproachisconsistentwiththeC/C++styleandhasmanyotheradvantages,sothefirstapproachisrecommended.UnlikeintheC/C++"__asm"block{},{}"willnotaffecttheC/C++variablescope.Atthesametime,th
7、e__asmblockcanbenestedandnestedwithoutaffectingthescopeofthevariable.Three.Useassemblylanguagein__asmblocks1.inlineassemblerinstructionsetInlinecompilationfullysupportstheIntel486instructionset,allowingtheuseofMMXinstructions.Unsupportedinstructionscanb
8、edefinedusingthe_EMITpseudoinstructiondefinition(_EMITinstructiondescriptionbelow).2.MASMexpressionInlineassemblycanuseexpressionsinMASM.Forexample:MOVEAX,1.3.dataindicatorsandoperatorsAlthough__asmblocksallowdatatypesandobjectst