본문 바로가기
csapp

3.7.4 Local Storage on the Stack

by 정구지개발자 2023. 4. 18.
728x90
  • At times, however, local data must be stored in memory. Common cases of this include these:
  • There are not enough registers to hold all of the local data.
  • The address operator ‘&’ is applied to a local variable, and hence we must be able to generate an address for it.
  • Some of the local variables are arrays or structures and hence must be accessed by array or structure references. We will discuss this possibility when we describe how arrays and structures are allocated.
  • a procedure allocates space on the stack frame by decrementing the stack pointer.

3.7.5 Local Storage in Registers

  • registers %rbx, %rbp, and %r12–%r15 are classified as callee- saved registers.

    The pushing of register values has the effect of creating the portion of the stack frame labeled “Saved registers” in Figure 3.25.

  • With this convention, the code for P can safely store a value in a callee-saved register (after saving the previous value on the stack, of course), call Q, and then use the value in the register without risk of it having been corrupted.
  • All other registers, except for the stack pointer %rsp, are classified as caller- saved registers.

 

3.7.6 Recursive Procedures

  • The conventions we have described for using the registers and the stack allow x86-64 procedures to call themselves recursively. Each procedure call has its own private space on the stack, and so the local variables of the multiple outstanding calls do not interfere with one another

 

3.8 Array Allocation and Access

 

  • suppose E is an array of values of type int and we wish to evaluate E[i], where the address of E is stored in register %rdx and i is stored in register %rcx. Then the instruction
movl (%rdx,%rcx,4),%eax

 

will perform the address computation xE + 4i, read that memory location, and copy the result to register %eax.

 

 

3.8.2 Pointer Arithmetic

 

728x90

'csapp' 카테고리의 다른 글

3.9.2 Unions  (0) 2023.04.22
3.8.3 Nested Arrays  (0) 2023.04.19
3.7.1 The Run-Time Stack  (2) 2023.04.18
3.6.8 Switch Statements  (0) 2023.04.14
3.6.7 Loops  (0) 2023.04.14

댓글