Answer the question
In order to leave comments, you need to log in
Where and how is the variable name stored?
Such is the general question caused by insufficient knowledge in the field of iron architecture.
When we declare variables, where are they stored? It is clear that in memory cells, but how exactly? One character in one cell, the second in another, because all this is somehow collected or what?
ps Yes, and what should I read (from the current books or what architecture should I start with) to stop asking such stupid questions?
Answer the question
In order to leave comments, you need to log in
The variable name is not stored anywhere.
If it’s simple, then: the compiler converts the variable name into an address, and then the address appears wherever the name was in the code.
If it's more complicated, then for stack variables (local variables of a function) - this will not even be an address, but an offset relative to the beginning of the function stack. And the beginning of the function stack is written to one of the processor registers. The address of a local variable is obtained by adding the register and the offset.
For global variables, the address. But even here it is somewhat more complicated, because. the real address appears only after the OS has loaded the program into memory, and here the OS loader and compiler work in pairs.
Variable names are written for the human developer for ease of reading and perception. The hardware processor only needs the address of this variable, it does not need a name.
For a compiled language (which is C), in the object file (and will be thrown away when the linker builds the EXE) and in debug data. Nowhere else. Variables are distinguished by their address.
Take DosBox, take the good old Turbo Assembler and assemble some COM file (even if it's a manual). And then take a hacker viewer like Hiew and look at the disassembler of what happened. Why COM - because it is simple.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question