arm汇编指令笔记._第1页
arm汇编指令笔记._第2页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、ARM assembler guide DUI00682.2Overview ol the ARM architectureThis seclion gi es a brief overviev. of the ARM arc hi teclure.ARM prnces,or cine topical of RISC卩mce汀口眄m iha【(hev impleinent a load/store archi lecture. On It load and jvioreinsi ructions cun access memoT-, 3ata processing jnsLructLans o

2、perate on register contenls only.是一个 RISC 指令结构,因为有一个加载存储结构。 只有 load 和 store 可以读取内存。223 Processor modeARM provenors support up to seven processurIIHXICS, dep;ndi on lhe sirdiiietUTe version. These are:U耙rF1Q- Fast Lnlerrupl RequesiRQ - niernipl RequeslSupervisorAbortUiKlefinecISystem (ARM archileclur

3、e v4IIIKI above).All nuxles exuijpl User nnxle are re I erred io as prhifeetl moiles.ARM 的处理器模式2.3.1Layout of assembly language source filesCaee mle$Instniclion miKmoiiics. directives, nd symbolic rcgisler name can be writ(i;n in iipperciise or lowercasehhilt not mixed.可以全部大写或小写,不能混LabelsLahcls arc

4、symbols llmt represent addresses. The address eiven hy n label iscalcukircd du ciassembly.标志符表示一个地址Local labelsLocal labels are a subclass of label. A local label begins with a inimber in the range 0-99. Unlike other labels, a local labelcan be defined many times. Local labels are useful when you ar

5、e gencraiing labels with u macro. When the assembler findsy ivferetice lo a local liibcL il links ii io a nearby instance of llic KKUI label-Thescopeof local labels islimited by(he AREAdireclive. Youcanuse the ROUTdirective to Limit die scopemore tightly.ConstantsConslanls be numcrk. Uwkan, tkiracle

6、r or string:Numbers Numeric constants arc accepted in three forms:*Decimj. for exainple+123*Hexadecimal, for example. 0 x7B*ft.jcxx where:nXXXis 3 base between 2 and 9 in n niiniha inibid biise.常量的定义格式:1230 x1C2_1001ARM 编译、链接后最终生成一个 ELF 格式(Executable and Linking Format)的可执行文件(后 缀.axf)ELF 中是分 sectior

7、 部分的,一个 ELF section在汇编中定义一个 section 使用 AREA 指令。2.3.2An example ARM assembly language moduleAREAARNextCODE, READONLYENTRY;Name this block of cod亡 ARMex;Mark flr&T insTruction to execurestartMOVrO, #10: Set up parametersMOYrl.ADDrO, rO, rl; r0 =+ rlstopMOVre, #0 x18; ang el _SWI re a soruRe po r t

8、 Exc e pti onLDRrl.=0 x20026; ADP.StoppecLApplicati onExitSWI0 x123456; ARM semi hosting ShiEND;Mark end of fileELF sections and the AREA directiveELF secfions are iniiependent, imm亡indivisible sequences of code or dota, A single code edion is the iniihinutn required lu produce un dpplkiiuoitThe out

9、put of an assembly or compilation can includeOne or more code sections. These nvc usually rtiid-uiilv scxliun.One cr mure data seelions. These arc uuully rcad-uiHc sec lions. They niiiy be zero hutiulized (Zl).The linker phees each section i门卫program image according ro section pUcement rules. Sectio

10、ns ilun ;xre adjacent in source filet ;irt not neeerilyadjaceni in rhe application image. Refer to the Linker chapter in ADS Linker tind C litilies Gifitle for niurv infomiation on how the linker placessections.hi nn ARM assembly Language()urce file, the start of 3 section is marked hy the AREA dire

11、ctive. This directive names I he section and sets itsattributes. The attributes are pluccil ufter the nuinc. scparatckl by gummas. Refer k) AREA un 7-52 for dctiiilcd description of die syntax of rheAREA directive.TheENTRYdlrecuveHit ENTRYdirculivr marks Lhr first instruct ion tu be rxccutcd. h appl

12、iculiiurks cunluiDiLnig C codc+an cnl ir)rpoint is also contained within the C libraryiiiilializution code.Inhhilizationicodeandexceptjo:n handle只awcontain, enurypoints.ENTRY 指令指示汇编代码第一条要执行的指令。Appllcatton executionThe application cixlc in Example 2- cn page 2-15 logins executing at the label stsrt.w

13、here il loads (lie decimqi rallies 10 and 3 into rrpihlcis r0 and 11.These registers arc Ltildcil Luuctlicj Jiid llic iriiult pLtvd in liJ.start 是一个标识符,代表一个地址。Applicatlon terminDonAfkr executing lhe itinin cixk. I he Eipplicdiion IcnniniiUs hy returning conlro to I he debugger. This is done using th

14、e ARM scmihosting SWl(0 x123456 by defau1t)hwith the following param亡忙rs:fO equal to a nge 1 _SWI rea son.R epc rtEKcept i on (0N1) rJ equal to ADP_Stopped_4pplicationExit (0 x20026).Refer to the Semihosting SWIs chapter in AOS Debug Tatget Guide for additional information.结束的方式是产生一个软件中断,把控制权交给调试器。T

15、he END directiveTli is directive inslructs I he assembler lo stop proccLiig this source tile. Everpassembly language也lurvu n)iK|ule mu.!IHUSIIwith END diiwiireon n line by iisclf.END 指令指示汇编的结束使用 cmd 进行调试:Microsoft Windows XP 版本 5.1.2600(C)版权所有 1985-2001 Microsoft Corp.C:Docume nts and Setti ngsAdmi

16、nistratorcd D:Program FilesARMADSv1_2BinC:Docume nts and Setti ngsAdmi nistratorD;D 不是内部或外部命令,也不是可运行的程序 或批处理文件。C:Docume nts and Setti ngsAdmi nistratorD:D:Program FilesARMADSv1_2Bi narmsd E:dsparmpxa270projectarmex_image.axARM Source-level Debugger, ADS1.2 Build 805 Software supplied by: Team-EFAARM

17、ulator ADS1.2 Build 805Software supplied by: Team-EFAARM7TDMI, BIU, Little endian, Semihosting, Debug Comms Channel, 4GB, Mapfile, Timer, Profiler, Tube,Millisecond 20000 cycles_per_millisecond, Pagetables, IntCtrl, Tracer, RDI CodesequencesObject program file E:dsparmpxa270projectarmex_image.axf ar

18、msd: help help Display help information on one of the following commands:RegistersFpregistersCoprocCRegistersCREGDefCWriteStepIstepExamineListQuitObeyGoBreakUnbreakWatchUNWatchPrintCONtextOUtINWHereBAcktraceVariableSYmbolsLSymLEtArgumentsLAnguageHelpTypeCAllWHIleALiasLOadLOGRELoadREAdsymsFIndPUtfile

19、GEtfileLOCalvarCOMmentPAuseLOADConfigSElectconfigLISTConfigLOADAgentPROfonPROFOFfPROFClearPROFWriteCCinCCOutPROCessorSYSSETregisterTRacetriggerTRACEExtentTRACEWriteTRACEStartTRACESTOpTRACEFlushHELP * gives helps on all available commands. To print the help use the LOG command to record the helpoutpu

20、t into a file & print the file.If the first character of a line is the ! character the rest of the command line is executed by a call to system().If the first character of a line is the | character the rest of the line is a treated as a comment.Note that this help is not intended to replace the

21、printed manual which explains ARMSD in much greaterdetail.armsd: LOG* Error: No log filearmsd: stepStep completed at PC = 0 x000080040 x00008004: 0 xe3a01003 . : mov r1,#3armsd: Registerr0= 0 x0000000a r1= 0 x00000000r2 = 0 x00000000r3= 0 x00000000r4= 0 x00000000 r5 =0 x00000000r6 = 0 x00000000r7= 0

22、 x00000000r8= 0 x00000000 r9 =0 x00000000r10 = 0 x00000000r110 x00000000r12=0 x00000000 r13 = 0 x00000000r14 =0 x00000000pc= 0 x00008004 cpsr= %nzcvqIFt_SVC spsr = %nzcvqift_Reserved_00armsd: stepStep completed at PC = 0 x00008008 0 x00008008: 0 xe0800001: add r0,r0,r1armsd: Registerr0 = 0 x0000000a

23、 r1 = 0 x00000003 r2 = 0 x00000000 r3 = 0 x00000000 r4 = 0 x00000000 r5 =0 x00000000 r6 = 0 x00000000 r7 = 0 x00000000r8 = 0 x00000000 r9 = 0 x00000000 r10 = 0 x00000000 r11 = 0 x00000000 r12 = 0 x00000000 r13 =0 x00000000 r14 = 0 x00000000pc = 0 x00008008 cpsr = %nzcvqIFt_SVC spsr = %nzcvqift_Reser

24、ved_00 armsd: stepStep completed at PC = 0 x0000800c0 x0000800c: 0 xe3a00018 . :movr0,#0 x18armsd:LOG* Error: No log filearmsd:Registerr0= 0 x0000000d r1= 0 x00000003r2 = 0 x00000000r3= 0 x00000000r4= 0 x00000000 r5= 0 x00000000r6 = 0 x00000000r7= 0 x00000000r8= 0 x00000000 r9= 0 x00000000r10 = 0 x0

25、0000000 r11 0 x00000000r12 = 0 x00000000 r13 = 0 x00000000r14 =0 x00000000pc = 0 x0000800c cpsr = %nzcvqIFt_SVC spsr = %nzcvqift_Reserved_00 armsd: step Step completed atPC = 0 x000080100 x00008010: 0 xe59f1000 . : ldr r1,0 x00008018 ; = #0 x00020026armsd: Registerr0= 0 x00000018 r1 =0 x00000003r2 =

26、 0 x00000000r3= 0 x00000000r4= 0 x00000000 r5 =0 x00000000r6 = 0 x00000000 r7= 0 x00000000r8= 0 x00000000 r9 =0 x00000000r10 = 0 x00000000 r110 x00000000r12=0 x00000000 r13 = 0 x00000000r14 =0 x00000000pc= 0 x00008010 cpsr= %nzcvqIFt_SVC spsr = %nzcvqift_Reserved_00armsd: stepStep completed at PC =

27、0 x000080140 x00008014: 0 xef123456 V4. :swi 0 x123456armsd: Registerr0= 0 x00000018 r1 =0 x00020026r2 = 0 x00000000r3= 0 x00000000r4= 0 x00000000 r5 =0 x00000000r6 = 0 x00000000 r7= 0 x00000000r8= 0 x00000000 r9 =0 x00000000r10 = 0 x00000000 r110 x00000000r12=0 x00000000 r13 = 0 x00000000r14 =0 x00

28、000000pc= 0 x00008014 cpsr= %nzcvqIFt_SVC spsr = %nzcvqift_Reserved_00armsd: stepProgram terminated normally at PC = 0 x000080140 x00008014: 0 xef123456 V4. :swi 0 x123456armsd: Registerr0= 0 x00000018 r1 =0 x00020026r2 = 0 x00000000r3= 0 x00000000r4= 0 x00000000 r5 =0 x00000000r6 = 0 x00000000 r7=

29、0 x00000000r8= 0 x00000000 r9 =0 x00000000r10 = 0 x00000000 r110 x00000000r12=0 x00000000 r13 = 0 x00000000r14 =0 x00000000pc= 0 x00008014 cpsr= %nzcvqIFt_SVC spsr = %nzcvqift_Reserved_00armsd: quitQuittingD:Program FilesARMADSv1_2Bin使用 armsd 调试有点像微机原理上调试汇编,爽!2,6 Loading constants into registersThe

30、ILIIIOWing secliuns deieribe:hov to use iIKMOV nd MVN inslnictiens to lead a range o| iimncdiak values, see Direct loading with MOV and MVN on page 2-26how to u牝die LDR p sen doinstruc Li on lo lod any 32-bil eonstctnL, sec Loading with LDR Hifr=CYJ;J.V/ on page 2-27MOV 叫指令,常数范围是 0-255LDR 叫伪指令都是将常数放

31、到 Reg 中4.3.4 MOV and MVNMove and Move Not.SyntaxM0Vcctn(J5 Rd, OperandZ唯11:伽聆$Rd, OperafKi?UsageTh亡MOV ilistmelion copies lhe value of Operands into Rd.The附M instruction takes Llic value of Operand, perfonns a bilwise logical NOT o|)emiion on ih亡vahie. jnd phices the refill uno Rd.2.6.2Loading with

32、LDR Rd, =constThe LDR Rd,=const |)scudo-inslmction can construct ans 32-bit numeric constiinl in a si rllk iilslrutlion. UsvpsLlldn-itlriK tHHi 111 Jjeik rnlk? uonslnilK lllul UV lUil ol runge of the MOV and MVN instructions.4.9.3 LDR ARM pseudo-in struct ionLoad a rvistcr witli cithei:*a 32-bit can

33、startt vain亡dii address.MOVLDRrt, #0 xlSrlt=0 x20026#和 FIELD 指令是一样的3.4 Built-in variablesTable 3-1 lists the built-in variables de lined by lliu ARM assembler.Table 3-1 Built-in variablesPC orAddress of current instruction.符号在汇编程序中代表一个地址,可以用在指令中,汇编程序经过汇编器的处理之后,所有的符号都被替换成它所代表的地址值。DCD (& ):分配一段字内存

34、单元用于分配一段字内存单元,与&同义。在中断向量表中不直接 LDR PC,异常地址.而是使用一个标号,然后再在后面使用 DCD 定义这个标号,其原因 是LDR 指令只能跳到当前 PC 4kB 范围内,而 B 指令能跳转到 32MB 范围,而现在这样在 LDR PC, xxxx这条指令不远处用xxxxDCD 定义一个字,而这个字里面存放最终异常服务程序 的地址,这样可以实现 4GB 全范围跳转。EQUIs an assembler directive, t is used to give a value to a symboL JDthis exatTiple ii assigns lh

35、e value 2 to num. When num isused elsewherein lhecode, thevalue 2 is substitnied. Using EQU in this way is similar to using define to define a con slant inC.DCDDeclares one or more ords of store. In (his exampleeach DCD stores the address of a rouline that handles a pardcLilar clauseof the jump tabl

36、e.BaseOfROM DCD |lmage$RO$Base|EQU (*):相当于 C 里面的#define 个常数7.7.6EQUThe EQU diiecuve gives a symbolicIKIIIKIn nIHLmeric consfanL a igMer-relative value or n program-relative value.* is a synonym for EQU,LTORG7.3.1LTORGThe LTORG directive instructs the asmbler to assemble theCUITCIII literal pool lmme

37、cliateJy.SyntaxLTORGUsageTheassJ.兀is a synonyiiL for SPACE,Sy ntaxlibel SPACE exprwhere:exprevalucres to rhe number of zeroed bytes to rcprvt?( sec Numericexpressions on page 3-20).ExampleMyData, DATA, READWRITE255; defines 255 bytes of zeroed store2.10 Describing data structures with MAP and FIELD directivesThe MAP directive specifies the base addressof the data structure.The FIELD directive specifies the amount of me

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论