C Function Call Convention: Why movl instead of pushl?

I don't understand why the following lines are used movl

to enter data under the stack pointer are generated by GCC.

movl    -4(%ebp), %eax      # -4(%ebp) <- local variable 1
movl    8(%ebp), %edx       # 8(%ebp)  <- first parameter
movl    %edx, 8(%esp)       # ??? WHY NOT:   pushl %edx
movl    %eax, 4(%esp)       # ??? WHY NOT:   pushl %eax
movl    -8(%ebp), %eax      # ??? WHY NOT:   pushl -8(%ebp)
movl    %eax, (%esp)
call    athena
movl    %eax, f

      

(full code)

I think this code is trying to push 3 parameters to call a function. But why doesn't he use pushl

. What is the use of this code and how does it work?

0


source to share


1 answer


Hans Passant answered correctly. The push / pop codes can be split into two microoperators that move memory and increment / decrement the stack pointer. If the stack pointer โ€” or any pointer โ€” is updated and then immediately used in the next opcode, it usually fails. By accessing individual memory locations using the stack pointer, as in your example, there would be no stops and the operations could be chained, allowing them to execute at the same time.



Any superscalar CPU type will try to execute multiple opcodes in one cycle if their results / sources have nothing to do with each other. The compiler does something for you to speed up execution, which would be time consuming enough to do it manually. Opcodes can take up more space than pushes, but they will run about twice as fast - everything else is the same.

+3


source







All Articles