簡體   English   中英

很難理解GCC匯編指令來計算條件跳轉

[英]Hard to understand GCC assembly instructions to calculate conditional jump

我有以下代碼:

if(( a<0 ) || ( a>global_count ))  //global_count is a global int
{
    print error;
}

normal_flow
    ...

現在這是GCC生成的匯編程序:

cmpl 0x0 , 0x10(%ebp) //first check
js print_error
mov 0x8(%ebp) , %eax
mov 0x8(%eax) , %eax 
cmp 0x10(%ebp) , %eax //second check
jge normal_flow
print_error

我不明白為什么jge 我看到它使用的是mov ,而不是movl ,但我相信在這種情況下它應該是jle ,如果我們改變跳躍目標那么jg ...或者我在這里想錯了?

它是jge因為編譯器交換了操作數和條件。 它在做global_count >= a 請注意, 0x10(%ebp)a%eaxglobal_count 更復雜的是,在&t語法本身有操作數反轉。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM