mov edi, ptr
assume edi: ptr type

the codes before will work. If it possible to accessing a field without the presence of register?
Posted on 2003-05-02 03:06:41 by taowen2002

you can just put the address into a variable if you like, the main reason for using the register is for addressing multiple members of the structure but it depends on how you want to address the structure member.

You can use this alternative notation as well,

mov ([STRUCT] PTR [eax]).left, 10

Where is the name of the structure whose member you wish to address. When used in this way the notation is a memory operand so it must be written to a register first if you wish to place its content in another memory location.

mov ecx, ([STRUCT] PTR [eax]).left

Posted on 2003-05-02 03:21:53 by hutch--
Thank you for your reply :alright:
I will have a try
Posted on 2003-05-02 11:55:43 by taowen2002
Thanks for the tip from me too. I didn't know one could do it like that, I always used a lot of ASSUME's.
Now my code can look cleaner!
Posted on 2003-05-02 16:08:49 by david
I have since taken this approach (origionally introduced to me by Ernie):

mov .StructureType.Field, Imm_Value

To me it looks more orderly:

Take THIS memory pointer "EDI"
Apply THIS "StructureType" to it
Reference THIS "Field"

and do something with it (mov immediate memory value).

Hope it helps.
Posted on 2003-05-02 19:01:30 by NaN
I personally use ASSUME, but I hate typing more than I have to :grin:

Here's a couple of problems I've come across using these formats

1. the format suggested by NaN doesn't play nice if the register your using is ASSUME'd, and
2. the format suggested by hutch doesn't play nice with .if unless you surround the entire structure reference with []

.if [(STRUCT ptr [reg]).field] == 0

Posted on 2003-05-02 21:23:39 by Maelstrom
Agreed, but im A$$UMING your not using ASSUME (<lol> )
Posted on 2003-05-02 21:39:21 by NaN
Well, the best is still to look use offset :grin: Seriously I would prefer to use assume, less typing like wat maelstorm stated
Posted on 2003-05-02 23:55:09 by roticv

I personally use ASSUME, but I hate typing more than I have to :grin:
You don't use RadASM? It will complete those structures for you with minimum of keys.
Posted on 2003-05-03 00:21:31 by bitRAKE

Errr, yes your right, BUT if your using other peoples macros, or my object preprocessor ( hint, hint ), conflicts like these could occur.
Should have been more specific, sorry :grin:


Yes it will but if the structure name changes, you have to change all those entries, and before you say use copy/paste I'm lazy remember :grin:

Posted on 2003-05-03 02:18:58 by Maelstrom
This also works:

call .bar2
0040101A FF 90 08 30 40 00 call dword ptr foo+4 (403008h)

This too:

_foo STRUC
bar1 dword PTR ?
bar2 dword PTR ?
bar3 dword PTR ?
_foo ENDS

assume ecx:ptr _foo

call [ecx].bar2
0040101A FF 51 04 call dword ptr [ecx+4]
Posted on 2003-05-03 05:28:47 by ThoughtCriminal
I ave a macro for this kind of thing called 'with'. Here it is with example usage.

with macro _src:req, _type:req, _reg:=<ebx>
ifdifi <_reg>, <_src>
if type _src eq 4 ; dword - ie. ptr struct
mov _reg, _src
lea _reg, _src ; struct
assume _reg:ptr _type
me equ [_reg]

.proc ON_WM_NOTIFY, wparam, lparam

with lparam, TOOLTIPTEXT ; load & cast ebx. 'me' equ [ebx]

switch me .hdr.code
or al, TRUE

let me .lpszText = tips[get_dwdata(me .hdr.idFrom) * 4]

clr eax ; 0 = 'no more'
assume ebx:ptr NMTOOLBAR ; 're-cast' lparam
.if me .iItem < ubound_tbarr
; me.tbbutton = tbarr[me.iItem]
imul esi, me .iItem, type tbarr ; ebx = @ tbarr[me.iItem]
memcpy @ (me).tbButton, @ tbarr[esi]

; me.pszText = tips[tbarr[me.iItem].dwData]
mov edx, tbarr[esi].dwData
strcpy me .pszText, tips[edx*4]

The space after 'me' is not necessary. My editor won't recognize -me-
as a key word otherwise.
Posted on 2003-05-03 06:37:07 by gfalen
My problem with assume is you have to be carefull with function calls in between your ASSUME:xxxx and ASSUME:NOTHING statements...

So i have since left it by the way side... Im not trying to enforce this on anyone.. just my views... this is alll.

Posted on 2003-05-03 10:26:29 by NaN
The original question was:
"If it possible to accessing a field without the presence of register?"
The answer is:

MyRect RECT <>
mov MyRect.left, 2
mov, 1
mov MyRect.bottom, 7
jmp ExitProcess ; kill the process

No registers!

I didn't see assume reg: NOTHING in the examples above! Why?

Posted on 2003-05-03 16:30:49 by lingo12
While masm is assembling your program, you tell it to assume a register is typed to something, it will remember it for all cases it comes from. This means you can create bugs without knowing it if your subroutine uses this register for something different, and you didnt "unassume" it before the call.

THis is not an issue for API's tho, because they are already compiled into dll's. Its only a problem to subfunctions that your write, and expect MASM to assemble.

To answer you question, they should always unassume anything you tell the assembler to assume.

Posted on 2003-05-03 16:41:30 by NaN
my question is to the authors of examples with assume reg...
"they should always unassume anything they tell the assembler to assume"
because I hate to use assume except assume FS:nothing..

Posted on 2003-05-03 17:43:10 by lingo12
I use the following macro to unassume registers used in a proc.

.ret macro a
ifnb <a>
ifdifi <a>, <eax>
mov eax, a
assume eax:nothing, ecx:nothing, edx:nothing
assume ebx:nothing, edi:nothing, esi:nothing

Posted on 2003-05-03 18:04:03 by Maelstrom
I prefer the alternate syntax .STRUCT.Field, no assume statement, no bugz, nothing to remember or worry about, makes for more readable code as well
Posted on 2003-05-03 18:09:55 by donkey
Sorry Lingo, my bad :)

Donkey, im with you 100% here....
Posted on 2003-05-03 19:41:20 by NaN

I prefer the alternate syntax .STRUCT.Field, no assume statement, no bugz, nothing to remember or worry about, makes for more readable code as well

This is great! thanks!!! I will never use any ASSUMEs anymore!
Posted on 2003-05-04 02:50:20 by david