1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| @ 内存寻址模式 .section .data test_array: .word 1, 2, 3, 4, 5, 6, 7, 8 test_struct: .word 0x12345678, 0x9ABCDEF0, 0x11111111
.text .global memory_addressing
memory_addressing: @ 1. 基址寻址 ldr r0, =test_array ldr r1, [r0] @ r1 = test_array[0] @ 2. 基址+偏移寻址 ldr r2, [r0, #4] @ r2 = test_array[1] ldr r3, [r0, #8] @ r3 = test_array[2] @ 3. 基址+偏移寻址(预索引,更新基址) ldr r4, [r0, #12]! @ r4 = test_array[3], r0 += 12 @ 4. 基址寻址(后索引,先访问后更新) ldr r5, [r0], #4 @ r5 = *r0, r0 += 4 @ 5. 基址+寄存器偏移 mov r6, #2 ldr r7, [r0, r6, lsl #2] @ r7 = *(r0 + (r6 << 2)) @ 6. 基址+寄存器偏移(预索引) ldr r8, [r0, r6, lsl #2]! @ r8 = *(r0 + (r6 << 2)), 更新r0 @ 7. 基址+寄存器偏移(后索引) ldr r9, [r0], r6, lsl #2 @ r9 = *r0, r0 += (r6 << 2) @ 8. 相对寻址(PC相对) adr r10, test_array @ r10 = test_array的地址 @ 9. 多寄存器加载/存储的寻址模式 ldr r0, =test_array @ IA (Increment After) - 默认模式 ldmia r0, {r1, r2, r3, r4} @ 从r0开始加载,地址递增 @ IB (Increment Before) ldmib r0, {r1, r2, r3, r4} @ 先递增地址再加载 @ DA (Decrement After) ldmda r0, {r1, r2, r3, r4} @ 加载后地址递减 @ DB (Decrement Before) ldmdb r0, {r1, r2, r3, r4} @ 先递减地址再加载 @ 栈操作的特殊寻址 @ PUSH等价于STMDB sp! @ POP等价于LDMIA sp! bx lr
|