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 |
|
nmake 18 Sep 2012, 00:01
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? |
|||
18 Sep 2012, 00:01 |
|
l_inc 18 Sep 2012, 00:15
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. |
|||
18 Sep 2012, 00:15 |
|
nmake 18 Sep 2012, 02:28
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?
|
|||
18 Sep 2012, 02:28 |
|
JohnFound 18 Sep 2012, 04:05
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. |
|||
18 Sep 2012, 04:05 |
|
nmake 18 Sep 2012, 04:56
JohnFound, is it really necessary to use locals and endl between locals in procedures?
|
|||
18 Sep 2012, 04:56 |
|
nmake 19 Sep 2012, 03:58
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. ? |
|||
19 Sep 2012, 03:58 |
|
revolution 19 Sep 2012, 04:16
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 } |
|||
19 Sep 2012, 04:16 |
|
nmake 19 Sep 2012, 04:44
Thanks revolution. Btw, that special character ~ what is it used for in fasm? I can't find it in the documentation.
|
|||
19 Sep 2012, 04:44 |
|
revolution 19 Sep 2012, 04:51
nmake wrote: Thanks revolution. Btw, that special character ~ what is it used for in fasm? I can't find it in the documentation. |
|||
19 Sep 2012, 04:51 |
|
nmake 19 Sep 2012, 09:50
The logical NOT operator. How amusing. In Masm it is the ! character.
|
|||
19 Sep 2012, 09:50 |
|
nmake 19 Sep 2012, 10:53
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. |
|||
19 Sep 2012, 10:53 |
|
JohnFound 19 Sep 2012, 14:01
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 The documentation is: here |
|||
19 Sep 2012, 14:01 |
|
l_inc 19 Sep 2012, 14:41
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
|
|||||||||||
19 Sep 2012, 14:41 |
|
nmake 19 Sep 2012, 15:10
I appreciate that you want to help me out here
|
|||
19 Sep 2012, 15:10 |
|
JohnFound 19 Sep 2012, 16:01
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) |
|||
19 Sep 2012, 16:01 |
|
l_inc 19 Sep 2012, 16:39
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. |
|||
19 Sep 2012, 16:39 |
|
JohnFound 19 Sep 2012, 16:45
l_inc, your idea of "not very fast machine" is pretty relative.
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. |
|||
19 Sep 2012, 16:45 |
|
Tomasz Grysztar 19 Sep 2012, 17:45
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.
|
|||
19 Sep 2012, 17:45 |
|
nmake 19 Sep 2012, 17:58
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?
|
|||
19 Sep 2012, 17:58 |
|
Goto page Previous 1, 2, 3, 4, 5, 6 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.