News:

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

trouble accessing adress

Started by a_h, August 22, 2005, 04:44:22 PM

Previous topic - Next topic

a_h

Hi!

In short:
My function gets the base adress of an array as parameter

extern "C" unsigned int __stdcall fortest2(unsigned int for_var_, int *for_ptr_);

where *for_ptr_ gets the adress (like fortest2(10,array) with int *array, array=new int[10]). With following code I try to access the array elements

add   eax, [for_ptr_+8*ecx]

however this doesn't work. Even reading [for_ptr_] yields huge numbers instead of the correct 0 I stored in. Doing the same as inline assembler works though.

In long:
I'm doing this, since I want to place some code into an external asm-file and call it via __fastcall (using __stdcall just to test). However within VisualC++ this object-file uses different name mangling than the c++-files where the global array is used too. Thus, unless I pass the base adress as parameter, I cannot see a different way of accessing the global dynamical array from within __fastcall masm and C++.

Thanks for your help! Cheers, Hannes

a_h

Ok, first bug found: int is 4 bytes, thus

add   eax, [for_ptr_+4*ecx]

is the correct version. Interestingly the fastcall-version works now flawlessly, just the stdcall-version refuses to work. Ideas?

Cheers, Hannes

tenkey

You can't use the pointer directly from memory (CPU limitation). Load it into a register first.

mov   edx, [for_ptr_]
add   eax, [edx+4*ecx]

A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

a_h

Many thanks for that one! That explains why the fastcall version works...!

Thanks for helping me out, tenkey! Have a nice day, Hannes