JamesSchumacher
May 2nd, 2008, 04:25 PM
I am using inline assembler in C++ (VC++ cl.exe) and I think I am using this code correctly.
Is this 'one way' to access locals in assembler? I only wrote this out this way to get a better understanding of how it works. This does not crash when I call it, so I am believing it's correct.
__declspec(naked) void __stdcall TestLocals()
{
#define _LocalArray -32
_asm
{
push edi ; store the data index
sub esp,_LocalArray ; grow the stack pointer
xor edi,edi ; zero the data index
InternalLoop:
mov eax,4 ; size of an element
mul edi ; multiply by data index
mov ecx,esp ; stack pointer into ecx
add ecx,eax ; add the offset
mov DWORD PTR[ecx],100 ; move into the value
inc edi ; increment the data index
cmp edi,8 ; check to see if we need to continue
jb InternalLoop ; if so, unsigned check - continue the loop
add esp,_LocalArray
pop edi
xor eax,eax
ret 0
}
#undef _LocalArray
}
Is this 'one way' to access locals in assembler? I only wrote this out this way to get a better understanding of how it works. This does not crash when I call it, so I am believing it's correct.
__declspec(naked) void __stdcall TestLocals()
{
#define _LocalArray -32
_asm
{
push edi ; store the data index
sub esp,_LocalArray ; grow the stack pointer
xor edi,edi ; zero the data index
InternalLoop:
mov eax,4 ; size of an element
mul edi ; multiply by data index
mov ecx,esp ; stack pointer into ecx
add ecx,eax ; add the offset
mov DWORD PTR[ecx],100 ; move into the value
inc edi ; increment the data index
cmp edi,8 ; check to see if we need to continue
jb InternalLoop ; if so, unsigned check - continue the loop
add esp,_LocalArray
pop edi
xor eax,eax
ret 0
}
#undef _LocalArray
}