QUESTION 1

I'm trying to get more familiar with FASM... Sorry if this has been asked before, but what are some of the ways you FASM guys use local variables? I'm a long-time MASM user, and I guess I'm spoiled by having the PROC and LOCAL directives. I've seen the source code for FASM uses something like this:



proc ShowErrorMessage, hWnd,dwError
.lpBuffer dd ?
enter
lea eax,[.lpBuffer]
invoke FormatMessage,...
invoke MessageBox,[hWnd],[.lpBuffer],...
invoke LocalFree,[.lpBuffer]
return

I'm assuming .lpBuffer is really just like a static variable in C, right?... which is fine for many uses, but sometimes not.

Any other methods you guys use, other than a stack frame?

Has anyone written any macros for an EBP-based stack frame with locals?

QUESTION 2

Does FASM have anything like MASM's "assume" directive? I'd like to write something like this...



blah:
ASSUME ebx:PTR WIN32_FIND_DATA

invoke lstrcpy, mybuf, ADDR [ebx].cFileName
. . .

ASSUME ebx:NOTHING

Or at least does it have a "cast" operator for registers?

Thanks in advance...!
Posted on 2003-07-16 19:22:28 by MANT
The example you gave is local variable. There is no assume directive, but you could use virtual instead.
Posted on 2003-07-16 19:37:35 by comrade
The example you gave is local variable.
The scope of the variable name is local, but it's a static memory location, yes? In other words, using this would not be thread-safe, since two threads running the same proc would be using the same memory location, right? Or do I misunderstand this aspect of FASM?

There is no assume directive, but you could use virtual instead.
Virtual, yes, that's exactly what I was looking for, thanks.
Posted on 2003-07-16 20:09:25 by MANT
The scope of the variable name is local, but it's a static memory location, yes?


The scope of the name is local (because it starts with a dot). In addition, the variable is located on the stack. Automatic stack frame handling is achieved by two macros: proc, and enter. The macros can be found in "%include%\macro\stdcall.inc".

The proc macro starts a "virtual at (EBP minus some offset) / end virtual" block, and the enter macro closes that block. Variables that are declared between proc and enter (like ".lpBuffer" in your example) are EBP-based stack variables, i.e., LOCALs.

Regards, Frank
Posted on 2003-07-16 21:31:12 by Frank
Thanks so much for clearing that up, Frank. I had read the stdcall.inc file, but I really didn't understand VIRTUAL well enough to figure out what the heck was going on. I read the VIRTUAL section in the PDF several times, and I still didn't get it. I'm glad this board exists: using the documentation alone, the task of learning FASM would be many times harder.
Posted on 2003-07-16 21:47:16 by MANT
Try this for assume. :)




virtual at ebx
ebx.wc WNDCLASSEX
end virtual

you can access like this,

mov [ebx.wc.cbSize],eax

Posted on 2003-07-17 22:11:26 by Bi_Dark
Yes indeed, thanks. I love "virtual"... a very handy concept!
Posted on 2003-07-17 23:45:23 by MANT