![]() |
| ||
| Function return values Hello, i'm developing a simple assembly (AT&T) program as exercise in preparation of an exam and i have a problem: I need to pass 4 return values of a function using the stack. I know that after the "call", %esp points to the return address that will be used from the "ret". I've tried to pop that value from the stack, push my return values and then push the return address again just before the "ret" but it doesn't work. Can i have an help please? Where do i need to put those values in the stack? And how do i have to manipulate the %esp or %ebp? Thanks |
| ||
| Re: Function return values val1 = func( &apple, &bat, &cat, &dog ) The address of apple, bat, cat, and dog are now on the stack. here's one method! ZZ equ ???? ; I forget the actual number to use try 8? |
| ||
| Re: Function return values ESP points to the current top of stack, PUSH & POP implicity decrement and increment ESP. Right upon entering your function ESP points to a DWORD containing the return address (address of the instruction past the CALL). RET will pop the DWORD off the stack (according to the value of ESP so make sure ESP points to the return address) to implicitly change the contents of IP. If you reserve space on the stack for a couple of DWORDs (if you need to return two values) before you CALL your function, to do so simply subtract 8 from ESP before calling your function. [ ] <-------Bottom of stack | Higher Address [ ] Space 2 [ ] Space 1 [ ] Return Address | Lower Address Then copy ESP into EBP to index into the stack, once in your function to place the return values on the stack. To copy into Space 1 use movl src,4(%ebp) To copy into Space 2 use movl src,8(%ebp) |
| ||
| Re: Function return values push bp Of course it would be a whole lot easier to use registers to return a value; or do as Wildgoose says, and push the address of variables onto the stack if you want to return more than one. |
| ||
| Re: Function return values mathematician your right you can just place the address of the memory variables on the stack, this would be a good method. AT&T syntax goes: mnemonic src,dest myfunc: 16-bit example: myfunc: |
| All times are GMT -4. The time now is 8:27 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC