免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5299 | 回复: 3
打印 上一主题 下一主题

关于ARM汇编指令BL的问题 [复制链接]

论坛徽章:
0
1 [报告]
发表于 2011-12-25 16:15 |显示全部楼层
B、BL指令都只能实现正负32M 地址空间内的跳转,通过向PC直接赋值的话,可以实现4GB地址空间内的任意跳转,要保留A程序的返回地址值,可以这样实现:

B_FUNC:

....
MOV LR,PC @保留A_FUNC返回地址
MOV PC,A_FUC@调用A_FUNC
....


A_FUC:
......
MOV PC,LR@从A_FUNC返回

论坛徽章:
0
2 [报告]
发表于 2011-12-27 17:25 |显示全部楼层
回复 4# garyv


     func_a 函数是汇编写的global函数吧,在func_b所在C函数这样用内嵌汇编调用func_a看看:

   extern void func_a(void);

   C_Function
    {
          .....
          void ((*function)(void)) = func_a;
          .....

          __asm("MOV LR,PC\n\t"
         "LDR PC,%[func]"::[func]"m"(function):"memory"); //调用func_a
     
          ....
   
    }

  

论坛徽章:
0
3 [报告]
发表于 2011-12-28 13:02 |显示全部楼层
回复 6# garyv


    asm("mov %[result], %[value], ror #1"  

: [result]"=r" (y) /* Rotation result. */  
: [value]"r" (x) /* Rotated value. */  
: /* No clobbers */  
);  
In the code section, operands are referenced by a percent sign followed by the related symbolic name enclosed in square brackets. It refers to the entry in one of the operand lists that contains the same symbolic name. From the rotating bits example:  

%[result] refers to output operand, the C variable y, and  
%[value] refers to the input operand, the C variable x.  

for more info,please refer to

共同学习

论坛徽章:
0
4 [报告]
发表于 2011-12-29 18:04 |显示全部楼层
回复 8# garyv

__asm("MOV LR,PC\n\t"
           "LDR PC,%0"::"m"(function));

这样也行,比较习惯%[name]这种形式,觉得比较清晰   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP