新闻中心

EEPW首页>嵌入式系统>设计应用> arm汇编学习(六)跳转到thumb状态

arm汇编学习(六)跳转到thumb状态

作者: 时间:2016-11-09 来源:网络 收藏
通常函数返回使用 pop {r7,pc}或bx lr等方式(bx,b类似jmp为跳转指令,但bx可以指定跳转区域究竟为thumb还是arm指令。

thumb指令指令的时候,直接填写该地址却总是产生SIGSYS信号(非法指令执行)。
原因就是该函数为thumb指令,因此跳转时必须要把指令地址的最低位设置为1(bx 通过这一位来区分指令集),所以函数地址就加了一。

本文引用地址://m.amcfsurvey.com/article/201611/317578.htm


thumb指令集与arm指令集切换

movR0,#5 ;Argument to function is in R0addR1,PC,#1 ;Load address of SUB_BRANCH, Set for THUMB by adding 1BX R1 ;R1 contains address of SUB_BRANCH+1;Assembler-specific instruction to switch to ThumbSUB_BRANCH:BLthumb_sub ;Must be in a space of +/- 4 MBaddR1,#7 ;Point to SUB_RETURN with bit 0 clearBXR1;Assembler-specific instruction to switch to ARM SUB_RETURN:


arm状态下指令的地址末两位都是0
thumb状态下指令地址的末尾是0
thum1+1表明你即将跳入thumb状态,系统会自动调整地址的



评论


技术专区

关闭