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?
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.
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
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?
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
Hi msqweasm,
If it's about structures, you can code without the ASSUME statement :
mov IMAGE_SECTION_HEADER.SizeOfRawData[edx],eax
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
There is also a very special case of assume syntax...
ASSUME NOTHING
:lol
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
Hi oex,
Thanks for the other forms of the syntax.
Here is another example :
mov [edx + IMAGE_SECTION_HEADER.SizeOfRawData],eax
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....
or
mov [edx][IMAGE_SECTION_HEADER.SizeOfRawData],eax