Get清风ARM程序示例Word格式文档下载.docx
- 文档编号:365754
- 上传时间:2023-04-28
- 格式:DOCX
- 页数:27
- 大小:24.38KB
Get清风ARM程序示例Word格式文档下载.docx
《Get清风ARM程序示例Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《Get清风ARM程序示例Word格式文档下载.docx(27页珍藏版)》请在冰点文库上搜索。
LTORG;
LiteralPool1contains
literalOx55555555
func2
LDRr3,=0x55555555;
LDRR3,[PC,#offsetto
LDRr4,=0x66666666;
Ifthisisuncommentedit
fails,becauseLiteralPool2
isoutofreach
LargeTable
SPACE4200;
Startingatthecurrentlocation,
clearsa4200byteareaofmemory
tozero
END;
LiteralPool2isempty
TheLDRpseudo-instructiongeneratesthemostefficientcodeforaspecificconstant:
iftheconstantcanbeconstructedwithaMOVorMVNinstruction,theassemblergeneratestheappropriateinstruction.
iftheconstantcannotbeconstructedwithaMOVorMVNinstruction,theassembler:
●placesthevalueinaliteralpool(aportionofmemoryembeddedinthecodetoholdconstantvalues)
●generatesanLDRinstructionwithaprogram-relativeaddressthatreadstheconstantfromtheliteralpool.
Forexample:
LDRrn,[pc,#offsettoliteralpool]
loadregisternwithoneword
fromtheaddress[pc+offset]
YoumustensurethatthereisaliteralpoolwithinrangeoftheLDRinstructiongeneratedbytheassembler.RefertoPlacingliteralpoolsformoreinformation.
Theoffsetfromthepctotheconstantmustbe:
lessthan4KBinARMstate,butcanbeineitherdirection
forwardandlessthan1KBinThumbstate.
WhenanLDRRd,=constpseudo-instructionrequirestheconstanttobeplacedinaliteralpool,theassembler:
●checksiftheconstantisavailableandaddressableinanypreviousliteralpools.Ifso,itaddressestheexistingconstant.
●attemptstoplacetheconstantinthenextliteralpoolifitisnotalreadyavailable.
Ifthenextliteralpoolisoutofrange,theassemblergeneratesanerrormessage.InthiscaseyoumustusetheLTORGdirectivetoplaceanadditionalliteralpoolinthecode.PlacetheLTORGdirectiveafterthefailedLDRpseudo-instruction,andwithin4KB(ARM)or1KB(Thumb).RefertoLTORGforadetaileddescription.
EXAMPLE2(ADRADRL)
AREAadrlabel,CODE,READONLY
Start
BLfunc;
Branchtosubroutine
Createaliteralpool
funcADRr0,Start;
SUBr0,PC,#offsettoStart
ADRr1,DataArea;
ADDr1,PC,#offsettoDataArea
ADRr2,DataArea+4300;
Thiswouldfailbecausetheoffset
cannotbeexpressedbyoperand2
ofanADD
ADRLr2,DataArea+4300;
ADDr2,PC,#offset1
ADDr2,r2,#offset2
MOVpc,lr;
Return
DataAreaSPACE8000;
clearsa8000byteareaofmemory
END
TheassemblerconvertsanADRrn,labelpseudo-instructionbygenerating:
●asingleADDorSUBinstructionthatloadstheaddress,ifitisinrange
●anerrormessageiftheaddresscannotbereachedinasingleinstruction.
Theoffsetrangeis±
255bytesforanoffsettoanonword-alignedaddress,and±
1020bytes(255words)foranoffsettoaword-alignedaddress.(ForThumb,theaddressmustbewordaligned,andtheoffsetmustbepositive.)
TheassemblerconvertsanADRLrn,labelpseudo-instructionbygenerating:
●twodata-processinginstructionsthatloadtheaddress,ifitisinrange
●anerrormessageiftheaddresscannotbeconstructedintwoinstructions.
TherangeofanADRLpseudo-instructionis±
64KBforanonword-alignedaddressand±
256KBforaword-alignedaddress.(ThereisnoADRLpseudo-instructionforThumb.)
ADRLassemblestotwoinstructions,ifsuccessful.Theassemblergeneratestwoinstructionseveniftheaddresscouldbeloadedinasingleinstruction.
EXAMPLE3ARMcodejumptable
AREAJump,CODE,READONLY;
Namethisblockofcode
CODE32;
FollowingcodeisARMcode
numEQU2;
Numberofentriesinjumptable
start;
Firstinstructiontocall
MOVr0,#0;
Setupthethreeparameters
MOVr1,#3
MOVr2,#2
BLarithfunc;
Callthefunction
arithfunc;
Labelthefunction
CMPr0,#num;
Treatfunctioncodeasunsignedinteger
MOVHSpc,lr;
Ifcodeis>
=numthensimplyreturn
ADRr3,JumpTable;
Loadaddressofjumptable
LDRpc,[r3,r0,LSL#2];
Jumptotheappropriateroutine
JumpTable
DCDDoAdd
DCDDoSub
DoAddADDr0,r1,r2;
Operation0
DoSubSUBr0,r1,r2;
Operation1
Marktheendofthisfile
Example4Stringcopy
AREAStrCopy,CODE,READONLY
startLDRr1,=srcstr;
Pointertofirststring
LDRr0,=dststr;
Pointertosecondstring
BLstrcopy;
Callsubroutinetodocopy
strcopy
LDRBr2,[r1],#1;
Loadbyteandupdateaddress
STRBr2,[r0],#1;
Storebyteandupdateaddress
CMPr2,#0;
Checkforzeroterminator
BNEstrcopy;
Keepgoingifnot
MOVpc,lr;
AREAStrings,DATA,READWRITE
srcstrDCB"
Firststring-source"
0
dststrDCB"
Secondstring-destination"
END
Example5Blockcopy
AREAWord,CODE,READONLY;
namethisblockofcode
numEQU20;
setnumberofwordstobecopied
markthefirstinstructiontocall
start
LDRr0,=src;
r0=pointertosourceblock
LDRr1,=dst;
r1=pointertodestinationblock
MOVr2,#num;
r2=numberofwordstocopy
wordcopyLDRr3,[r0],#4;
loadawordfromthesourceand
STRr3,[r1],#4;
storeittothedestination
SUBSr2,r2,#1;
decrementthecounter
BNEwordcopy;
...copymore
AREABlockData,DATA,READWRITE
srcDCD1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4
dstDCD0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
AREABlock,CODE,READONLY;
MOVsp,#0x400;
Setupstackpointer(r13)
blockcopyMOVSr3,r2,LSR#3;
Numberofeightwordmultiples
BEQcopywords;
Lessthaneightwordstomove?
STMFDsp!
{r4-r11};
Savesomeworkingregisters
octcopyLDMIAr0!
Load8wordsfromthesource
STMIAr1!
andputthematthedestination
SUBSr3,r3,#1;
Decrementthecounter
BNEoctcopy;
LDMFDsp!
Don'
tneedthesenow-restore
originals
copywordsANDSr2,r2,#7;
Numberofoddwordstocopy
BEQstop;
Nowordslefttocopy?
Loadawordfromthesourceand
Test-and-branchmacroexample
Atest-and-branchoperationrequirestwoARMinstructionstoimplement.
Youcandefineamacrodefinitionsuchasthis:
MACRO
$labelTestAndBranch$dest,$reg,$cc
$labelCMP$reg,#0
B$cc$dest
MEND
ThelineaftertheMACROdirectiveisthemacroprototypestatement.Themacroprototypestatementdefinesthename(TestAndBranch)youusetoinvokethemacro.Italsodefinesparameters($label,$dest,$reg,and$cc).Youmustgivevaluestotheparameterswhenyouinvokethemacro.Theassemblersubstitutesthevaluesyougiveintothecode.
Thismacrocanbeinvokedasfollows:
testTestAndBranchNonZero,r0,NE
...
NonZero
Aftersubstitutionthisbecomes:
testCMPr0,#0
BNENonZero
EXAMPLE6MAP&
FIELD
typedefstructPoint
{
floatx,y,z;
}Point;
Pointorigin,oldloc,newloc;
Thefollowingassemblylanguagecodeisequivalenttothetypedefstatementabove:
PointBaseRNr11
MAP0,PointBase
Point_xFIELD4
Point_yFIELD4
Point_zFIELD4
Thefollowingassemblylanguagecodeallocatesspaceinmemory.ThisisequivalenttothelastlineofCcode:
originSPACE12
oldlocSPACE12
newlocSPACE12
Youmustloadthebaseaddressofthedatastructureintothebaseregisterbeforeyoucanusethelabelsdefinedinthemap.Forexample:
LDRPointBase,=origin
MOVr0,#0
STRr0,Point_x
MOVr0,#2
STRr0,Point_y
MOVr0,#3
STRr0,Point_z
isequivalenttotheCcode:
origin.x=0;
origin.y=2;
origin.z=3;
Examples7
straightforwardsubstitution
GBLSadd4ff
add4ffSETS"
ADDr4,r4,#0xFF"
setupadd4ff
$add4ff.00;
invokeadd4ff
thisproduces
ADDr4,r4,#0xFF00
elaboratesubstitution
GBLSs1
GBLSs2
GBLSfixup
GBLAcount
countSETA14
s1SETS"
a$$b$count"
s1nowhasvaluea$b0000000E
s2SETS"
abc"
fixupSETS"
|xy$s2.z|"
fixupnowhasvalue|xyabcz|
|C$$code|MOVr4,#16;
butthelabelhereisC$$code
C与汇编的混合编程
TheARMC++compilerssupportt
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Get 清风 ARM 程序 示例
![提示](https://static.bingdoc.com/images/bang_tan.gif)