cassemblyarchitecturex86y86

Y86 Sum program confusion


I'm confused about this example program from my computer architecture textbook.

Here's the C code...

enter image description here

And here's the generated Y86 code...

enter image description here

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.


Solution

  • The code pushes things onto the stack in the following order:

    The code then sets %ebp to %esp, and the stack looks like this:

    stack layout

    (You are mainly interested in the part marked %EBP and above.)

    Hope this clarifies things. You can read more here.