The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: msqweasm on June 15, 2011, 07:02:51 AM

Title: What is the Purpose of MASM ASSUME Directive
Post by: msqweasm on June 15, 2011, 07:02:51 AM
The ASSUME directive, according to Kip Irvine's book (section16.2.2.4,, 4TH edition), is to "makes it possible for the assembler to calculate the offsets of labels and variables at assembly time."
But according to MASM 6.x reference manual it is to:

Enables error-checking for register values. After an ASSUME is put into effect, the assembler
watches for changes to the values of the given registers. ERROR generates an error if
the register is used. NOTHING removes register error-checking. You can combine different
kinds of assumptions in one statement.


Both descriptions confuse me.  What exactly is this directive doing?
Title: Re: What is the Purpose of MASM ASSUME Directive
Post by: hutch-- on June 15, 2011, 07:11:44 AM
Both are basically correct, it can be used to make an operation with a register invalid FS and GS for example as they are used for SEH. ASSUME can also be used to make a register a structure pointer, have a look at the ASM Intro Help file to see what can be done with structures using ASSUME.
Title: Re: What is the Purpose of MASM ASSUME Directive
Post by: MichaelW on June 15, 2011, 07:54:11 AM
The difference between the two descriptions is in the type of register. The first description applies only for segment registers, and the second for general-purpose registers or segment registers. For a segment register ASSUME is used to tell the assembler what segment or group to associate with the segment register. For a general-purpose register ASSUME is used to tell the assembler that the register is a pointer to a certain size or type of object (where 'type' here means a structure or union). For either type of register ASSUME reg:ERROR can be used to disable use of the register, until the assumption is canceled with ASSUME reg:NOTHING
Title: Re: What is the Purpose of MASM ASSUME Directive
Post by: msqweasm on June 15, 2011, 07:56:49 AM
Quote from: MichaelW on June 15, 2011, 07:54:11 AM
The difference between the two descriptions is in the type of register. The first description applies only for segment registers, and the second for general-purpose registers or segment registers. For a segment register ASSUME is used to tell the assembler what segment or group to associate with the segment register. For a general-purpose register ASSUME is used to tell the assembler that the register is a pointer to a certain size or type of object (where 'type' here means a structure or union). For either type of register ASSUME reg:ERROR can be used to disable use of the register, until the assumption is canceled with ASSUME reg:NOTHING


So ASSUME actually has 3 different uses?
Title: Re: What is the Purpose of MASM ASSUME Directive
Post by: MichaelW on June 15, 2011, 08:25:42 AM
QuoteSo ASSUME actually has 3 different uses?

Basically, but I would consider specifying a structure or union for the object pointed to as a somewhat different use than specifying a simple data type, because specifying a structure or union causes the assembler to do more than just a size check.

;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================
T STRUCT
    x DWORD ?
    y DWORD ?
T ENDS
;==============================================================================
    .data
        t T   <>
        d dd  ?
    .code
;==============================================================================
start:
;==============================================================================

    mov eax, t.T.x
    mov ecx, t.T.y

    ASSUME ebx: PTR T
    mov eax, t.x
    mov ecx, t.y

    ASSUME ebx: PTR DWORD
    mov eax, [ebx]
    mov ax, [ebx]   ;error A2022: instruction operands must be the same size

    ASSUME ebx: NOTHING

    inkey "Press any key to exit..."
    exit
;==============================================================================
end start



Title: Re: What is the Purpose of MASM ASSUME Directive
Post by: Vortex on June 15, 2011, 04:44:50 PM
Hi msqweasm,

If it's about structures, you can code without the ASSUME statement :

mov  IMAGE_SECTION_HEADER.SizeOfRawData[edx],eax
Title: Re: What is the Purpose of MASM ASSUME Directive
Post by: oex on June 15, 2011, 05:43:50 PM
Quote from: Vortex on June 15, 2011, 04:44:50 PM
Hi msqweasm,

If it's about structures, you can code without the ASSUME statement :

mov  IMAGE_SECTION_HEADER.SizeOfRawData[edx],eax

Or

mov  (IMAGE_SECTION_HEADER PTR [edx]).SizeOfRawData,eax

Or

mov  [edx].IMAGE_SECTION_HEADER.SizeOfRawData,eax
Title: Re: What is the Purpose of MASM ASSUME Directive
Post by: drizz on June 15, 2011, 06:07:52 PM
There is also a very special case of assume syntax...

ASSUME NOTHING

:lol
Title: Re: What is the Purpose of MASM ASSUME Directive
Post by: jj2007 on June 15, 2011, 06:19:45 PM
Quote from: oex on June 15, 2011, 05:43:50 PM
mov  [edx].IMAGE_SECTION_HEADER.SizeOfRawData,eax

You forgot mov [edx.IMAGE_SECTION_HEADER.SizeOfRawData], eax :bg
Title: Re: What is the Purpose of MASM ASSUME Directive
Post by: Vortex on June 15, 2011, 06:20:31 PM
Hi oex,

Thanks for the other forms of the syntax.

Here is another example :

mov  [edx + IMAGE_SECTION_HEADER.SizeOfRawData],eax
Title: Re: What is the Purpose of MASM ASSUME Directive
Post by: oex on June 15, 2011, 06:50:03 PM
Just pick one.... I have all forms in my code from when I learned which is just plain daft :lol....

It has just become one of those jobs that will never get done to standardise my code....
Title: Re: What is the Purpose of MASM ASSUME Directive
Post by: mineiro on June 15, 2011, 11:28:51 PM
or
mov  [edx][IMAGE_SECTION_HEADER.SizeOfRawData],eax