News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

ASSUME is evil

Started by oex, February 02, 2012, 12:10:47 PM

Previous topic - Next topic

oex

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
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

dedndave

don't use ASSUME   :P

        mov     eax,[edi].sStruct.MemberName

dedndave

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

dedndave


qWord

you can use PUSH/POPCONTEXT to save the current ASUMME-settings:

mymacro macro
PUSHCONTEXT ASSUMES
assume whatever
...
POPCONTEXT ASSUMES
endm
FPU in a trice: SmplMath
It's that simple!

dedndave

i thought that only applied to the ASSUME for segment registers

Vortex

Another example :

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

oex

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
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

dedndave

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

jj2007

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 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