hi, i would like to use call to get to a label and want jump after a few instructions i want to jump back.
But when I use ret, the programm jump out from the whole proc-routine:

abs PROC
[...]
call label1
[...]
label1:
ret <-------what I have to do, to jump to the point where the label get called?
[...]
RET
abs ENDP
Posted on 2003-05-28 08:30:05 by Forginforcer
Try


abs PROC
[...]
call label1
[...]
label1:
pop eax
jmp eax
[...]
RET
abs ENDP
Posted on 2003-05-28 08:39:14 by roticv
many thanks !
Posted on 2003-05-28 09:24:58 by Forginforcer
ret <-------what I have to do, to jump to the point where the label get called?


Replace ret by retn.
Posted on 2003-05-28 11:17:47 by Frank
thangs for the great TIPS!
Posted on 2003-05-28 11:20:04 by Forginforcer

Try


abs PROC
[...]
call label1
[...]
label1:
pop eax
jmp eax
[...]
RET
abs ENDP


wow!! how does that work...does this mean that whenever u use 'call', its address gets pushed on to the stack??
Posted on 2003-05-28 14:43:24 by AnotherWay83
Yes. And ret pops off a dword of the stack and jumps there (to the address that was poped of).
This might make it easier for you:
call labelx

is equivalent to:
push @F
jmp labelx
@@: ; (the call instruction doesn't really use the @@ label.)

and

ret
is equivalent to:
pop eax ;(anyRegister will do, the actual ret instruciton doesn't use any register)
jmp eax


When knowing this one can do this:
(however, note that this is playing with the stack. And playing with the stack might cause headace (I've personally experienced this), so don't worry if you don't get the hold of what below instantly. )
push offset neverland
jmp here

neverland:
nop

Here:
push offset SomeOtherPlace
ret

SomeOtherPlace:
pop ebx
jmp ebx
Posted on 2003-05-28 15:44:29 by scientica

wow!! how does that work...does this mean that whenever u use 'call', its address gets pushed on to the stack??

Yup, that's why balancing the stack is important, if it isn't balanced the program will pop the wrong return address ;)
Posted on 2003-05-28 15:48:50 by donkey
ah i remember now! call pushes IP on the stack when a near proc is called, and CS and IP when a far proc is called...totally forgot abt that..and ret pops them off

thanks
Posted on 2003-05-28 17:26:49 by AnotherWay83
Correction in win32 it's EIP not IP, IP is 16-bit EIP is 32-bit.

The stack is hard to get flaw free (I've just finnihsed translating a "few" kB of masm code to fasm syntax, and I got a number of stack realated problems (the fact that I'm using a few "hacks" hasn't made it easier to find and fix the errors, the most irritating is the wvsprint* functions, they don't balance the stack them selves (masm did the job for me, and I know there are macros in fasm for those functions but that's things one deosn't think when translating), due to their calling conversion).
Posted on 2003-05-29 07:13:22 by scientica
Don't worry, scientica. I have my share of playing too much with the stack and landing at the wrong return address. I accidentally typed "push eax" instead of "call eax", and it was a horror looking through my source code debugging it, as it was full of push reg and call reg. :grin:
Posted on 2003-05-29 07:43:40 by roticv
Hi Scientica,

I had the same problem translating some of my favourite routines to GoAsm, eventually I just set up breakpoints and checked esp to see how much balancing was needed, several crashes later I got them all worked out. :tongue:
Posted on 2003-05-29 07:45:56 by donkey