2017-08-13 36 views
-1

在下面的代码中,当我使用./filename ; echo $?编译并执行它时,我得到4。为什么?ARM中的程序集如何使用比较助记符?

.global _start 

_start: 

    mov R1,#1 
    mov R2,#2 
    cmp R1,R2 
    BGT bigger 

bigger: 

    mov R0,#4 
    B end 

_default: 

    mov R0,#3 

end: 

    mov R7,#1 
    swi 0 
+0

您是否尝试过使用调试器? –

+0

@RaymondChen我不知道如何使用gdb,如果你能指导我通过它,那将是美好的。 – user7083361

+1

你无法格式化。我的建议是:在学习如何使用基本工具之前,请勿触碰汇编程序 –

回答

1

既然你是编程,你已经有一个指令集的参考权像ARM体系结构参考手册(ARM ARM),正确的汇编语言?而当你在读的手动操作下的CMP指令,你发现:

if ConditionPassed(cond) then 
alu_out = Rn - shifter_operand 
N Flag = alu_out[31] 
Z Flag = if alu_out == 0 then 1 else 0 
C Flag = NOT BorrowFrom(Rn - shifter_operand) 
V Flag = OverflowFrom(Rn - shifter_operand) 

然后在该分支指令下

if ConditionPassed(cond) then 
if L == 1 then 
LR = address of the instruction after the branch instruction 
PC = PC + (SignExtend(signed_immed_24) << 2) 

,并同时为COND字段描述执行或不执行所需要的条件指令

1100 GT Signed greater than Z clear, and either N set and V set, or 
N clear and V clear (Z == 0,N == V) 

1110 AL Always (unconditional) 

如果没有指定其他条件,则暗示AL。

当您在阅读本手册时,您不了解这部分内容吗?