These two QWORDS are notThese two QWORDS are not arguments but local variables. You can recognize this, because of the negative offset (variables are above the base pointer and the stack is growing towards lower addresses). x64 assembler gives the first arguments but local variables. You can recognize thisin registers, because of the negative offset (variables are above the base pointer andso the stackfirst line is growing towards lower addresses)a function argument. The second one is a local variable. Since they are QWORDS, the datatype has a length of 8 byte. The first instruction assigns the value of rdi
to a local variable (say var_18
) and the second assigns 0 to another local variable (say var_8
).
And then we are at the comparison to 0 again. So going over all these lines, it is obvious that this is a loop where the value of rdi
argument is loaded into var_18
a number which then acts as a counter, from which is counted down to zero. The second local variable var_8
is simply the sum of the different counter values. For example if var_18
has 5 then the result would be 5+4+3+2+1=15.
The corresponding C code would be similar to this for loading var_18
with 5.
long foo() {
long var_18 =nr) 5;{
long var_8 = 0;
while(var_18nr != 0) {
var_8 += var_18nr--;
}
return var_8;
}