News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Using Memory Pointer as Parameter

Started by Thomas_1110, September 04, 2009, 07:17:42 PM

Previous topic - Next topic

Thomas_1110

Hello
The value in the messagebox is 0.

include \masm32\include\masm32rt.inc
TestProc proto :DWORD

.data?
Mem1 DWORD ?

.code
start:

mov Mem1, alloc(1024)
push ebx
xor ebx, ebx
xor ecx, ecx
xor eax, eax
.while ecx < 1024
mov eax, ebx
mul eax
mov Mem1[ecx], eax
add ecx, 4
add ebx, 1
.endw
pop ebx

invoke TestProc, Mem1

invoke GlobalFree, Mem1
invoke ExitProcess, NULL
;-------------------------------------------------------------------------------------------
TestProc proc Mem_ :DWORD
invoke MessageBox,NULL , str$(Mem_[10*4]), NULL, NULL
ret
TestProc endp

end start



When I change the line in TestProc, the value in the MessageBox is 100.

invoke MessageBox,NULL , str$(Mem1[10*4]), NULL, NULL



How can I use the allocated Memory as Parameter in TestProc?
Best regards Thomas

dedndave

i think you may have a little boo-boo in generating the values
no need to use mul at all (btw, "mul eax" squares the value in eax)
i am not really sure what you want to generate in the allocated block - lol
give this a try...

include \masm32\include\masm32rt.inc
TestProc proto :DWORD

.data?
Mem1 DWORD ?

.code
start:

mov Mem1, alloc(1024)
xor edx,edx

loop00:
mov [eax],edx
add eax,4
add edx,4
cmp edx,1024
jb loop00

invoke TestProc, Mem1

invoke GlobalFree, Mem1
invoke ExitProcess, NULL
;-------------------------------------------------------------------------------------------
TestProc proc Mem_ :DWORD
mov eax,Mem_
mov eax,[eax+10*4]
invoke MessageBox,NULL , str$(eax), NULL, NULL
ret
TestProc endp

end start

Thomas_1110

Hello
Thanks for answer.
But you missunderstood me. Sorry, was my fault.
Here a code without multiplication.

include \masm32\include\masm32rt.inc
TestProc proto :DWORD
.data

.data?
Mem1 DWORD ?
.const

.code
start:

mov Mem1, alloc(1024)

mov Mem1[0], 13
mov Mem1[4], 17

invoke TestProc, Mem1

invoke GlobalFree, Mem1
invoke ExitProcess, NULL
;-------------------------------------------------------------------------------------------
TestProc proc Mem_ :DWORD
invoke MessageBox,NULL , str$(Mem_[4]), NULL, NULL
ret
TestProc endp

end start


My problem is to get the content of the allocated memory with a local variable, here in TestProc as parameter "Mem_".
With "Mem1" it works (global variable)

dedndave

yes - i see a different problem as well
i edited my post above - try it again
the problem is that "Mem_" is actually something like "[ebp+8]"
you can't access memory via an address stored in memory
you have to get the address into a register, first

the value you were seeing was some value from the stack - lol

Thomas_1110

Hello
Thank you, it works.
Best regards, Thomas