I am reading a \"programming from the ground up\", if you don\'t know what this book is, you still can help me.
In this book(chapter 4) there are 2 things that I don\'t
I believe that this:
movl 8(%ebp), %ebx #put first argument in %eax
was a typo, and it should really be:
movl 8(%ebp), %ebx #put first argument in %ebx
and if you noticed, later the code is correct:
movl %ebx, -4(%ebp) #store current result
In the end, the author could have used %eax
for this operation as well (instead of %ebx
), there's no reason why he shouldn't since it wouldn't change the program at all.
But the comment could be a lot clearer and I believe that this is a typo as well. At this point, it would be better if it said: #storing 1st argument on the local stack frame
.
label power_loop_start uses that variable and temporarily stores it in %eax
for quick operations and then place it back on the same location on the stack for the next loop:
movl %eax, -4(%ebp) #store the current result
decl %ecx #decrease the power
jmp power_loop_start #run for the next power