I'm a beginner in the X86 assembly language. Can someone give an example of local and global variables? In particular, how are they initialized? Where are they stored? How are they accessed?
What's the difference between local and global variables in 32-bit X86?
5.5k views Asked by Meteorite At
1
In x86 assembly, global variables are also referred as static data regions. You can find a good tutorial here - from which I pasted some information. Here is an example of declaring globals:
The globals can then be accessed from any place in the code, in any method without having them passed as arguments.
Local variables are being stored in the stack space, and are processed generally by copying them into registers, doing computations and put them back on the stack.
Let's say you want to call a function. The parameters you pass to the function will be locals for that function.
When the code enters the function, it needs to get them from the stack, using pop:
So in eax, ebx, ecx you have values for local variables. After you modify them you can always put them again on the stack and pop them out as you need them.
Hope this helps.