The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: oex on February 02, 2012, 12:10:47 PM

Title: ASSUME is evil
Post by: oex on February 02, 2012, 12:10:47 PM
Used it once and it breaks in macros right?

Any way for a macro to push an assume state?

x macro arg:REQ
mov edi, arg <---- Cant, assume:nothing and cant restore in macro as assume struct is unknown
endm

.code
assume edi:PTR sStruct
x var
<---- can not restore assume here in macro?
assume edi:nothing
Title: Re: ASSUME is evil
Post by: dedndave on February 02, 2012, 12:19:51 PM
don't use ASSUME   :P

        mov     eax,[edi].sStruct.MemberName
Title: Re: ASSUME is evil
Post by: dedndave on February 02, 2012, 12:29:12 PM
come to think of it - there should be no problem
ASSUME is an assembler directive
it is applied in a "serial" manner to the source text
so, if your macros are defined at the beginning of the program, or in an INC file,
then ASSUME should only apply to that macro
        ASSUME Something:Something

;macro code

        ASSUME Something:Nothing
;
;
;
;
;
        ASSUME Something:SomethingElse

;macro call

;SomethingElse is still assumed, here


applying ASSUME inside the macro may be a different story   :P
Title: Re: ASSUME is evil
Post by: dedndave on February 02, 2012, 12:31:42 PM
oops
Title: Re: ASSUME is evil
Post by: qWord on February 02, 2012, 05:15:17 PM
you can use PUSH/POPCONTEXT to save the current ASUMME-settings:

mymacro macro
PUSHCONTEXT ASSUMES
assume whatever
...
POPCONTEXT ASSUMES
endm
Title: Re: ASSUME is evil
Post by: dedndave on February 02, 2012, 05:31:14 PM
i thought that only applied to the ASSUME for segment registers
Title: Re: ASSUME is evil
Post by: Vortex on February 02, 2012, 06:28:17 PM
Another example :

mov eax,[esi+IMAGE_NT_HEADERS.OptionalHeader.DataDirectory.VirtualAddress+SIZEOF IMAGE_DATA_DIRECTORY]
Title: Re: ASSUME is evil
Post by: oex on February 02, 2012, 08:56:59 PM
Quote from: Vortex on February 02, 2012, 06:28:17 PM
Another example :

mov eax,[esi+IMAGE_NT_HEADERS.OptionalHeader.DataDirectory.VirtualAddress+SIZEOF IMAGE_DATA_DIRECTORY]

yes I use this.... [esi].IMAGE_NT_HEADERS.OptionalHeader.....

I thought I'd post as I had once used assume in all my code, it errored on compile and I knew no work-around

Quote from: qWord on February 02, 2012, 05:15:17 PM
you can use PUSH/POPCONTEXT to save the current ASUMME-settings:

mymacro macro
PUSHCONTEXT ASSUMES
assume whatever
...
POPCONTEXT ASSUMES
endm


nice 1

Quote from: dedndave on February 02, 2012, 05:31:14 PM
i thought that only applied to the ASSUME for segment registers

I didnt test :lol
Title: Re: ASSUME is evil
Post by: dedndave on February 02, 2012, 09:31:20 PM
well - that's the wording used in the masm manual
however, it could be a carry-over from previous versions of masm
i.e., the text in the manual could be out of date

QuoteYou can save the contexts inside macros with PUSHCONTEXT and
POPCONTEXT. The options for these keywords are:

Option Description
ASSUMES Saves segment register information
RADIX Saves current default radix
LISTING Saves listing and CREF information
CPU Saves current CPU and processor
ALL All of the above
Title: Re: ASSUME is evil
Post by: jj2007 on February 02, 2012, 10:08:47 PM
Quote from: dedndave on February 02, 2012, 09:31:20 PM
well - that's the wording used in the masm manual
however, it could be a carry-over from previous versions of masm
i.e., the text in the manual could be out of date

MSDN (http://msdn.microsoft.com/en-us/library/0adys4da%28v=vs.71%29.aspx) still says segment register assumes

But let's just test it... try commenting out the P*CONTEXT inside the macro:
include \masm32\include\masm32rt.inc

mypt MACRO ptArg
LOCAL tmp$, is
PUSHCONTEXT assumes
  Assume esi:PTR POINT
  tmp$ CATSTR <mov eax, [esi.>, <ptArg>, <]>
  % echo tmp$
  tmp$
POPCONTEXT assumes
  EXITM <eax>
ENDM

.code
TheRect RECT <12, 34, 56, 78>
ThePoint POINT <88, 99>

start:
Assume esi:PTR RECT
mov esi, offset TheRect
print str$([esi.left]), ", "
print str$([esi.right]), 13, 10
mov esi, offset ThePoint
print str$(mypt(x)), ", "
print str$(mypt(y)), 13, 10
mov esi, offset TheRect
print str$([esi.left]), ", "
print str$([esi.right]), 13, 10
exit

end start