Why function call stack?

Why is the introduction of the stack

Complete the process of function calls, we need to have a place to store address instruction after the function call returns to be executed (referred to as the return address)

Time Geeks - deep Principles of Computer Composition

A function call, the stack use

A1
call B
A3

B1
B2
retq
  • Register rip: store the address of the next instruction to be executed
  • callq instructions to do two things
  1. A3 push the rip address (that is, the address of that instruction after the called function returns, the caller could have been the next will be executed) // Actually, this instruction addresses are placed in a rip, would normally executed, call instruction but was hijacked.
  2. The first instruction of the called function address in the rip, so that the cpu starts executing a subroutine.
  • retq instructions to do a thing
  1. A3 pop the stack, into the rip. Continue down the cpu so that A plus function.

-3.7-depth understanding of computer systems

Guess you like

Origin www.cnblogs.com/yudidi/p/12439271.html