This:
testl %esi, %esi
jle .L3
movl %esi, %eax
If testl
do a logical AND on esi
the result can't never be less but only equals, either if esi
is 0. In this way movl
can't be reached. It's that true, or I'm missing somethings.
Step two:
f1:
pushq %rbp
movq %rsp, %rbp
testl %esi, %esi
jle .L3
movl %esi, %eax
.L2:
incb (%rdi)
incq %rdi
decq %rax
jne .L2
.L3:
popq %rbp
ret
In a hypothetical C translation if .L3
consists of pop
then ret
and the branch take place it's possible to determine the value returned by the function?
JLE. Jump if Less or Equal.
In x86 assembly, al is the least significant byte of eax register, which is typically used to return values from function calls. The test al,al is a bitwise AND operation between al and itself. If al & al == 0, the zero flag will be set to 1.
In the x86 assembly language, the TEST instruction performs a bitwise AND on two operands. The flags SF , ZF , PF are modified while the result of the AND is discarded. The OF and CF flags are set to 0 , while AF flag is undefined.
eax contains the return value of strcmp. test is like bitwise and except it only sets the flags. Anding a value with itself gives the same value, so test eax, eax sets the flags based on whatever eax contains. ZF is set when the result of an operation is zero.
"Less than or equal" is defined as: ZF=1 or SF != OF
The TEST
instruction sets ZF
and SF
based on a logical AND
between the operands, and clears OF
.
So in effect you end up with the condition ZF or SF
, meaning "Less than or equal to zero" (i.e. the jump would be taken if (signed int)esi <= 0
in this case).
Edit: For the second part of your question, it looks like it's doing something along these lines:
void f1(char *c, int len)
{
if (len > 0) {
for (i = len; i != 0; i--) {
(*c)++;
c++;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With