Memory assignment of local variables
Posted
by Mask
on Stack Overflow
See other posts from Stack Overflow
or by Mask
Published on 2010-03-30T02:47:35Z
Indexed on
2010/03/30
2:53 UTC
Read the original article
Hit count: 381
void function(int a, int b, int c) {
char buffer1[5];
char buffer2[10];
}
We must remember that memory can only be addressed in multiples of the word size. A word in our case is 4 bytes, or 32 bits. So our 5 byte buffer is really going to take 8 bytes (2 words) of memory, and our 10 byte buffer is going to take 12 bytes (3 words) of memory. That is why SP is being subtracted by 20.
Why it's not ceil((5+10)/4)*4=16?
© Stack Overflow or respective owner