2017-08-13 38 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。

當您在閱讀本手冊時,您不瞭解這部分內容嗎?