I want to define a structure that looks like this



Link STRUCT
element DWORD ?
next ptr Link ?
previous ptr Link ?
Link ENDS


except I'm having a tough time defining pointers in the structure... I want the assembler to know that if I move next to a register, without the assume directive, make it think it's a pointer to another Link structure... But my efforts seem in vain... What is wrong with my syntax? Also, is there a MASM manual out there for the assembler directives and such? Thanks
Posted on 2004-01-20 22:28:33 by FearHQ
Pointers are DWORDs:
Link STRUCT

element DWORD ?
next DWORD ?
previous DWORD ?
Link ENDS

You can download the MASM manuals from Randall's site at webster.
Posted on 2004-01-20 22:42:05 by donkey
I see what he's trying to do .. I've been here before.
This may make you feel more comfortable, but won't matter if you use dword instead. We perform a TYPEDEF and we do it BEFORE we define the type itself.
We are allowed to do this because we are defining a PTR to a type, not the type itself. So we use "typedef ptr" as follows:

LPLINK typedef ptr Link
Link STRUCT
element DWORD ?
next LPLINK ?
previous LPLINK ?
Link ENDS

Have a nice day :)
Posted on 2004-01-20 23:12:12 by Homer
Thanks EvilHomer2k, that's along the lines of what I'm looking for... However, there is a reason I didn't want to use Dwords, apart from it's esthetics. I wish to be able to do something like this



LPLINK typedef ptr Link
Link STRUCT
element DWORD ?
next LPLINK ?
previous LPLINK ?
Link ends
(...)

Link_delete proc _this:LPLINK

mov eax, [_this].elemen
test eax, eax
jz @F
invoke HeapFree, hHeap, NULL, eax
@@:
invoke HeapFree, hHeap, NULL, _this
ret

Link_delete endp


That is incorrect. I wish to create "C style objects" like this, but I cannot do that. Do I have to move _this to a register and explicitly use assume directive in order to accomplish this? If there is any other way, I'd be happy to hear about it... I also see an alternative of not passing by stack but in a register, say ecx... That would remove the moving overhead but require extra precaution from my part.. Any ideas?


Also does the assume directive affect functions you call or does it only stay in current function? eg if you do



assume ecx:ptr Link
invoke BlaBla

is ecx still treated as a pointer to a Link in BlaBla? What if BlaBla itself uses the assume directive, if I return from BlaBla will I have a pointer to Link again?
Posted on 2004-01-20 23:47:04 by FearHQ
Well, the addressing mode does not exist for what you want to do. You can only use displacement addressing with a register so you will have to move the pointer into the register then use this:

mov eax,_this
mov eax,.LINK.element
Posted on 2004-01-21 00:44:14 by donkey