[Solved] How an CPU finds location of a variable


It seems that you have some concept misunderstanding. In every program, there is a memory area called stack where local variables are allocated. In most computer architectures, there is a register called stack pointer (rsp in the x86_64 architecture) which points at the top of the stack (which grows from higher memory addresses to lower addresses).

In execution time, the program code (generated by the compiler, and not the OS) uses this stack pointer as the base to allocate its local variables. So your code would move the number 5 itself to a location that’s pointed by the current value of the stack pointer at the moment when main() was called, with an offset of 4 bytes (the location pointed by the current sp register is not known at all, because it is changing all the time with every function call).

2

solved How an CPU finds location of a variable