ARM程序示例Word格式文档下载.docx

上传人:b****5 文档编号:15769280 上传时间:2022-11-16 格式:DOCX 页数:24 大小:24.91KB
下载 相关 举报
ARM程序示例Word格式文档下载.docx_第1页
第1页 / 共24页
ARM程序示例Word格式文档下载.docx_第2页
第2页 / 共24页
ARM程序示例Word格式文档下载.docx_第3页
第3页 / 共24页
ARM程序示例Word格式文档下载.docx_第4页
第4页 / 共24页
ARM程序示例Word格式文档下载.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

ARM程序示例Word格式文档下载.docx

《ARM程序示例Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《ARM程序示例Word格式文档下载.docx(24页珍藏版)》请在冰豆网上搜索。

ARM程序示例Word格式文档下载.docx

returna;

AREAgcd,CODE,READONLYALIGN=3

ENTRY

startCMPR0,R1

BEQstop

BLTless

SUBR0,R0,R1

Bstart

lessSUBR1,R1,R0

stopNOP

END

SUBGTR0,R0,R1

SUBLTR1,R1,R0

BNEstart

EXAMPLE1(AboutLDR、LTORG)

AREALoadcon,CODE,READONLYALIGN=3

ENTRY;

Markfirstinstructiontoexecute

startBLfunc1;

Branchtofirstsubroutine

BLfunc2;

Branchtosecondsubroutine

stopMOVr0,#0x18;

angel_SWIreason_ReportException

LDRr1,=0x20026;

ADP_Stopped_ApplicationExit

SWI0x123456;

ARMsemihostingSWI

func1

LDRr0,=42;

=>

MOVR0,#42

LDRr1,=0x55555555;

LDRR1,[PC,#offsetto

;

LiteralPool1]

LDRr2,=0xFFFFFFFF;

MVNR2,#0

MOVpc,lr

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;

Callth

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 表格模板 > 调查报告

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1