1

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.

Weston
  • 1,291
  • 3
  • 12
  • 25

1 Answers1

1

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

  • Count (4)
  • Start (array)
  • Return %eip (implicitly pushed by call);
  • %ebp.

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.

NPE
  • 486,780
  • 108
  • 951
  • 1,012
  • Oh I think I get it, so since *Start was the 3rd latest thing to be pushed to the stack, we need to move past the latest and 2nd latest things (4 bytes each) to get to the start of the *Start byte. The *Start byte contains an address to the array and _that_ is what's being incremented by 4. One more thing, at the end of the program they set the Stack to .pos 100. So say you push 4 bytes to the stack, with it be in addresses 100-103 or 0FD - 100? – Weston Oct 05 '14 at 07:34
  • Can you please take a look https://stackoverflow.com/questions/70919423/y86-instructions-set-create-confusion – Encipher Jan 30 '22 at 22:17