I know this is a pretty basic question, but here it goes:
I am starting to learn Assembler, and I'm trying to understand how the stack works.
At first, when I pass a value to an assembler function, I'd access it like this:
movl 4(%esp),%eax # first parameter
movl 8(%esp),%ebx # second parameter
But I then was told that it was better to do this:
push %ebp
movl %esp,%ebp
# and then I'd access the values on %ebp:
movl 8(%ebp),%eax
movl 12(%ebp),%eax
pop %ebp
Ok, what is the difference here? When I accessed the values directly from %esp, weren't they already on the stack? What's the advantage of using push to do it again?
Does anyone have a tip on a good learning tool (for dummies-type) on how to learn how stack works so one can learn on these stack pointers, return addresses and so on? I haven't found any good visual demonstration on how it works. Thanks!