Features global variables and local variables

Features global variables

  1, global variables after the program has finished compiling addresses have already been determined, as long as the program starts, global variables already exist, whether the start there if given the initial value depends on the value of the statement, and if not, the default is 0
  2, the values of global variables can be modified by all functions, which are stored last modified value.
  3, global variables share memory will always exist, we know that the end of the whole process.
  4, disassemble identify global variables:
  MOV register , byte / word / dword ptr ds : [0x12345678]
  is determined by the global variable width register, or byte / word / dword width global variable is called base address

  

 1 int g_n = 10;            
 2 int Function()            
 3 {            
 4     int x = 2;        
 5     int y = 3;        
 6             
 7     return g_n+x+y;        
 8 }            
 9 int Function2()            
10 {            
11             
12     int y = 3;        
13             
14     return g_n+x+y;        
15 }    

 

Local variable characteristics:

  1, local variables are not allocated in the program compiled a fixed address.
  2, when the method belongs not called, local variables and does not allocate memory only when the program belongs is called, will be on the stack memory allocation.
  3, after the implementation of the method when the local variable belongs, the memory occupied by the local variable becomes garbage data. local variables disappears.
  4, local variables can only be used within the method, the function a can not use a local function B variable
  5, disassembly identifying local variables:
  [-EBP. 4]
  [-EBP. 8]
  [EBP-0xC]

 1 int Function()            
 2 {            
 3     int x = 2;        
 4     int y = 3;        
 5             
 6     return g_n+x+y;        
 7 }            
 8 int Function2()            
 9 {            
10     int x = 3;        
11     int y = 4;        
12             
13     return g_n+x+y;        
14 }    

 

Guess you like

Origin www.cnblogs.com/Reverse-xiaoyu/p/11620321.html