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

clive

Quote from: Astro on April 20, 2010, 03:46:06 PM
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.

Yes that looks fine, you could PUSH EAX; POP EAX too. Or not save/restore it at all if the API/SUB doesn't change the value of EAX.

As noted previously ASSUME is an assemble time directive so MASM knows what you mean when you don't spell things out explicitly. ie It infers which structure, code/data/extra segment, etc should be the default. I'm pretty sure it doesn't stop you using explicit references, to this or other structures if you want.

The ASSUME has absolutely no impact on the API being called, it is not setting a state/register in the CPU.

Registers are always thread safe, each thread has it's own set of registers (context), so is the stack (above esp). What gets you in trouble is multiple threads fighting over a memory location they all see in common, usually who wrote to it last, and when reading it back whose value is there.

-Clive
It could be a random act of randomness. Those happen a lot as well.

Astro

Great! Thanks!

Best regards,
Robin.