資源描述:
《mips快速入門-入門指南-簡單高效》由會員上傳分享,免費在線閱讀,更多相關內(nèi)容在教育資源-天天文庫。
1、Mips快速入門ProgramStructurejustplaintextfilewithdatadeclarations,programcode(nameoffileshouldendinsuffix.stobeusedwithSPIMsimulator)datadeclarationsectionprogramcodesectionDataDeclarationsplacedinsectionofprogramidentifiedwithassemblerdirective.datadeclaresvariablenamesusedinprogram;storagea
2、llocatedinmainmemory(RAM)Codeplacedinsectionoftextidentifiedwithassemblerdirective.textcontainsprogramcode(instructions)startingpointforcodee.g.ecutiongivenlabelmain:endingpointofmaincodeshoulduseexitsystemcall(seebelowunderSystemCalls)Commentsanythingfollowing#onaline#Thisstuffwouldbeco
3、nsideredacommentTemplateforaMIPSassemblylanguageprogram:#Commentgivingnameofprogramanddescriptionoffunction#Template.s#Bare-bonesoutlineofMIPSassemblylanguageprogram.data#variabledeclarationsfollowthisline#....text#instructionsfollowthislinemain:#indicatesstartofcode(firstinstructiontoexe
4、cute)#...#Endofprogram,leaveablanklineafterwardstomakeSPIMhappyDataDeclarationsformatfordeclarations:name:storage_typevalue(s)createstorageforvariableofspecifiedtypewithgivennameandspecifiedvaluevalue(s)usuallygivesinitialvalue(s);forstoragetype.space,givesnumberofspacestobeallocatedNote:
5、labelsalwaysfollowedbycolon(:)examplevar1:.word3#createasingleintegervariablewithinitialvalue3array1:.byte'a','b'#createa2-elementcharacterarraywithelements#initializedtoaandbarray2:.space40#allocate40consecutivebytes,withstorageuninitialized#couldbeusedasa40-elementcharacterarray,ora#10-
6、elementintegerarray;acommentshouldindicatewhich!Load/StoreInstructionsRAMaccessonlyallowedwithloadandstoreinstructionsallotherinstructionsuseregisteroperandsload:lwregister_destination,RAM_source#copyword(4bytes)atsourceRAMlocationtodestinationregister.Lbregister_destination,RAM_source#co
7、pybyteatsourceRAMlocationtolow-orderbyteofdestinationregister,#andsign-e.g.tendtohigher-orderbytesstoreword:swregister_source,RAM_destination#storewordinsourceregisterintoRAMdestinationsbregister_source,RAM_destination#storebyte(low-order)insourceregisterintoRAMdes