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

通常函数返回使用 pop {r7,pc}或bx lr等方式(bx,b类似jmp为跳转指令,但bx可以指定跳转区域究竟为thumb还是arm指令。
thumb指令指令的时候,直接填写该地址却总是产生SIGSYS信号(非法指令执行)。
原因就是该函数为thumb指令,因此跳转时必须要把指令地址的最低位设置为1(bx 通过这一位来区分指令集),所以函数地址就加了一。


thumb指令集与arm指令集切换

mov
R0,#5     ;Argument to function is in R0
add
R1,PC,#1     ;Load address of SUB_BRANCH, Set for THUMB by adding 1
BX     R1     ;R1 contains address of SUB_BRANCH+1
;Assembler-specific instruction to switch to Thumb
SUB_BRANCH:
BL
thumb_sub     ;Must be in a space of +/- 4 MB
add
R1,#7     ;Point to SUB_RETURN with bit 0 clear
BX
R1
;Assembler-specific instruction to switch to ARM 
SUB_RETURN:


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

参考:
http://bbs.pediy.com/showthread.php?t=127501
http://www.embedded.com/electronics-blogs/beginner-s-corner/4024632/Introduction-to-ARM-thumb

原文地址:https://www.cnblogs.com/moonflow/p/3245906.html