JamesSchumacher
May 2nd, 2008, 03:27 PM
Consider the following function.
void * __stdcall MemAlloc2(unsigned long dwSize)
{
return ::HeapAlloc(::GetProcessHeap(),HEAP_ZERO_MEMORY,dwSize);
}
Below is the VC++ generation for this function.
_TEXT SEGMENT
_dwSize$ = 8 ; size = 4
?MemAlloc2@@YGPAXK@Z PROC NEAR ; MemAlloc2
; Line 25
push ebp
mov ebp, esp
; Line 26
mov eax, DWORD PTR _dwSize$[ebp]
push eax
push 8
call DWORD PTR __imp__GetProcessHeap@0
push eax
call DWORD PTR __imp__HeapAlloc@12
; Line 27
pop ebp
ret 4
?MemAlloc2@@YGPAXK@Z ENDP ; MemAlloc2
_TEXT ENDS
Now here is the inline assembly I use. (This is probably something to do with the preprocessor, or it's a bug in the compiler/assembler)
{
#define _dwSize 8
_asm
{
push ebp
mov ebp,esp
mov eax, DWORD PTR _dwSize[ebp]
push eax
push HEAP_ZERO_MEMORY
call DWORD PTR GetProcessHeap
push eax
call HeapAlloc
pop ebp
ret 4
}
#undef _dwSize
}
Here is what it looks like in the output.
_dwSize$ = 8 ; size = 4
?MemAlloc@@YGPAXK@Z PROC NEAR ; MemAlloc
; File h:\documents\masm projects\inlinasm\main.cpp
; Line 8
push ebp
; Line 9
mov ebp, esp
; Line 11
mov eax, DWORD PTR [ebp+8]
; Line 12
push eax
; Line 13
push 8
; Line 14
call DWORD PTR __imp__GetProcessHeap@0
; Line 15
push eax
; Line 16
call __imp__HeapAlloc@12
; Line 18
pop ebp
; Line 20
ret 4
?MemAlloc@@YGPAXK@Z ENDP ; MemAlloc
_TEXT ENDS
???
EDIT....
Nevermind, adding DWORD PTR in front of the call to HeapAlloc fixed it.
void * __stdcall MemAlloc2(unsigned long dwSize)
{
return ::HeapAlloc(::GetProcessHeap(),HEAP_ZERO_MEMORY,dwSize);
}
Below is the VC++ generation for this function.
_TEXT SEGMENT
_dwSize$ = 8 ; size = 4
?MemAlloc2@@YGPAXK@Z PROC NEAR ; MemAlloc2
; Line 25
push ebp
mov ebp, esp
; Line 26
mov eax, DWORD PTR _dwSize$[ebp]
push eax
push 8
call DWORD PTR __imp__GetProcessHeap@0
push eax
call DWORD PTR __imp__HeapAlloc@12
; Line 27
pop ebp
ret 4
?MemAlloc2@@YGPAXK@Z ENDP ; MemAlloc2
_TEXT ENDS
Now here is the inline assembly I use. (This is probably something to do with the preprocessor, or it's a bug in the compiler/assembler)
{
#define _dwSize 8
_asm
{
push ebp
mov ebp,esp
mov eax, DWORD PTR _dwSize[ebp]
push eax
push HEAP_ZERO_MEMORY
call DWORD PTR GetProcessHeap
push eax
call HeapAlloc
pop ebp
ret 4
}
#undef _dwSize
}
Here is what it looks like in the output.
_dwSize$ = 8 ; size = 4
?MemAlloc@@YGPAXK@Z PROC NEAR ; MemAlloc
; File h:\documents\masm projects\inlinasm\main.cpp
; Line 8
push ebp
; Line 9
mov ebp, esp
; Line 11
mov eax, DWORD PTR [ebp+8]
; Line 12
push eax
; Line 13
push 8
; Line 14
call DWORD PTR __imp__GetProcessHeap@0
; Line 15
push eax
; Line 16
call __imp__HeapAlloc@12
; Line 18
pop ebp
; Line 20
ret 4
?MemAlloc@@YGPAXK@Z ENDP ; MemAlloc
_TEXT ENDS
???
EDIT....
Nevermind, adding DWORD PTR in front of the call to HeapAlloc fixed it.