[英]ARM Assembly Branch Segmentation Fault
我是組裝的新手,在執行以下操作時當前遇到分段錯誤:
.global _start @ Provide program starting address to linker
_start: mov R0,#0 @ A value of 1 indicates "True"
bl v_bool @ Call subroutine to display "True" or "False"
mov R0,#0 @ Exit Status code of 0 for "normal completion"
mov R7,#1 @ Service command 1 terminates this program
svc 0 @ Issue Linux command to terminate program
@ Subroutine v_bool wil display "True" or "False" on the monitor
@ R0: contains 0 implies false; non-zero implies true
@ LR: Contains the return address
@ Registers R0 through R7 will be used by v_bool and not saved
v_bool: cmp R0,#0 @ Set condition flags for True or False
beq setf
bne sett
mov R2,#6 @ Number of characters to be displayed at a time.
mov R0,#1 @ Code for stdout (standard output, monitor)
mov R7,#4 @ Linux service command code to write.
svc 0 @ Call Linux command
bx LR @ Return to the calling program
sett: ldr R1,=T_msg
setf: ldr R1,=F_msg
.data
T_msg: .ascii "True " @ ASCII string to display if true
F_msg: .ascii "False " @ ASCII string to display if false
.end
我已經使用調試器來發現分段錯誤的原因是sett和setf這兩個分支,並且我知道這是由於程序試圖寫入非法內存位置引起的。
但是,我不明白為什么這些分支無法寫入R1,或者我應該怎么做才能解決此問題。 任何幫助是極大的贊賞。
問題不是說明本身。 問題是,在例如setf
處執行了指令之后,執行繼續到未定義的內存。 你需要確保執行后setf
和sett
追溯到的代碼v_bool
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.