[gameprogrammer] Pushing on stack in assembly
- From: Kevin Jenkins <gameprogrammer@xxxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Fri, 21 Mar 2008 22:18:55 -0700
I'm writing code to support variadic remote procedure calls in RakNet.
I concatenate the parameter list of a function to an array of bytes.
On the recipient, I read the length of the array, push this amount on
the stack, and copy the memory onto the stack. I then call the function.
Problem is, my assembly sucks.
C++:
struct MyStruct
{
char a[50];
};
void _cdecl func2(MyStruct b)
{
}
Assembly:
// Bytes to pass, rounded up to 4
sub esp,34h
// Loop counter (where does the 80 come from) ?
mov ecx,0Ch
// Load esi with address of variable
lea esi,[ebp-3Ch]
// Copy esp to edi
mov edi,esp
// * Moves a byte, word or doubleword (8 bytes) from data segment and
offset esi to extra segment and offset edi .
// * Increments/decrements both edi and esi :
// ecx stores count, not sure how it is calculated yet
rep movs dword ptr es:[edi],dword ptr [esi]
// Copy out remainder bytes
movs word ptr es:[edi],word ptr [esi]
// Call function
00413734 call func2 (4111EFh)
// Take bytes off stack
00413739 add esp,34h
My questions are:
1. Will it even work at all, to concatenate input parameters, then
just push that whole concatenated array onto the stack?
2. Where does the value of ecx come from? I'm pushing 50 bytes onto
the stack
3. How cross platform is this?
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- Follow-Ups:
- [gameprogrammer] Re: Pushing on stack in assembly
- From: Chris Nystrom
Other related posts:
- » [gameprogrammer] Pushing on stack in assembly
- » [gameprogrammer] Re: Pushing on stack in assembly
- » [gameprogrammer] Re: Pushing on stack in assembly
- » [gameprogrammer] Re: Pushing on stack in assembly
- » [gameprogrammer] Re: Pushing on stack in assembly
- » [gameprogrammer] Re: Pushing on stack in assembly
- » [gameprogrammer] Re: Pushing on stack in assembly
- » [gameprogrammer] Re: Pushing on stack in assembly
- » [gameprogrammer] Re: Pushing on stack in assembly
- » [gameprogrammer] Re: Pushing on stack in assembly
- [gameprogrammer] Re: Pushing on stack in assembly
- From: Chris Nystrom