What I'm trying to do is pass a table ref to another proc. Well it's kind of hard to explain so I'll just post an example:


.data
tblStuff dd offset stuff1
dd offset stuff2
dd offset stuff3
....
stuff1 db "stuff",0
stuff2 db "more stuff",0
stuff3 db "even more stuff",0
....
.code
.....
invoke SomeProc,tblStuff
.....
SomeProc proc stuff:DWORD
....
push ecx
imul ecx,4
;then I'm trying to reference tblStuff (passed through stuff)
;by using stuff[ecx]
pop ecx


It doesn't work that way but if I just do "tblStuff" instead of "stuff" it works.

How can I use what I'm passing to SomeProc directly?

I'm not sure how much sense that makes, but it's the best that I can explain it.
Posted on 2002-05-07 17:37:06 by Will
You need to pass the address of the table to your proc, not the contents (4 byte dword of info ) found at tblStuff.

.data

tblStuff dd offset stuff1
dd offset stuff2
dd offset stuff3
....
stuff1 db "stuff",0
stuff2 db "more stuff",0
stuff3 db "even more stuff",0
....
.code
.....
invoke SomeProc, [b]addr[/b] tblStuff
.....
SomeProc proc [b]lp[/b]Stuff:DWORD
....
[b]mov ecx, lpStuff[/b]
;then I'm trying to reference tblStuff (passed through stuff)
;by using stuff[ecx]


Then use ecx as a pointer, and add multiples of 4 bytes to the address to get the various dword contents. (0 time == offset to Stuf1, 1 times == offset to stuff2, etc.)

I made simular suggestions on a topic simular to your problem here Here.

As well you can skip the 'dynamic' math at run time to access the offests with a structure, and allow the assembler to do the math for you.



MyStuff STRUCT
lpString1 dd ?
lpString2 dd ?
lpString3 dd ?
MyStuff ENDS

.data
stuff1 db "stuff",0
stuff2 db "more stuff",0
stuff3 db "even more stuff",0

tblStuff MyStuff < offset stuff1, offset stuff2, offset stuff3 >

.code
.....
invoke SomeProc, [b]addr[/b] tblStuff
.....
SomeProc proc [b]lp[/b]Stuff:DWORD
....
[b]mov ecx, lpStuff[/b]
invoke MessageBox, NULL, [ecx].MyStuff.lpString1, [ecx].MyStuff.lpString2, MB_OK


Just a suggestion of alternate ways.

:NaN:
Posted on 2002-05-07 18:39:33 by NaN
     .....

invoke SomeProc, addr tblStuff
.....
SomeProc proc lpStuff:DWORD
....
mov ecx, lpStuff
;then I'm trying to reference tblStuff (passed through stuff)
;by using stuff[ecx]
4oh4, you can't reference from stuff in the PROC because that is the stack and you didn't pass the whole table. Instead:
SomeProc proc lp[b]tbl[/b]Stuff:DWORD

....
mov ebx, lp[b]tbl[/b]Stuff
;then I'm trying to reference tblStuff (passed through stuff)
;by using stuff[ecx]
mov eax, [ebx + ecx*4] ; index table by ecx
; or...
invoke MessageBox, hWin, [ebx + ecx*4], [ebx + ecx*4], MB_OK
I'm assuming that different tables can be passed and that access to that table is dynamic, else NaN's advice with the STRUCT is the best way.
Posted on 2002-05-07 18:51:06 by bitRAKE
NaN:
Thanks very much for your suggestion. :) That would be great, but I fear that it won't work in my situation. Please feel free to correct me if I'm wrong though.

bitRAKE:
You're right in assuming that I want this to be a fairly dynamic proc and I'm trying to pass different tables to it. I'll be working in my other office for most of the morning so I won't be able to test your suggestion till probably early afternoon at the earliest. But it looks like it'll work. :)


Thanks for the replies guys. Three heads are always better than one.
Posted on 2002-05-08 10:05:27 by Will