News:

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

Assume

Started by ecube, November 10, 2009, 09:58:23 PM

Previous topic - Next topic

ecube

is using assume thread safe? eg

mov ecx,whatever
assume ecx:ptr mystruct

and if not any easy alternatives?

Slugsnack

yes it's 'threadsafe', you can see it as 'typecasting' a register in a way. after you're done you should assume:nothing again. alternatively :

(MYSTRUCT PTR [ecx]).

Vortex

It's possible to avoid completely the ASSUME statement :

mov IMAGE_ARCHIVE_MEMBER_HEADER.Mode[edx],030h

ecube

Quote from: Vortex on November 11, 2009, 07:33:15 PM
It's possible to avoid completely the ASSUME statement :

mov IMAGE_ARCHIVE_MEMBER_HEADER.Mode[edx],030h

how long does edx remain a ptr though? like when your finish you just use it direct without brackets?

Farabi

Quote from: E^cube on November 12, 2009, 02:07:06 AM
Quote from: Vortex on November 11, 2009, 07:33:15 PM
It's possible to avoid completely the ASSUME statement :

mov IMAGE_ARCHIVE_MEMBER_HEADER.Mode[edx],030h

how long does edx remain a ptr though? like when your finish you just use it direct without brackets?

Until you change the edx value.


mov edx,MY_STRUCT_ADDR1
mov [edx].MY_STRUCT.VALUE1 ; Still Valid
mov edx,MY_STRUCT_ADDR2 ; Not valid anymore
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

sinsi

>Until you change the edx value

Even then masm won't care - you've told it that edx points to a certain structure
Of course you can use "mov eax,edx" and such but anything like "mov eax,[edx]" should pop an error.
Light travels faster than sound, that's why some people seem bright until you hear them.

sinsi

An example: (edited to make sense...)

.386
.model flat,stdcall

mystruc struct
first  dd ?
second dd ?
mystruc ends

otherstruc struct
deedee1 dd ?
deedee2 dd ?
otherstruc ends

.data?
my1    mystruc <>
other1 otherstruc <>

.code

start:     
        mov edx,offset my1
        assume edx:ptr mystruc
        mov eax,[edx].first         ;legit
       
        mov edx,offset other1
        ;assume edx:ptr otherstruc  ;normally we would do this, since edx changed
        mov eax,[edx].second        ;still legit without the above assume but wrong
       
        mov eax,[edx]               ;error here
       
        assume edx:nothing          ;without this assume all references to [edx] are doomed
        mov eax,[edx]
        ret

end start

Light travels faster than sound, that's why some people seem bright until you hear them.

Mirno

Assume is not a run-time directive - it affects how masm generates machine code.

It is therefore neither thread-safe, nor not thread-safe.

Mirno

ecube

Quote from: Mirno on November 12, 2009, 09:39:59 AM
Assume is not a run-time directive - it affects how masm generates machine code.

It is therefore neither thread-safe, nor not thread-safe.

Mirno


that doesn't help me,slugsnack can you comment on this? or can anyone confirm/deny/elaborate.

dedndave

it may be easier to understand ASSUME if you look at how it was used for segment registers in 16-bit code

        ASSUME  CS:_TEXT,DS:DGROUP,ES:FAR_DATA

        mov     ax,FAR_DATA
        mov     es,ax
.
.
.
        mov     bx,SomeFarData    ;the assembler knows to add the segment override: ES:SomeFarData
        mov     cx,SomeCodeData   ;the assembler knows to add the segment override: CS:SomeCodeData
.
.
.
        ASSUME  ES:nothing
.
. from this point on, the assembler does not make any assumptions about ES
. any segment overrides that are required must be entered manually
. or, for example, if ES points to the video buffer - there are no labels in that segment
. but intructions like STOS still use the ES register

ecube

dave thanks but my real concern is the threadsafeness. Say you had 5 threads that all want to use edi to ptr to a struct using assume, is that safe or no? and why please, thanks.

dedndave

sure it is safe
the ASSUME directive(s) should follow the flow of the source code, though
it is like any other assembler "switch"
you turn it on - and it stays on (in the flow of the source text) until you turn it off
you could place the ASSUME directive in the source text, then the 5 threads, then ASSUME WhatEver:nothing
or, you could place the ASSUME directive before each thread and ASSUME WhatEver:nothing after each thread

the directive makes no changes during run-time - it only affects how MASM interprets the source text

ecube

great  :U thankyou  :bg

Astro

Is it OK to use:

lea eax,MyStruct
assume eax:ptr Whatever

; do stuff here

call SomeWinAPICallHere ; <<<<<<< Is this call safe..........

lea eax,MyStruct ; <<<<<<<<<< as long as I do this before carrying on?

; carry on

assume eax:nothing


Is this safe?

Best regards,
Robin.

Astro

Quote from: Vortex on November 11, 2009, 07:33:15 PM
It's possible to avoid completely the ASSUME statement :

mov IMAGE_ARCHIVE_MEMBER_HEADER.Mode[edx],030h

So the full code to make this work would be:

SomeStruct struct
Member1 DWORD ?
Member2 DWORD ?
SomeStruct ends

MyStruct SomeStruct <?>

lea edx,MyStruct

mov SomeStruct.Member1[edx],50


That is legal?

Best regards,
Robin.