I'm confused about this example program from my computer architecture textbook.
Here's the C code...
And here's the generated Y86 code...
My question is with 0x046
mrmovl 8(%ebp), %ecx
Why exactly is it setting Start to 8 bytes in front of the stack pointer? I think I'm mostly confused as to where everything is. Like if the stack is looking at 0x100, why exactly is %ecx being set to 8 bytes away from there, and then being incremented by 4 when Count is already being set to 12 bytes away from %ebp? My understanding of what exactly the stack pointers are looking at is probably wrong.
The code pushes things onto the stack in the following order:
Count
(4
)Start
(array
)%eip
(implicitly pushed by call
);%ebp
.The code then sets %ebp
to %esp
, and the stack looks like this:
(You are mainly interested in the part marked %EBP
and above.)
Hope this clarifies things. You can read more here.