ldr作爲用法在arm中比較常見,爲了搞清楚其區別今天特意寫了一個demo,貼出來把心得記下來。
ADS1.2的工程
代碼路徑:http://download.csdn.net/download/losting_boy/9620660
//start.s
AREA SCopy, CODE, READONLY
COUNT EQU 0x300
IMPORT test
entry
start
;僞指令
ldr r0,=COUNT
;跳轉方式1(位置不相關)反彙編中有很多類似的用法
ldr r1,=(test1 - tag)
mov lr,pc
add pc,pc,r1
;跳轉方式2
mov lr,pc
tag ldr
pc,=test
;跳轉方式3
mov lr,pc
b test
;跳轉方式4
bl test
;加載寄存器r2中地址的內存區間
ldr r3,[r2]
mov lr,pc
b test2
test1
mov r5,#0x1
mov pc,lr
test2
;注意二者的區別,前者是指令對應的內存地址,是代碼指令的地址,
ldr r4,test1 //首先test1其實就是地址,這裏加載的[test1]處的內存
ldr r5,=test1 //僞指令,就是test1地址賦值給r5,這個表述有些麻煩最好能調試看下
ldr r6,=(test2 - test1) //僞指令,賦值test2 - test1
//可以調試下上面三者
stop
b .
END
//test.c
#include <stdio.h>
extern int test(int i,int j);
int test(int i,int j)
{
int c = 0;
i++;//
i = i + 3;
sub_func(10,1,2,3,4,5);
c = c+4;
}
//這個故意寫了5個參數,主要是反編譯看下ATPCS約定
int sub_func(int a,int b,int c,int d,int f)
{
return a - b - c - d - f;
}