LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-09-2010, 06:28 PM   #1
With no.Mute
LQ Newbie
 
Registered: Feb 2009
Posts: 22

Rep: Reputation: 0
[ASM] Some questions about the stack.


I was hoping someone could explain to me, what is going on when you push something that is already on the stack?

Example:
Code:
pushl 8(ebp)
 
Old 09-09-2010, 07:21 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
I use intel syntax but I think it means the same as 'push [ebp+8]' - you'll get another copy of it at the top of the stack -

eg.

before:
Code:
ebp +8       -> 0x00000008
ebp +4       -> 0x00000009
ebp          -> 0x0000000a
ebp -4       -> 0x0000000b
esp          -> 0x0000000c
after: pushl 8(ebp)
Code:
ebp +8       -> 0x00000008
ebp +4       -> 0x00000009
ebp          -> 0x0000000a
ebp -4       -> 0x0000000b
ebp -8       -> 0x0000000c
esp          -> 0x00000008
Please correct me if my gas -> intel interpretation is wrong

hth
 
Old 09-09-2010, 07:28 PM   #3
With no.Mute
LQ Newbie
 
Registered: Feb 2009
Posts: 22

Original Poster
Rep: Reputation: 0
ok cheers, but why do that? i mean the data is already on the stack.
 
Old 09-09-2010, 08:34 PM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
It's probably about to call another function and this argument needed to be passed through ..

pseudo code:
Code:
push arg2
push arg1
call myfunc_a
..
# inside myfunc_a
...
push [ebp+8]        # <- original myfunc_a:arg2 pushed (copied) to be validate_arg:arg1
call validate_arg
Depending on the calling convention, arguments may be expected in registers or on the stack - usually starting at [ebp+8] after the standard function preamble has modified ebp to create a new stack frame

You may need to post a bit more code for an accurate assessment

cheers

Last edited by kbp; 09-09-2010 at 08:37 PM.
 
Old 09-09-2010, 10:18 PM   #5
With no.Mute
LQ Newbie
 
Registered: Feb 2009
Posts: 22

Original Poster
Rep: Reputation: 0
ah ok i understand now thanks for clearing that up =]
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
single 8K process stack vs 4K process stack and a seperate 4K interrupt stack charvak Linux - Kernel 1 03-17-2010 06:58 PM
Difference b/t Kernel stack and User stack hazzyb Linux - Software 2 09-29-2008 07:40 PM
ASM x32 vs ASM x64 Tegramon Programming 3 02-27-2008 02:26 PM
ASM and Stack Questions Mercurius Programming 6 06-26-2006 11:30 PM
stack organization questions 0x0000h Linux - Security 2 08-26-2005 11:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration