Good afternoon every one.
Probably you all remember my first post (http://masm32.com/board/index.php?topic=3519.msg37001#msg37001) about String Arrays.
That time and acording to the manual, is perfectly fine if you do:
Invoke SomeProc, Addr (StringStruct Ptr MyArray[Edi]).MyString
; or using qWord's advice:
Invoke SomeProc, Addr MyArray[Edi].MyString
Taking the same example, oddly enough, if I try to obtain the offset with mov the compiler throws a "error A2098: invalid operand for OFFSET". The Structure and data are all global, of course. So any of the following fails to compile:
Mov Ebx, Offset (StringStruct Ptr MyArray[Edi]).MyString
Mov Ebx, Offset MyArray[Edi].MyString
Mov Ebx, Offset (MyArray[Edi].MyString)
Mov Ebx, Offset (MyArray[Edi]).MyString
What's wrong please ?
OFFSET should resxolve to an actual address but ML doesn't know whay EDI points to.
Try using LEA instead.
Lea Ebx, (StringStruct Ptr MyArray[Edi]).MyString
OFFSET is used when the assembler knows an absolute address
ADDR is used when it must be calculated from register contents
the ADDR operator actually generates code that uses the LEA (Load Effective Address) instruction
lea ebx,MyArray[edi].MyString
the address of MyArray[edi].MyString is calculated and loaded into EBX
the actual code that is generated will look something like this
lea ebx,[edi+nnnnnnnn]
where nnnnnnnn is the address of MyArray + the index of MyString
so, the processor has to make a run-time calculation because the contents of EDI are not known at assembly-time
I was aware of LEA but not sure enough in this particular case as the structure is global. :lol:
Thank you all, is working fine now and learned the lesson :t