Never really use ASSUME much but as I am try to figure out some of the internal of the LOCAL directive, I figure it just assumes the lacals text name to ebp and on proc exit unassumes that name.
How do you unassume something?
Thanks.
Real easy:
assume <reg> : nothing
i hope i remembered that correctly, it's been a while since i did any asm :eek :bg
Hi ThoughtCriminal,
My only encounters with ASSUME.
ASSUME edx:PTR WORD
mov ax,[edx+2]
ASSUME edx:PTR BYTE
mov [edx+4],cl
ASSUME edx:nothing
Hope this helps a little,
Darrel
Thanks.
Anyone have any more info on assume? Most of what I can find is for 16-bit.
Perhaps I should be using textequates instead.
AFAIK, assume should be used whenever you are using references. in darrel's example, it really isnt necessary due to the size of the destination operands. when i see the assume directive in use, it is usually used with structures to shorten the lines. personally, i would rather write everything explicitly and do not use ASSUME. consider the following:
POINT STRUCT
x WORD ?
y WORD ?
POINT ENDS
COORD STRUCT ;a "different" structure
x WORD ? ;contains the same exact member names as the POINT structure
y WORD ?
COORD ENDS
.DATA
dot POINT <20,40>
.CODE
;...
MOV ebx,OFFSET dot
ASSUME ebx:PTR POINT ;treat ebx as a pointer to a POINT structure from now on
;MOV ax,(POINT PTR [ebx]).x ;instead of this...
MOV ax,[ebx].x ;ax = 20 without the assume, it would cause errors
;MOV dx,(POINT PTR [ebx]).x ;instead of this...
MOV dx,[ebx].y ;dx = 40 without the assume, it would cause errors
ASSUME ebx:NOTHING ;do not make any assumptions on ebx
;...
in this example, ASSUME prevents ambiguity when structures use same names for its members.
What about when the structure is larger than the register? I tried it with a structure that had 3 dword sixed members ie:
MYSTRUCT STUCT
one DD ?
two DD ?
three DD ?
MYSTRUCT ENDS
I get and error that the struct is to large to fit in the register. Any ideas?
Thanks.
ThoughtCriminal,
Normally you put the address of the structure into a register, then you dereference the bits you need from that base address.
I normally use ASSUME for accessing structures within lib modules, which I find more convenient. Especially if its large.
The ebx register is untouched by most win32 APIs (if not all) so, as long as I dont mess with it between ASSUME and NOTHING I can use something like this:
; MAIN |||||||||||||||||||||||||||||||||||||||||
THUMBNAIL struct
width dword ?
height dword ?
xpos dword ?
ypos dword ?
comment db 80 DUP (?)
THUMBNAIL ends
.data
Thumb THUMBNAIL < >
.code
invoke ShowInfo,hWin,addr Thumb
; LIBRARY MODULE |||||||||||||||||||||||||||||||
THUMBNAIL struct
width dword ?
height dword ?
xpos dword ?
ypos dword ?
comment db 80 DUP (?)
THUMBNAIL ends
.code
ShowInfo proc uses ebx hWin:dword, ptrThumb:dword
mov ebx,ptrThumb
ASSUME ebx:ptr THUMBNAIL
invoke SetWindowText,hWin,addr [ebx].comment
ASSUME ebx:NOTHING
ret
ShowInfo endp
Hope this helps
dougieM
Ahhh! Thats what I missed. I did not put the PTR in.
ASSUME ebx:ptr THUMBNAIL correct
ASSUME ebx: THUMBNAIL error
Thanks.
It seems the lack of PTR is not the problem.
error A2022: instruction operands must be the same size
_API STRUC
ExitProcess @4 .ExitProcess ;_imp__ExitProcess@4
CreateFile @28 .CreateFile ;_imp__CreateFileA@28
GetLastError @0 .GetLastError ;_imp__GetLastError@0
_API ENDS
__@0 TYPEDEF proto
_@0 TYPEDEF PTR __@0
__@4 TYPEDEF proto :dword
_@4 TYPEDEF PTR __@4
__@28 TYPEDEF proto :dword, :dword, :dword, :dword, :dword, :dword, :dword
_@28 TYPEDEF PTR __@28
@0 textequ <_@0 ptr>
@4 textequ <_@4 ptr>
@28 textequ <_@28 ptr>
_DATA SEGMENT
loc_api dd loc_api ;+4 ;$+0Ch _imp__ExitProcess@4;
.ExitProcess .@4 _imp__ExitProcess@4
.CreateFile .@28 _imp__CreateFileA@28
.GetLastError .@0 _imp__GetLastError@0
_DATA ENDS
mov edx,[loc_api][4]
mov edx,[edx] <-----------------error above happens here
Thanks for any help.
error A2022: instruction operands must be the same size
My experience is, that if you (or any other proc you call) between setting ASSUME and resetting to NOTHING, uses or changes the ebx register it will return this error.
dougieM
Quotemov edx,[edx] <-----------------error above happens here
mov edx,DWORD PTR[edx]
This will get rid of the error message
Regards,
Darrel