본문 바로가기
csapp

3.7.1 The Run-Time Stack

by 정구지개발자 2023. 4. 18.
728x90
  • A key feature of the procedure-calling mechanism of C, and of most other languages, is that it can make use of the last-in, first-out memory management disci- pline provided by a stack data structure.
  • the x86-64 stack grows toward lower addresses and the stack pointer %rsp points to the top element of the stack.
  • When an x86-64 procedure requires storage beyond what it can hold in reg- isters, it allocates space on the stack.
  • This region is referred to as the procedure’s stack frame

 

 

3.7.2 Control Transfer

  • The call instruction has a target indicating the address of the instruction where the called procedure starts. Like jumps, a call can be either direct or indirect.

  • indicated values for the stack pointer %rsp and the program counter %rip.

 

3.7.3 Data Transfer

  • we have already seen numerous examples of functions where arguments are passed in registers %rdi, %rsi, and others, and where values are re- turned in register %rax.
  • When procedure P calls procedure Q, the code for P must first copy the arguments into the proper registers. Similarly, when Q returns back to P, the code for P can access the returned value in register %rax

 

  • When a function has more than six integral arguments, the other ones are passed on the stack.
  • When passing parameters on the stack, all data sizes are rounded up to be multiples of eight.
  • If Q, in turn, calls some function that has more than six arguments, it can allocate space within its stack frame for these, as is illustrated by the area labeled “Argument build area” in Figure 3.25.

 

728x90

'csapp' 카테고리의 다른 글

3.8.3 Nested Arrays  (0) 2023.04.19
3.7.4 Local Storage on the Stack  (0) 2023.04.18
3.6.8 Switch Statements  (0) 2023.04.14
3.6.7 Loops  (0) 2023.04.14
3.6.5 Implementing Conditional Branches with Conditional Control  (0) 2023.04.13

댓글