assembly function flow

后端 未结 3 1887
半阙折子戏
半阙折子戏 2021-01-23 12:32

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

3条回答
  •  难免孤独
    2021-01-23 12:55

    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
    

提交回复
热议问题