LinuxQuestions.org
Review your favorite Linux distribution.
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
 
LinkBack Search this Thread
Old 05-10-2007, 02:05 PM   #1
cdog
Member
 
Registered: Dec 2005
Posts: 65

Rep: Reputation: 15
Assembly - little problem with ret


Hei guys, I'm writting a small assembly problem that has to deal with a string received by value - I mean the entire string is in the stack. Everything works well until I have to return because I have to remove the string from the stack, but before I don't know from the start what's it's size in order to execute : ret size (where size=strlen*4). Is there a way to make a variable act as a constant for ret or maybe a workaround?
Thanks
 
Old 05-10-2007, 11:12 PM   #2
leosgb
Member
 
Registered: Nov 2004
Location: Brazil
Distribution: Gentoo
Posts: 363

Rep: Reputation: 31
Hi, can you try to make your message clearer? Maybe some pseudo code could help.

If you are going to process yout string in the routine then you dont need to worry about its size. You can have the string size passed thru a variable and later you loop decrementing it until you are done and you pop the values from the stack.

In the end you will have your return address in the stack so you just have to return.

Is this what you are looking for?
 
Old 05-11-2007, 12:26 AM   #3
Alien_Hominid
Senior Member
 
Registered: Oct 2005
Location: Lithuania
Distribution: Hybrid
Posts: 2,247

Rep: Reputation: 53
Maybe this:
pop value from stack
cmp it to what should be in the string
repeat it while they are different with loopnz
when different push value back to stack
now ret

Last edited by Alien_Hominid; 05-11-2007 at 12:27 AM.
 
Old 05-11-2007, 12:26 PM   #4
Dox Systems - Brian
Member
 
Registered: Nov 2006
Posts: 344

Rep: Reputation: 31
I'm curious as to what is passing you a string on the stack and not via a ptr! :-)
 
Old 05-11-2007, 12:33 PM   #5
cdog
Member
 
Registered: Dec 2005
Posts: 65

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by leosgb
Hi, can you try to make your message clearer? Maybe some pseudo code could help.

If you are going to process yout string in the routine then you dont need to worry about its size. You can have the string size passed thru a variable and later you loop decrementing it until you are done and you pop the values from the stack.

In the end you will have your return address in the stack so you just have to return.

Is this what you are looking for?
Not exactly. I cannot pop anything because the EIP is the last in the stack when the call to the function is made and "pop EIP" thriws an error: undefined symbol.

Alien_Hominid, as I said I cannot pop because of the EIP.
But I think I can save the last pushed dword into a register and after all the pops to push it back.
 
Old 05-11-2007, 01:41 PM   #6
leosgb
Member
 
Registered: Nov 2004
Location: Brazil
Distribution: Gentoo
Posts: 363

Rep: Reputation: 31
I see, so in that case you just pop it first and store it in a register. Then you have all your string on the stack so you can pop it one by one. After you are done you should push your EIP back to the stack because ret will pop it automatically from there.

Maybe this is what you want:

pop Some_register // will get your return address stored in a register
while (not end of string)
{
pop AX // bring current char to AX for processing
process_data_AX
}
push Some_register // return your desired address to stack
ret // will fetch your correct return address.

Does it make sense? If you could copy and paste this portion of your code it would make it easier for people to help you. Guessing is hard Good luck.
 
Old 05-11-2007, 03:35 PM   #7
Dox Systems - Brian
Member
 
Registered: Nov 2006
Posts: 344

Rep: Reputation: 31
That seems a little dangerous. Wouldn't be easier to just say, move esp into ebp and look at values based on ebp-"x" (or is it "+"? Stack grows down, right?)? then you don't have to mess around with popping the ret address, only to have to store it and push it back on right before the ret...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
emacs ctrl-m is RET. how to change ? Horos23 Linux - Software 1 11-12-2007 11:53 PM
assembly language: ret>>=10 ashlesha Programming 2 09-13-2006 04:11 AM
another problem in assembly usr Programming 1 01-31-2004 01:54 AM
Ask for help: Problem printing using Ret Hat Linux 9 agung100 Linux - Hardware 1 09-17-2003 11:43 PM


All times are GMT -5. The time now is 12:54 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration