我是汇编的新手,执行以下内容时,我目前会遇到细分错误:
.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
我已经使用调试器发现分割故障的原因是两个分支Settes and setF,我知道这是由于试图写入非法内存位置的程序引起的。
但是,我不明白为什么这些分支无法写入R1,或者我应该做什么来解决此问题。任何帮助是极大的赞赏。
问题不是指令本身。问题是,在执行指令之后,例如setf
,执行继续进行不确定的内存。您需要确保在setf
和sett
之后执行返回v_bool
的代码。