摘自 ARM 程序分析与设计 王宇行
1.在 C 中声明函数原型,并加extern 关键词
extern int num;
exitern int sqr(int i);
2.在汇编中,用EXPROT 导出函数名,并用该函数名作为汇编代码段的标志
EXPORT sqr
EXPORT num
- 1. AREA |.text|,CODE,READONLY
-
2. IMPORT Relacation
-
3. EXPORT sqr
-
4. EXPORT num
-
5. ldr r5,=Relacation
-
6. sqr
-
7. MUL R1,R0,R0 ;R1=R0*R0
-
8. MOV R0,R1 ;R0=R1
-
9. MOV PC,LR ;return R0
-
10. AREA |.data|,NOINIT,READWRITE
-
11. data SPACE 1024
-
12. END
- 1. #include<stdio.h>
-
2. extern int num;
-
3. extern int sqr(int i)
-
4.
-
-
5. int Relocation=0;
-
6. int main(void)
-
7. {
-
8. printf("square of %d is %d\n",num,sqr(num));
-
9. }
阅读(2629) | 评论(0) | 转发(0) |