Reputation: 143
I'm having some issues understanding some of the parts of the assembly code I am suppose to decipher into a loop
prob2:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
cmpl $1, %eax
je .L1
.L6:
testb $1, %al
je .L3
leal 1(%eax,%eax,2), %eax
jmp .L4
.L3:
shrl %eax
.L4:
cmpl $1, %eax
jne .L6
.L1:
popl %ebp
ret
Now I am given the general outline of the C code
void prob2(unsigned n)
{
while (________________) {
if (_______________) {
______________;
} else {
_______________;
}
}
}
I've figured out that the while loop tests to see whether n < 1, but in the next if-else part I am confused as to what the %al part is. I assume it's testing to see if it is equal to 1 and if it is (which it never will be because the while loop breaks when n = 1) then it shifts n to the right by a byte else it does the leal part and compares to see if it's not equal to 1 yet.
Does that sound right?
Upvotes: 2
Views: 130
Reputation: 49803
%al
is l
owest byte of the register %eax
, which is where you have determined that n
is being kept (based on your interpretation of cmpl $1, %eax
).
Upvotes: 1