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?
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?
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
I'm curious as to what is passing you a string on the stack and not via a ptr! :-)
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.
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
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.
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...
|All times are GMT -5. The time now is 03:50 AM.|