1 / 10

ARM 及 Thumb 指令集 ( 练习)

ARM 及 Thumb 指令集 ( 练习). Quiz #2 - GCD. 新建一个 ‘ARM Executable Image’ 项目 新建一个 text 文件 另存为 “gcd.s” 加入到项目中 Build 并执行. Start. Yes. r0 = r1 ?. Stop. No. AREA myarea, CODE ENTRY MOV r0, #9 MOV r1, #15 start ; your code here stop B stop END. r0 > r1 ?. Yes. No.

lionel
Télécharger la présentation

ARM 及 Thumb 指令集 ( 练习)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ARM及Thumb指令集(练习)

  2. Quiz #2 - GCD • 新建一个 ‘ARM Executable Image’ 项目 • 新建一个 text文件 • 另存为 “gcd.s” • 加入到项目中 • Build 并执行 Start Yes r0 = r1? Stop No AREA myarea, CODE ENTRY MOV r0, #9 MOV r1, #15 start ; your code here stop B stop END r0 > r1? Yes No r0 = r0 - r1 r1 = r1 - r0 你只需要使用CMP、SUB和B指令。 充分使用条件执行! 大家可以尝试计算 2109 和 4161 的GCD

  3. Quiz #2 – 答案 AREA gcd, CODE ENTRY MOV r0, #9 MOV r1, #15 start CMP r0, r1 SUBLT r1, r1, r0 SUBGT r0, r0, r1 BNE start stop B stop END 设置初始值 一次比较的值可多次使用 死循环 练习:求 2109和4161的 GCD 57 (0x39)

  4. Quiz #3 - Total of array • 写一段 ARM汇编程序:循环累加队列中的所有元素,直到碰上零值元素,结果放在r4. • 源程序末尾处声明队列: myarray DCD 0x11 DCD 0x22 DCD 0 • r0 指向队列头 ADR r0,myarray • 使用命令LDR r1,[r0],#4来装载 • 累加至 r4 • 循环,直到r1为0 • 用死循环来停止 0 0x22 地址增加 r0 0x11

  5. Quiz #3 - Solution AREA total, CODE ENTRY MOV r4, #0 ADR r0, array loop LDR r1, [r0], #4 ADD r4, r4, r1 CMP r1, #0 BNE loop stop B stop array DCD 0x11 DCD 0x22 DCD 0 END 设置初始值 基址指针 r0自动增加 r1为0时中断循环 死循环 声明队列

  6. Quiz #5 – DSP计算能力 1)写一个汇编函数 ‘qtest’来测试Q flag, 并清零。 • 参看模板 ‘asm\dsp.s’ • 如果 Q 为0,返回0,否则返回非零 2) 写一个汇编主程序,把一个含64个带符号的16-bit数据组成的队列求平方和。 int total=0; for (n=0; n<64; n++) total += x[n]*x[n]; • 使用 LDRH来装载数值。 • 使用SMLABB来求平方和。 3) 是否存在interlocks? 4) 在AXD中检查Q标志, (修改cpsr 为 E-PSR) 5) 循环末尾增加一个BL来调用qtest,并检测返回值。 6)高手可尝试:改用LDR,一次 加载两个数据。 7)高手可尝试:修改代码,使用一个64-bit累加器。 x r0 x[0] x[1] x[2] x[3] x[4] x[5] x[62] x[63]

  7. Quiz #5 - Solution (1) 1)写一个汇编函数 ‘qtest’来测试Q flag, 并清零. AREA TestQFlag, CODE Qflag EQU 0x08000000 qtest MRS r0, cpsr BIC r1, r0, #Qflag AND r0, r0, #Qflag MSR cpsr_f, r1 BX lr END 遵从 ATPCS标准,如果Q为1 ,非零值放在r0中返回 使用 “BX lr”返回, interworking时很安全

  8. Quiz #7 - Solution (2) 2)写一个汇编主程序,把一个含64个带符号的16-bit数据组成的队列求平方和 AREA dspcode, CODE ENTRY MOV r2, #64 MOV r4, #0 LDR r0, =x loop LDRH r1, [r0], #2 SMLABB r4, r1, r1, r4 SUBS r2, r2, #1 BGT loop stop B stop AREA dspdata, DATA x DCW 0x7777 DCW 0x1111 DCW 0xeeef ... END 这两条指令上r1 interlock。可通过交换 SMLABB 和 SUBS来消除。 (注意 LDRH 优于LDRSH因为高halfword被忽略,而 LDRSH 速度更慢。) 最终结果 (r4) 0x011D4324

  9. Quiz #7 - Solution (3) AREA dspcode, CODE ENTRY MOV r2, #64/2 ; as doing word loads MOV r4, #0 LDR r0, =x loop LDR r1, [r0], #4 SUBS r2, r2, #1 SMLABB r4, r1, r1, r4 SMLATT r4, r1, r1, r4 BGT loop stop B stop AREA dspdata, DATA x DCW 0x7777 DCW 0x1111 DCW 0xeeef ... END 6)改用LDR,一次 加载两个数据。

More Related