arm彙編學習(六)---跳轉到thumb狀態

一般函數返回使用 pop {r7,pc}或bx lr等方式(bx,b相似jmp爲跳轉指令,但bx能夠指定跳轉區域究竟爲thumb仍是arm指令。
thumb指令指令的時候,直接填寫該地址卻老是產生SIGSYS信號(非法指令執行)。
緣由就是該函數爲thumb指令,所以跳轉時必需要把指令地址的最低位設置爲1(bx 經過這一位來區分指令集),因此函數地址就加了一。php


thumb指令集與arm指令集切換electron

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-thumbspa

相關文章
相關標籤/搜索