ARM 微处理器部分指令实例整理(持续增加...)


1.add (addition)

1.1.1 add r1, r2, #5  @ r1 = r2 + 5

1.2.1 add r1, r2, r3   @ r1 = r2 + r3

1.3.1 add r1, r2, r3, lsl #5 @  r1 = r2 + (r3 <<5),逻辑左移

1.3.2 add r1, r2, r3, lsr #5 @ r1 = r2 + (r3 >> 5),逻辑右移

1.3.3 add r1, r2, r3, asr #5 @ r1= r2 + ((r3 >> 5) | (r3 & (1>>31))),算术右移

1.3.4 add r1, r2, r3, ror #5 @ r1 = r2 + (r3>> 5) | (r3 << (32- 5)) ,循环右移

1.3.5 add r1, r2, r3, rrx       @ r1 = r2 + (r3>>1) | (carry << 31), carry = (r3 & 0x0001), 带进位逻辑右移一位

1.3.6 add r1, r2, r3, lsl r4   @ r1 = r2 + (r3 << r4)

1.3.7 add r1, r2, r3, lsr r4   @ r1= r2 + (r3 >> r4)

1.3.8 add r1, r2, r3, asr r4  @ r1 = r2 + ((r3 >> r4) & ( r3 & (1>> 31)))

1.3.9 add r1, r2, r3, ror r4 @ r1 = r2 + ((r3 >> r4) | (r3 << (32- r4)))

2.sub (subtract)

2.1.1 sub r1, r2, #0x8 @ r1 = r2 - 0x8;

2.2.1 sub r1, r2, r3       @ r1 = r2 - r3;

2.3.1 sub r1, r2, r3, lsl #3 @ r1 = r2 - (r3 << 3)

2.3.2 sub r1, r2, r3, lsr #3 @ r1 = r2 - (r3 >> 3)

2.3.3 sub r1, r2, r3, asr #3 @ r1 = r2 -  ((r3>>3) | (r3& (1 << 31)))

2.3.4 sub r1, r2, r3, ror #3 @ r1 = r2 - ((r3 >> 3) | (r3 << (32 - 3)))

2.3.5 sub r1, r2, r3, rrx       @ r1 = r2 - ((r3>>1) | (carry << 31)), carry = r3 &0x1;

2.3.6 sub r1, r2, r3, lsl r4   @ r1 = r2 - (r3 << r4)

2.3.7 sub r1, r2, r3, lsr r4   @ r1 = r2 - (r3 >> r4)

2.3.8 sub r1, r2, r3, asr r4  @ r1 = r2 - ((r3 >> r4) | (r3 & (1<<31)))

2.3.9 sub r1,r2, r3, ror r4   @ r1 = r2 - ((r3 >> r4) | ( r3 << (32-r4)))

3. mov (move data)

3.1.1 mov r1, #0x23 @ r1 = 0x23

3.1.2 mov r1, r3         @ r1 = r3;

3.1.3 mov r1, r3, lsl #0x7 @ r1 = r3 << 7;

3.1.4 mov r1, r3, lsr #0x7 @ r1 = r3 >> 7;

3.1.5 mov r1, r3, asr #0x7 @ r1 = (r3 >> 7) | (r3 & (1<< 31))

3.1.6 mov r1, r3, ror #0x7  @ r1 = (r3 >> 7) | (r3 <<(32-7))

3.2.3 mov r1, r3, lsl r2 @ r1 = r3 << r2;

3.2.4 mov r1, r3, lsr r2  @ r1 = r1 >> r2;

3.2.5 mov r1, r3, asr r2 @ r1 = ( r3 >> r2) | (r3 &(1 <<31))

3.2.6 mov r1, r3, ror r2 @ r1 = (r3 >> r2)  | (r3 << (32 -r2))

3.3.1 mov r1, r3, rrx   @ r1 = (r3 >> 1) | (carry << 31), carry, = r3 &0x01,

4. mvn (move negative)

4.1.1 mvn r1, # 0x23  @ r1 = 0xffffffff xor 0x23

4.1.1 mvn r1, r2      @ r1 = (1<<32-1) xor r2

4.1.2 mvn r1, [r2]     @ r1 = (1<<32-1) xor [r2], 寄存器间接寻值,

列举个例子, mvn r0, 0 ==> r0 = 0xffffffff,根据.Two's Complement to Decimal Conversion,可以计算出 r0 = -1,

再来个例子, mvn r0, 5 => r0 = 0b1111 1111 1111 0110 => sign 为一,推出为negative,

                             该值异或,可得0b0000 0000 0000 1001

                             该值加1,可得0b0000 0000 0000 1010 = 6, 从而得到值为-6                                                 


5. bic (bit clear)

5.1.1 bic r5, r3 @ r5 = r5 & (~r3),  注意这里只有一个操作数,目的操作数要带入计算

5.1.2 bic r5,  r5, #7 @ r5 = r5 & ((1 << 32 -1)^ 7)  <=> r5 = r5 & (~0x7)

5.1.3 bic r4, r3, [r1] @ r4 = r3 & ((1<< 32 -1) ^[r1])  <=> r4 = r3 & (~[r1])

6. eor (exclusive or)

6.1.1 eor  r1, r9 @ r1 = r1 ^ r9

6.1.2 eor  r1, r1, r9 @ r1 = r1 ^ r9

6.1,3 eor r1, r7, #7 @ r1 = r7 ^ 7

6.1.4 eor r1, r5, r5 , ror #16  @ r1 = r5 ^( (r5 >> 16) | (r5 << (32-16)))

6.1.5 eor r5, r5, r1, lsr #8 @ r5 = r5 ^ (r1<<8)


7. orr (bitwise or)

1.1 orr r1, r8 @ r1 = r1 | r8

1.2 orr r1, r1, r8 @ r1 = r1 |  r8

1,3 orr r11, r10, r9, lsl r5 @ r11 = r10 | (r9 << r5)

1,4 orr r0, r0, #002d @ r0 = r0 | (0x002d)

8. TST (Test)

1,1 TST r3, #1 << 14 @ update CPSR flags,  r3 & (1<<14)

1.2 TST r3, r2 @update CPSR flags, r3 & r2


9.TEQ (Test equivalence)

1.1 teq r3, #3 << 14 @update CPSR flags, r3 ^ ( 3 << 14)

10. CMP (Compare positive)

1.1 cmp r3, r9 @update CPSR flags, r3 - r9

1.2 cmp r3, #9 @ update CPSR flags, r3 - 9

11.CMN (Compare negative)

1.1 cmn r3, r9 @update CPSR flags, r3 + r9

1.2 cmn r3, 8   @update CPSR flags, r3 + 8


12. adr

restart:    adr    r0, LC0   @计算处LC0的地址后,存入r0寄存器
        ldmia    r0, {r1, r2, r3, r6, r10, r11, r12} @从r0指向内存地址加载值,依次赋予r1, r2, r3, r6, r10, r11, r12,
        ldr    sp, [r0, #28] @加载stack point的值,上条指令r0值未改变,因此用(r0+4×7)来寻址

.......

        .align    2
        .type    LC0, #object
LC0:        .word    LC0            @ r1
        .word    __bss_start        @ r2
        .word    _end            @ r3
        .word    _edata            @ r6
        .word    input_data_end - 4    @ r10 (inflated size location)
        .word    _got_start        @ r11
        .word    _got_end        @ ip
        .word    .L_user_stack_end    @ sp
        .size    LC0, . - LC0










-





Logical Shift Left
( LSL ) moves each bit of a bitstring left by a specified number of bits. Zeros are shifted in at the right
end of the bitstring. Bits that are shifted off the left end of the bitstring are discarded, except that the
last such bit can be produced as a carry output.

Logical Shift Right
( LSR ) moves each bit of a bitstring right by a specified number of bits. Zeros are shifted in at the left
end of the bitstring. Bits that are shifted off the right end of the bitstring are discarded, except that
the last such bit can be produced as a carry output.

Arithmetic Shift Right

( ASR ) moves each bit of a bitstring right by a specified number of bits. Copies of the leftmost bit are
shifted in at the left end of the bitstring. Bits that are shifted off the right end of the bitstring are
discarded, except that the last such bit can be produced as a carry output.
Rotate Right

( ROR ) moves each bit of a bitstring right by a specified number of bits. Each bit that is shifted off the
right end of the bitstring is re-introduced at the left end. The last bit shifted off the right end of the
bitstring can be produced as a carry output.

Rotate Right with Extend
( RRX ) moves each bit of a bitstring right by one bit. A carry input is shifted in at the left end of the
bitstring. The bit shifted off the right end of the bitstring can be produced as a carry output.


参考资料:

1. The Definitive Guide to ARM Cortex-M3 and Cotex-M4 Processors, Joseph Yiu

2.ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition

3.Two's Complement to Decimal Conversion ,http://sandbox.mc.edu/~bennet/cs110/tc/tctod.html 

4. ARM and Thumb-2 Instruction Set Quick Reference Card






-



  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值