Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between PUSH eax and mov [esp], eax?

Tags:

x86

assembly

What is the difference between the two lines

push eax

mov [esp], eax

Doesn't push eax on to the stack (where esp is pointing to just as mov [esp], eax does?)

like image 565
Zimm3r Avatar asked Sep 06 '13 14:09

Zimm3r


1 Answers

"push" will automatically bump the value of "esp" (your stack pointer). The "mov" won't. So i if you wanted to put multiple items on the stack, with push, you just do:

push eax
push ebx
...

With mov, to get the same results, you'd have:

sub  esp,4
mov  [esp], eax
sub  esp,4
mov  [esp], ebx
...

And the nice thing about push is that there is the reverse operation, pop which allows you to pull things back off in reverse order. Which is, of course, what a stack is all about. :)

like image 176
lurker Avatar answered Nov 10 '22 22:11

lurker