[英]From C to Assembly jge and jg?
如果語句中的第二個寄存器(例如cmpl%esi, %edi )大於或等於(或僅大於)第一個寄存器%esi,則 jg和jge是執行還是跳轉到以下標簽? 並且結果較大的結果是否存儲在第二個寄存器中,並用於確定跳轉是否執行了連續標簽?
sum1.c
int sum(int first, int last)
{
int sum = 0;
int in_between;
for (in_between = first; in_between <= last; in_between++)
{
sum += in_between;
}
return sum;
}
sum1.s:
.file "sum1.c"
.text
.globl sum
.type sum, @function
sum:
.LFB0:
.cfi_startproc
movl %edi, %edx ; puts first into in_between
movl $0, %eax ; sets sum to zero
cmpl %esi, %edi ;compares first and last, checking if first– last < 0
jg .L3 ; jumps to .L3 if first is greater than last, otherwise
;executes .L6
.L6:
addl %edx, %eax ;adds in_between to sum
addl $1, %edx ; increments in_between
cmpl %edx, %esi ; makes the comparison between in_between and last,
;last < in_between
jge .L6 ; jumps to .L6 if last is greater than or equal to
;in_between. (the result jump uses is stored in last).
.L3:
rep
ret ;returns the value stored in %eax register.
.cfi_endproc
.LFE0:
.size sum, .-sum
.ident "GCC: (GNU) 4.4.7 20120313 (Red Hat 4.4.7-17)"
.section .note.GNU-stack,"",@progbits
[幾乎]每條指令后,CPU都會更新處理器狀態(有時為PS,有時為PSL)寄存器。 CMPL指令執行隱式減法,並更新PS Rester的值。 如果執行SUBL指令,將會得到相同的效果,除了SUBL將結果放入目標操作數而CMPL則不然。
Jxx指令根據PS寄存器的值有條件地跳轉。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.