Good discussion! I learned a lot from it. I accept .struct.field too.
Posted on 2003-05-04 05:37:08 by taowen2002
My problem with assume is you have to be carefull with function calls in between your ASSUME:xxxx and ASSUME:NOTHING statements...
You think so? I have never had this problem. Or i have a bunch of undiscovered bugs in my code because of it. Hmmm, i know which option i prefer to believe in.....

What i am saying is that i have never found any indication of the ASSUME being carried across the bounds of functions, API or otherwise.

I have used both the ASSUME method, and the <ptr>.<struct>.<field> method, and definately prefer the ASSUME (mainly because it means less typing, i don't believe in short cryptic names for my structs).
Posted on 2003-05-04 06:33:48 by sluggy
I think ASSUME is good if you're going to make "alot" of references to a STRUC.

Also, I used to use

(struc PTR ).item

but I've changed my ways and have been using

.struc.item

for a while now. I think it's easier to read, etc...

:)
Posted on 2003-05-04 07:21:16 by S/390
I will post it here. But this question is something else. BTW. ASSUME is more cool :tongue:


;K this one is my struct

HANDLESSTRU struct
hCBSh dd ?
hCBLo dd ?
hCBNIP dd ?
hCBKon dd ?
hCBTel dd ?
hLV dd ?
HANDLESSTRU ends


HandlesS HANDLESSTRU <?>


;after filling HandlesS with proper data i wonted to read it somewhere in my proc.
;i made something like this.

invoke MyProc,addr HandlesS



MyProc proc pHandlesS:DWORD

;I thought that structures are just like arrays so i add 4 to adres to
;obtain HandlesS.hCBLo

add pHandlesS,4

;Unfortunatelly addr HandlesS != HandlesS.hCBSh

ret
MyProc endp


how can i obtain pointers to struct members without knowing name of them ??

pleas can you explain to me struct rules ??
Posted on 2003-06-09 17:01:11 by AceEmbler
That should have worked AceEmbler. A structure in all languages is an array of contiguous data, addressed by named labels. The first field in the structure is always at offset 0. So :

MyStruct STRUCT
f1 dd ?
f2 dd ?
f3 dd ?
MyStruct ENDS

ms MyStruct <?>

mov edi,OFFSET ms

holds f1
holds f2
holds f3

This pattern is unchanging even in HLL's. There must be something else up with the code for it not to have worked. I have used this method extensively and have never had a problem with it.
Posted on 2003-06-09 18:55:22 by donkey
youre right I fail:alright:
Posted on 2003-06-10 01:47:19 by AceEmbler
Hi all,

I have been using this format in my programs as I find that its shorted and easier to type. (sorry for the formatting - I could not figure out how to get it right)

sFixedSzArray struct
hArrMem dd 0
nMemSz dd 0
nElmtSz dd 0
nArrLen dd 0
hIdxMem dd 0
nIdxMemSz dd 0
pIdxMem dd 0
pArrMem dd 0
sFixedSzArray ends
pAr TEXTEQU<.sFixedSzArray>
pArESI TEXTEQU<.sFixedSzArray>

;---------------------------------------------------------------------------------

ReleaseArray proc uses ebx pArr:dword
mov ebx,pArr
.if(pAr.pArrMem)
invoke GlobalUnlock,pAr.hArrMem
mov pAr.pArrMem,0
.endif
ret
ReleaseArray endp

I use EBX For a lot of my structures I, so when I have to use more than one in the same section I use the alternat pointer pArESI ect to remind myself which Register is being used.
Posted on 2003-07-23 14:33:50 by Gr8ful dead

guys,
The original question was:
"If it possible to accessing a field without the presence of register?"
The answer is:


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

No registers!

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

Regards,
Lingo


you can read a little more, to catch a little more.. or have more questions.. i dunno here.. ;)
http://www.asmcommunity.net/board/showthread.php?s=&postid=112728.msg112728

Also centering on what you are saying i will try explain here too :D


struct mean
m1 dword 1
m2 dword 1
endstruct

think in this like res is for reserve
struct mean
m1 resd 1
m2 resd 1
endstruct



Then what is the mean of this??, nothing for the compter, but for the assembler you are defining a dta type, maybe or probable that in language at level of assembly time this is (in words for understand at human level :D ):

define a type struct called mean
define the first member with displacement 0 and is called m1 and size double word
define the next member with displacement 4 and is called m2 and size double word

ok ok... that was easy... for how to use it??.. and for what to use?? (read the explanation that i write in the other post), is simply for acces more easy ;).

ok now have two cases in general.

The first in the code, when you do:

.data
MyRect RECT <>

you are saying to the compiler some like this:

hey I want define a label called MyRect
I want you reserve for me the space of RECT
I will not give you any initializer <>

After the assembler know this, then it go for the case, if, jmp or call :D, and "say" hey, i have a dta type called RECT is a struct and have four members, and the displacements of the members are (i dont know the order):

left 0
top 4
bottom 8
top 12

now that i know that i will make others labels with the first label (the base label), make the suposition that in the data section your label MyRect is in the addres 10
then the addresses will be:

---------------
MyRect 10
MyRect.left 10
MyRect.top 14
MyRect.bottom 18
MyRect.right22
----------------


But the assembler cannot create the addres, first need some content if provided is in <,,,,> and if no is <> and simply declare the sizes without initializers:

Then the assembler will do some like (without the need of write in the code, only calling directly the secuences of instructions for do this:

MyRect:
MyRect.left dd 0
MyRect.top dd 0
MyRect.bottom dd 0
MyRect.right dd 0


This is a large explanation, but at the end you will get completely the idea.

And for what no assume when you acces it???, simple, they are labels with a specific address, and name, you dont need assume nothing, the compiler know all that need for acces this part of memory in the way that you abstract it :D.


And for what assume with registers???

Go to the first steps, where you say to the compiler that you are defining a data type.

What things you know????

-The name of the data type
- The type of the data type
- The displacements of the members (based on the size of the previous member )
- The sizes of each member (for the fill with initializers)
- the size of the data type.

First look at this, you can move the direction of a addres to a register, then you can add the displacements, at the end, dosent matter what you use for access, at the end will look like ebx+0 or ebx+4, ok now with this fact.

you can think now in this posibility:

if you have only rectangle, then you can access

ebx.top and will be ebx+x
ebx.left etc ebx+x2

but see this case:

struct TRIANGLE
topx resd 1
topy resd 1
left resd 1
bottomleft resd 1
right resd 1
bottomright resd 1
endstruct


Now you have two diferent things, if you take ebx.left or ebx.right, here for the rectangle ebx.left will be for example ebx+4 and for the triangle ebx.left will be ebx+8, here the assembler say.. WHAT APPEND!!!!!!!!!!!!, what of this two take???, and here we comes..... the diferent forms of acces.... (when you write the rules, you have to take decisions).

--Complete cualified names:

ebx.DATATYPE.member

(in this form the assembler know that you will take the value of DATATYPE and no DATATYPE2)

By this way are the other forsm of cualified names:

DATATYPE register.member.. and others....

--Using a indicator of what to take if a bot specifiers taked:

This is assume...

assume ebx:RECTANGLE
then ebx.left will be taked from the data type RECTANGLE...


here a break... i dont know if you can do this:
assume ebx:RECTANGLE
assume ebx:BINFO
and if both (the two) data types have diferent members, then you can acces booth (the two)??, if this can be done, then the problem of what to choice comes for second time if some of the members in the two structures have the same name (or give a error). I dont know the mechanism of assume in the way that i dont know if they push when you do that combination, or simple rewrite RECTANGLE with BINFO without the assume nothing for ebx (get the idea?), or more simple, simple give a message error. If a mechanis like a push.. then you can do:


assume ebx:RECTANGLE
;use ebx with the members of rectangle
assume ebx:TRIANGLE
;push the anterior assume
;use ebx with members of triangle
assume ebx:nothing
;pop the assume
;continue using ebx with the members of RECTANGLE
assume ebx:nothing

if have a implementation like a list (walk all)


assume ebx:RECTANGLE
;use ebx with the members of rectangle
assume ebx:TRIANGLE
;link with the anterior assume and check for no duplicate members in the dta types in the list
;use ebx with members of triangle
; and with members of rectangle
assume ebx:nothing
;unlink the assume
;continue using ebx with the members of RECTANGLE
assume ebx:nothing




or if have a more simple implementation:


assume ebx:RECTANGLE
;use ebx with the members of rectangle
assume ebx:TRIANGLE
; give a error you are trying rewrite the anterior assume, use assume ebx:nothing
;and the next will maybe not work correctly by this error
; THAT IS NOT FUNNY say the assembler :D
assume ebx:nothing
;right you are in the correct path (but before this you have a fail
assume ebx:nothing




haha, now you can see in a more deep way for what the assume for registers.... anf for what the cualified names :D, and for what no with data in the code :), you see that is a question of choise... make desicions, use one or other sintaxis, if assume work like some of the first two posible choises, then i prefer for readibility a complete cualified name (maybe If I have a goode use of tab can work with this way.), you can be a little ambigous if you use assume (if first read of code) you need search where is the assume you can not know at first look to what Data TYPE is ebx.left (remember RECTANGLE and TRIANGLE) and can type a little fast more, or by a no ambigous (at first read) with complete cualified names ebx.DataType.member, but write a little less fast and more ;D




* remember that a union manipulate in diferent way the displacement of his members, and sure the total size of the data type.

Nice day.
Posted on 2003-08-18 10:40:02 by rea
Since we are talking about ASSUME with structures now....

I uae ASSUME alot now, and many structure definitions. I've wrapped API call into structures. Now an API call looks like this:

invoke .GetModuleHandle, NULL

But what I do is an ASSUME like:

WAPI TEXTEQU <ecx>
ASSUME WAPI:PTR _WAPI

So it ends up looking like this:

invoke .GetModuleHandle, NULL

This might not be the best example, but the benfit of equating your assumed reg is that if you decide to use a diffrent reg, just change the reg in the equate. Done. No error of forgeting to change a reg in the code after you change the reg in the ASSUME.

I am beginning to think ASSUME is good for structured programming, especial if you name the reg with an equate. Nameing the reg gives it meaning, if you change the meaning, done right, you can emulate scope. You dont see a reg, but information about what the reg is being used for or contains. Starting to apply HLL techniques to assem. Cant really explaine it very well, it really seems to be something that must be tried, to start to understand.
Posted on 2003-08-18 12:34:29 by ThoughtCriminal