The offsets of local variables are “baked” into machine code as constants. By the time the compiler finishes, the things that your program calls local variables are replaced by the fixed memory offsets assigned by the compiler.
Let's say you declare three local variables:
char a[8];
int b;
short c;
The compiler assigns offsets to these variables: it ais in an offset 0, bis in an offset 8, and cis in an offset 12. Let's say your code does b += c. The compiler translates this into a block of code that looks like this:
LOAD @(SP+8)
ADD @(SP+12)
STORE @(SP+8)
The only value that changes here is SP(stack pointer). All offsets are numerical constants.
source
share