flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [fasm] structure behavior from docs..

Author
Thread Post new topic Reply to topic
Azagaros



Joined: 18 Jan 2013
Posts: 26
Azagaros 17 Jul 2017, 16:55
I am trying to understand why the following code does not compile when it is modeled off the documentation code. I realize the documentation is a living document. This is Fasm and not Fasmg which might have better ways to do this.

These idea comes straight out of the Fasm 1.71 docs...
Code:
struc dirtype dirlba, dirlen, dirclust
{
        label . : 3*dword
        .dir_lba    rd dirlba
        .dir_len    rd dirlen
        .dir_clust  rd dirclust
        .size = $ - .
}
;end struc

rootDir dirtype dd 0, 0, 0 ; compiler complains here, referring to label...
    



the code does not compile in any combinations I have tried. I am not sure if I am running into a compiler error vs the documentation or I am being naive to the actual code structure..


Last edited by Azagaros on 17 Jul 2017, 17:22; edited 2 times in total
Post 17 Jul 2017, 16:55
View user's profile Send private message ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8411
Location: Kraków, Poland
Tomasz Grysztar 17 Jul 2017, 17:11
Yes, this is something that could work with fasmg but not with fasm 1, where sizes can only be specified with size operators and no other values are allowed.
Post 17 Jul 2017, 17:11
View user's profile Send private message Visit poster's website Reply with quote
Azagaros



Joined: 18 Jan 2013
Posts: 26
Azagaros 17 Jul 2017, 17:16
Do you have fasmg with your simple windows editor? I was looking for fasm 1 solutions because of this issue...
Post 17 Jul 2017, 17:16
View user's profile Send private message ICQ Number Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 817
Location: Russian Federation, Sochi
ProMiNick 17 Jul 2017, 19:10
FASMG & FASM - AllInOne, all sources,all includes. All workable, all portable (whole package I mean).
FASMW used as editor and compilation launcher for both fasm & fasmg sources.
https://board.flatassembler.net/topic.php?t=19966

But my example it is only for windows. Because it uses BAT files for automation.

How to play with it?:
unzip all & run Init.bat (it will adapt package to current directory, all params go to fasmg.ini not to registry).
fasmg not uses fasmg.ini, but automation scripts uses it.


Last edited by ProMiNick on 01 Aug 2017, 14:22; edited 1 time in total
Post 17 Jul 2017, 19:10
View user's profile Send private message Send e-mail Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 817
Location: Russian Federation, Sochi
ProMiNick 19 Jul 2017, 11:56
Post removed.
Here was attached outdate version of package FASM1 FASMG AllInOne.
Newer version always refered by link in above post.

_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 19 Jul 2017, 11:56
View user's profile Send private message Send e-mail Reply with quote
donn



Joined: 05 Mar 2010
Posts: 321
donn 09 Oct 2018, 20:59
Is there an include needed to use struc with fasmg?


The format I'm assembling (successfully) is MS64 COFF and each time I define a struc, I get:
Code:
fasmg APP.asm APP.obj
flat assembler  version g.i4pue
APP.asm [4] macro format [201] include/format/coffms.inc [231]:
        NumberOfSections dw NUMBER_OF_SECTIONS
Processed: NumberOfSections dw NUMBER_OF_SECTIONS
Error: symbol 'NUMBER_OF_SECTIONS' is undefined or out of scope.
    


Example strucs:

Code:
        struc ListItem{
                .item dq 0
                .previous dq 0
                .next dq 0
                .itemSize dq 0
        }

        struc List{
                .firstItem dq 0
                .listSize dq 0
                .itemsCount dq 0
                .index dq 0
                .indexItem dq 0                         
                .indexedItemIndex dq 0  
        }       

    


I'm still looking to resolve this and will edit this if I come across a resolution.
Post 09 Oct 2018, 20:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20628
Location: In your JS exploiting you and your system
revolution 10 Oct 2018, 00:22
fasmg does not use the curly brackets "{}" for structure definitions. Those are fasm syntax.
Post 10 Oct 2018, 00:22
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8411
Location: Kraków, Poland
Tomasz Grysztar 10 Oct 2018, 08:26
The curly braces are the syntax of fasm's preprocessor. fasmg does not have a separate preprocessor, so its STRUC uses the same syntax as assembler's structures:
Code:
        struc ListItem
                label .
                .item dq 0
                .previous dq 0
                .next dq 0
                .itemSize dq 0
        end struc

        struc List
                label .
                .firstItem dq 0
                .listSize dq 0
                .itemsCount dq 0
                .index dq 0
                .indexItem dq 0                         
                .indexedItemIndex dq 0  
        end struc    
Also note that in fasmg "label ." is not created by default, you have to state it explicitly.

See also this thread: https://board.flatassembler.net/topic.php?t=19283
Post 10 Oct 2018, 08:26
View user's profile Send private message Visit poster's website Reply with quote
donn



Joined: 05 Mar 2010
Posts: 321
donn 10 Oct 2018, 17:46
Great, it assembles now.


Still using the virtuals:

Code:
        ; Used with address offsets
        virtual at 0
                List List
        end virtual

        ; Used with address offsets
        virtual at 0
                ListItem ListItem
        end virtual    


Also built my first working macros yesterday, which have been helpful to getting things rolling:


Code:
macro newFile fileNameAddr,handleAddr

        sub rsp, 8*8
        mov qword [rsp+6*8], 0                                  ;hTemplateFile
        mov qword [rsp+5*8], 128                                ;dwFlagsandAttributes
        mov qword [rsp+4*8], 000000100b                         ;dwCreationDisposition
        mov r9, 0                                               ;lpSecurityAttributes
        mov r8, 000000010b                                      ;dwShareMode
        mov rdx, 10100000000000000000000100000101b              ;dwDesiredAccess
        mov rcx, fileNameAddr
        call [CreateFile]
        add rsp, 8*8
        mov [handleAddr], rax

        mov rcx, [handleAddr]
        sub rsp, 8*4
        call [SetEndOfFile]
        add rsp, 8*4

end macro

macro writeFile handleAddr,entry,size,writtenAddr

        mov rcx, [handleAddr]
        sub rsp, 8*4
        call [SetEndOfFile]
        add rsp, 8*4
        

        sub rsp, 8*8
        mov qword [rsp+4*8], 0
        mov r9, writtenAddr
        mov r8, [size]
        mov rdx, entry
        mov rcx, [handleAddr]
        call [WriteFile]
        add rsp, 8*8


end macro    
Post 10 Oct 2018, 17:46
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.