如果语句中的第二个寄存器例如.cmpl%esi,%edi 大于或等于(或仅大于),则jg和jge是执行还是跳转到以下标签首先注册%esi ?并且结果是一个更大的存储在第二个寄存器中并用于确定跳转是否执行连续标签?
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
答案 0 :(得分:1)
CPU在[几乎]每条指令后更新处理器状态(PS有时是PSL)寄存器。 CMPL指令执行隐式减法并更新PS rester的值。如果你做了SUBL指令,你会得到相同的效果,除了SUBL将结果放在目标操作数中,而CMPL没有。
Jxx指令有条件地分支,具体取决于PS寄存器的值。