flat assembler
Message board for the users of flat assembler.

Index > Windows > Learning fasm from masm

Goto page Previous  1, 2, 3, 4, 5, 6  Next
Author
Thread Post new topic Reply to topic
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
nmake
No. You could try to use something like
Code:
match +,- {
;commented out
}    

or a similar workaround, but it's only a partial solution, which does not work for many situations. A complete solution can only be achieved by modifying the fasm source codes.
Post 17 Sep 2012, 12:54
View user's profile Send private message Reply with quote
nmake



Joined: 13 Sep 2012
Posts: 193
nmake
Thanks

When using local structures from within a procedure I need the address of that structure to pass it to another procedure. In MASM we use the ADDR directive or use lea eax, structname. I could use the latter in Fasm, but is there a way to pass the address of a local structure directly when calling procedures?

for example:
Code:
proc test
locals
  mystruct structure ?
endl

stdcall someprocedure, mystruct  <- need to pass the address of mystruct here
endp
    


The only way I can think of that works is to use lea to get the address in the stack. In Masm we use the ADDR operator when dealing with stack variables and structures. What method do I use in Fasm?
Post 18 Sep 2012, 00:01
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
nmake
Quote:
The only way I can think of that works is to use lea to get the address in the stack.

And that's also the correct way.
Quote:
In Masm we use the ADDR operator when dealing with stack variables and structures.

There's an emulation of this operator in the invoke macro from the extended headers. I.e. you can use this operator (lowercased) same as in masm if you include win32ax.inc instead of win32a.inc. The result is same: lea edx, ... . But then you can't control what register is used: it's always edx.
Post 18 Sep 2012, 00:15
View user's profile Send private message Reply with quote
nmake



Joined: 13 Sep 2012
Posts: 193
nmake
One thing that I've been talking about are include files. Let's say I have procedures in my include files that I want to include in my main program. Is it normal/common to place these include files at various places around the main source file? Or can I not put all include files at the top of the program? Very Happy
Post 18 Sep 2012, 02:28
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
IIRC, it was already answered. You can put your labels (not only procedures, but every label) before or after the place you refer it. FASM can always resolve its address.

nmake, isn't it better simply to write some program with FASM? It will teach you more than thousand questions. Smile
Post 18 Sep 2012, 04:05
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
nmake



Joined: 13 Sep 2012
Posts: 193
nmake
JohnFound, is it really necessary to use locals and endl between locals in procedures?
Post 18 Sep 2012, 04:56
View user's profile Send private message Reply with quote
nmake



Joined: 13 Sep 2012
Posts: 193
nmake
Is there a macroinstruction or directive for checking whether a passed macro parameter is a register or not?

something like this:
Code:
IF IsReg
end if
    


I also wonder what the special character mean " if ~ arg" I don't recall the name of this special character and don't know what it is used for in fasm, could anyone explain? Thanks in advance.

? Smile
Post 19 Sep 2012, 03:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16891
Location: In your JS exploiting you and your system
revolution
You can always refer to the documentation:
Code:
    macro mov op1,op2
     {
      if op1 in <ds,es,fs,gs,ss> & op2 in <cs,ds,es,fs,gs,ss>
        push  op2
        pop   op1
      else
        mov   op1,op2
      end if
     }    
Post 19 Sep 2012, 04:16
View user's profile Send private message Visit poster's website Reply with quote
nmake



Joined: 13 Sep 2012
Posts: 193
nmake
Thanks revolution. Btw, that special character ~ what is it used for in fasm? I can't find it in the documentation.
Post 19 Sep 2012, 04:44
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16891
Location: In your JS exploiting you and your system
revolution
nmake wrote:
Thanks revolution. Btw, that special character ~ what is it used for in fasm? I can't find it in the documentation.
It is there.
Post 19 Sep 2012, 04:51
View user's profile Send private message Visit poster's website Reply with quote
nmake



Joined: 13 Sep 2012
Posts: 193
nmake
The logical NOT operator. How amusing. In Masm it is the ! character. Very Happy
Post 19 Sep 2012, 09:50
View user's profile Send private message Reply with quote
nmake



Joined: 13 Sep 2012
Posts: 193
nmake
Do anyone know how I can declare a global variable in the .data section from within a procedure?

In masm you can do it this way:
Code:
name proc
.data
  somevariable dd 10
.code
  xor eax,eax
  xor eax,eax
  ret
name endp
    


never mind, solved it. I simply put a .data section in the include file that contains the procedure and used "if used" to conditionally include globals.
Post 19 Sep 2012, 10:53
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
nmake, as I already answered you, the only way is to use macros. And the only known such macros are from FreshLib library. The code will look following way:
Code:
proc name
begin
  iglobal
    somevariable dd 10
  endg

  xor eax,eax
  xor eax,eax
  return
endp    
You can use only the include file with these macros: "freshlib/macros/_globals.inc".
The documentation is: here
Post 19 Sep 2012, 14:01
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
JohnFound
Quote:
The documentation is: here

I just noticed your comment about the slowness of the text macro with duplication prevention. About a year ago I've written similar macros able to gather strings and to provide different levels of duplication prevention.

I wasn't using those widely and therefore not sure about their efficiency. But may be you could test them and find to be more efficient. The attached include file contains different versions of the duplication prevention mechanisms. Those are:
1. "no duplication prevention". This one's clear. All strings will be put into the output file.
2. "full duplication prevention". Prevents duplication only if the strings completely match.
3. "internal duplication prevention". Prevents duplication of substrings, but only in case, when a longer string is declared before it's shorter substring.
4. "internal duplication prevention with reordering". This one's not commented, and it's the most sophisticated mechanism. It first sorts the strings by length and after that it searches for the duplications. This is not an absolutely optimal duplication prevention (an optimal solution is NP), but it prevents duplications in most practical cases.

A usage example looks as follows:
Code:
format PE GUI 4.0
include 'win32a.inc'
include 'accstrings.inc'

main:
      invoke MessageBox,NULL,<string "Hello, world!",0>,<string "Title",0>,MB_OK
  
    message2 dstring "Full string fusion",0
   title2 dstring "Full string fusion",0
     invoke MessageBox,NULL,message2,title2,MB_OK
        
    title1 dustring "fusion",0
        message1 dustring "Substring fusion",0
    invoke MessageBoxW,NULL,message1,title1,MB_OK
       
xor eax,eax
ret

IncludeStrings

data import
   library user32,"user32.dll"
   
   import user32,\
     MessageBox,'MessageBoxA',\
       MessageBoxW,'MessageBoxW'
end data    


Description:
Download
Filename: ACCSTRINGS.INC
Filesize: 6.82 KB
Downloaded: 109 Time(s)

Post 19 Sep 2012, 14:41
View user's profile Send private message Reply with quote
nmake



Joined: 13 Sep 2012
Posts: 193
nmake
I appreciate that you want to help me out here Smile
Post 19 Sep 2012, 15:10
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
l_inc, it is interesting work, but unfortunately, it has the same disadvantages as my first implementation.

For example I made some test with the following code:
Code:
rept 1000 {
local strlbl
  strlbl dstring 'test string',0
}    


The results was bad:
0 strings -> 0.3s
100 strings -> 0.6s
1000 strings -> 18s

Maximal number of defined strings are 1480 for 512MB of memory allocated for the compiler.

With unique strings, the things got even worse:
Code:
rept 228 {
local strlbl
  strlbl dstring `strlbl,0
}    


The maximal count of strings defined this way is 228 for 512MB memory allocated for the compiler (compiled for 10s)
Post 19 Sep 2012, 16:01
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
JohnFound
Quote:
1000 strings -> 18s

Well... On my not-very-fast-machine it compiles within 1.9 seconds. But I get 15 seconds, when trying to compile 3000 equal strings.
Quote:
With unique strings, the things got even worse:

This behaviour is expected. But again, 10 seconds are taken by 700 strings on my machine. However I always use 1.5 GB for the compiler.

P.S. Anyway, thanks for providing the test results.
Post 19 Sep 2012, 16:39
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
l_inc, your idea of "not very fast machine" is pretty relative. Wink

I am using netbook eeePC with Intel Atom under-clocked to 900MHz and expect FASM/Fresh to compile in 5..10seconds for huge projects.

We are assembly programmers after all. Very Happy
Post 19 Sep 2012, 16:45
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7489
Location: Kraków, Poland
Tomasz Grysztar
This reminded me of the addressing spaces labeling feature, which I promised for fasm 2.0 but may still give it a shot in 1.x line. I think I have an idea how to adapt the 1.x architecture so that it would handle it.
Post 19 Sep 2012, 17:45
View user's profile Send private message Visit poster's website Reply with quote
nmake



Joined: 13 Sep 2012
Posts: 193
nmake
Tomasz, will fasm support floating point calculations during compile-time later? Another question, does fasm produce any form of signatures in the final executable to identify fasm programs?
Post 19 Sep 2012, 17:58
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4, 5, 6  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.