flat assembler
Message board for the users of flat assembler.

Index > Linux > FASMg and Linux32

Author
Thread Post new topic Reply to topic
TheSage



Joined: 03 Jan 2023
Posts: 6
TheSage 03 Jan 2023, 00:30
What would need to be done to make the following code compile under FASMg:

Code:
format ELF

include 'cdecl.inc'
include 'gtk.inc'

public main

; extrn blah

extrn gtk_init
extrn gtk_window_new
extrn gtk_widget_show
extrn gtk_main

; section '.data' writeable

section '.bss' writeable

    hWindow         dd ?

section '.text' executable

proc main argc, argv

    lea eax, [argc]
    lea ebx, [argv]

    ccall gtk_init, eax, ebx

    ccall gtk_window_new, GTK_WINDOW_TOPLEVEL
    mov [hWindow], eax

    ccall gtk_widget_show, [hWindow]

    call gtk_main

    ret

endp    
Post 03 Jan 2023, 00:30
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 03 Jan 2023, 09:54
It's one of the old GTK examples that are on the (deprecated) page, isn't it?

The CDECL.INC is mostly the same as macros used in Windows headers, except that it marks procedure as "C" by default. Using standard compatibility macros, this assembles to exactly the same output file as with fasm 1:
Code:
include 'format/format.inc'
format ELF

include 'macro/proc32.inc'
include 'gtk.inc'

public main

; extrn blah

extrn gtk_init
extrn gtk_window_new
extrn gtk_widget_show
extrn gtk_main

; section '.data' writeable

section '.bss' writeable

    hWindow         dd ?

section '.text' executable

proc main C argc, argv  ; note the added marking

    lea eax, [argc]
    lea ebx, [argv]

    ccall gtk_init, eax, ebx

    ccall gtk_window_new, GTK_WINDOW_TOPLEVEL
    mov [hWindow], eax

    ccall gtk_widget_show, [hWindow]

    call gtk_main

    ret

endp    
Post 03 Jan 2023, 09:54
View user's profile Send private message Visit poster's website Reply with quote
TheSage



Joined: 03 Jan 2023
Posts: 6
TheSage 03 Jan 2023, 15:48
Thanks for such a prompt reply! I wasn't expecting that.

That won't compile because the program can't find proc32.inc. Actually, I can't find it either. Bummer.

"It's one of the old GTK examples that are on the (deprecated) page, isn't it"

If only I were that stupid because that would be an improvement! Actually I found it in the link on the front page called "Examples". I saw nothing about being "deprecated" or "depreciated".

PS - I found proc32.inc in the source file for FASMg-master. I found quite a few other .incs with it too, like @@.inc, import64.inc, struct.inc, and so on. Are those supposed to be built-in macros that I need to "activate" instead of include or should I just copy them to my root dir for FASMg?


Last edited by TheSage on 03 Jan 2023, 18:32; edited 1 time in total
Post 03 Jan 2023, 15:48
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 03 Jan 2023, 18:30
TheSage wrote:
That won't compile because the program can't find proc32.inc. Actually, I can't find it either. Bummer.
You need the set of fasm compatibility headers, available here: https://github.com/tgrysztar/fasmg/tree/master/packages/x86/include
See also the thread about migration from fasm to fasmg. It does not have a Linux-dedicated section (yet), but as demonstrated by this example, the same headers can be helpful.

TheSage wrote:
Actually I found it in the link on the front page called "Examples". I saw nothing about being "deprecated" or "depreciated".
Yes, that's the page I linked. The page itself states that "Nowadays new examples are contributed on the relevant forum."
Post 03 Jan 2023, 18:30
View user's profile Send private message Visit poster's website Reply with quote
TheSage



Joined: 03 Jan 2023
Posts: 6
TheSage 03 Jan 2023, 18:55
Tomasz Grysztar wrote:
TheSage wrote:
That won't compile because the program can't find proc32.inc. Actually, I can't find it either. Bummer.
You need the set of fasm compatibility headers, available here: https://github.com/tgrysztar/fasmg/tree/master/packages/x86/include
See also the thread about migration from fasm to fasmg.


Yes, I already downloaded FASMg-master. Shouldn't something that critical be included in the FASMg package? I also converted your linked page into a PDF for reference purposes.

Tomasz Grysztar wrote:
It does not have a Linux-dedicated section (yet), but as demonstrated by this example, the same headers can be helpful.


In hindsight I can see that.

Tomasz Grysztar wrote:
TheSage wrote:
Actually I found it in the link on the front page called "Examples". I saw nothing about being "deprecated" or "depreciated".
Yes, that's the page I linked. The page itself states that "Nowadays new examples are contributed on the relevant forum."


My interpretation of that is that new examples doesn't mean that the old examples may or may not work anymore.

PS -- It compiles. Thanks. New problem: it won't link. I'm using "GoLink /entry:main coff window.obj", which typically works for me on GoAsm and NASM, but GoLink reports "An object file was given to GoLink whose format was not supported (window.obj)". What is the format?
Post 03 Jan 2023, 18:55
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 03 Jan 2023, 19:55
TheSage wrote:
Yes, I already downloaded FASMg-master. Shouldn't something that critical be included in the FASMg package?
By itself fasmg is an universal engine that can be extended into many different frameworks and architectures. The "fasm 1 compatibility" is just one of them.

TheSage wrote:
New problem: it won't link.
I thought you had the project working with fasm 1 already and then asked about migrating it to fasmg. But it seems you did not, because you would then run into the same problem earlier. Why didn't you start with fasm 1, for which the example was actually intended?

TheSage wrote:
What is the format?
The very first line of the original source tells you that. It is ELF object format.
Post 03 Jan 2023, 19:55
View user's profile Send private message Visit poster's website Reply with quote
TheSage



Joined: 03 Jan 2023
Posts: 6
TheSage 04 Jan 2023, 01:58
Tomasz Grysztar wrote:
TheSage wrote:
Yes, I already downloaded FASMg-master. Shouldn't something that critical be included in the FASMg package?
By itself fasmg is an universal engine that can be extended into many different frameworks and architectures. The "fasm 1 compatibility" is just one of them.


If everyone wanting to learn FASMg must first become a FASM 1 expert, put that in the documentation so everyone can know from the start the prerequisites. The advertisement for FASMg implies that it is a mature standalone product not requiring FASM 1 experience.

TheSage wrote:
New problem: it won't link.
Tomasz Grysztar wrote:
I thought you had the project working with fasm 1 already and then asked about migrating it to fasmg. Why didn't you start with fasm 1, for which the example was actually intended?


See what I mean? If that is what you want then put that in the documentation on page one. As for me, I don't want to learn FASM 1, I want to learn FASMg. Is that not possible? If I were a beginning programmer, I would have already given up.

TheSage wrote:
What is the format?
Tomasz Grysztar wrote:
The very first line of the original source tells you that. It is ELF object format.


Oops! That's due to an old typing habit I have because I haven't fully switched over from Windows to Linux yet so I'm writing Linux programs on a computer only setup for Windows development (and most asm programs use the linker to specify the format).

***NOTICE***

This issue has been resolved to my satisfaction so it can be closed out, but remember this for our next discussion:

1) If you have to spell it out in a forum post, it belongs in the documentation

2) My next step is to convert that simple program to a 64-bit ELF (cdecl.inc needs the most work). I would ask for helpful examples to shorten the learning curve but I know there are none because you just confessed there are none. So expect feedback

3) That shouldn't be too hard too do, but maybe that can't be done until I learn FASM 1 first for a few months, then switch over to FASMg? Very Happy I have five large Windows asm projects that (if FASMg works as I believe it can) will be converted to Linux FASMg projects. Because apparently I am the first and only person to be doing such a thing (simple "Hello world" programs aren't even close to being helpful), I think I can be good feedback for you and your product. So you will see future posts from me asking for help on things not documented, poorly documented, or not working properly. Okay?
Post 04 Jan 2023, 01:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20517
Location: In your JS exploiting you and your system
revolution 04 Jan 2023, 02:25
fasmg is more like an HLL than an assembler. Perhaps this is what has misled some. It needs many support files before it can become an assembler.

fasm is an assembler at heart. It can be used stand-alone with just the executable file.

You don't need to become an expert in either to use them. As long as the distinction is understood, that fasmg is nothing like an assembler by itself, then I think that can prime one's thought process to realise how to use them.
Post 04 Jan 2023, 02:25
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 04 Jan 2023, 07:41
TheSage wrote:
If everyone wanting to learn FASMg must first become a FASM 1 expert, put that in the documentation so everyone can know from the start the prerequisites. The advertisement for FASMg implies that it is a mature standalone product not requiring FASM 1 experience.
As already mentioned, fasmg can be used as a base for different assemblers, not necessarily x86, and even for x86 it could implement syntaxes different than fasm 1. But if you choose to use "fasm compatibility package" then it's emulating the syntax of fasm 1, obviously.

TheSage wrote:
See what I mean? If that is what you want then put that in the documentation on page one. As for me, I don't want to learn FASM 1, I want to learn FASMg. Is that not possible? If I were a beginning programmer, I would have already given up.
You have taken an example written for fasm 1, from the page that mentions that explicitly. Normally you would have even less luck trying to take an example for one language and feeding it to compiler of another one (and fasmg by itself is just a bare "data assembly language", not even an x86 assembler), but here it was possible, because fasmg can be extended with specialized headers to become an assembler for an architecture and syntax variant of choice. So with "fasm compatibility package" it becomes possible to assemble sources written in fasm 1 syntax. This is what I provided.
Post 04 Jan 2023, 07:41
View user's profile Send private message Visit poster's website Reply with quote
TheSage



Joined: 03 Jan 2023
Posts: 6
TheSage 04 Jan 2023, 12:53
Tomasz Grysztar wrote:
As already mentioned, fasmg can be used as a base for different assemblers, not necessarily x86, and even for x86 it could implement syntaxes different than fasm 1. But if you choose to use "fasm compatibility package" then it's emulating the syntax of fasm 1, obviously.


Tomasz Grysztar wrote:
You have taken an example written for fasm 1, from the page that mentions that explicitly.


You mean the page with nothing but depreciated examples that say nothing about fasmg.

Tomasz Grysztar wrote:
Normally you would have even less luck trying to take an example for one language and feeding it to compiler of another one (and fasmg by itself is just a bare "data assembly language", not even an x86 assembler), but here it was possible, because fasmg can be extended with specialized headers to become an assembler for an architecture and syntax variant of choice. So with "fasm compatibility package" it becomes possible to assemble sources written in fasm 1 syntax. This is what I provided.


If in order for fasmg to be able to assemble object files for Linux I must install fasm1 first, then I don't need fasmg to do that. If I need to know how fasm1 works to assemble files but I do not need to know how fasmg works to assemble files, I don't need fasmg to do that. Currently, because fasm1 and fasmg cannot co-exist on top of each other, if I want to use fasmg to develop for Linux or Windows, I need to install and then create two sets of environment variables: one for fasm1 and one for fasmg. If I want to simplify things and merge fasm1 with fasmg into something common, it won't be easy to update the fasm1 files because the fasm1 files will no longer be where they belong.

Therefore the way you are presenting fasmg, makes it appear to be a macro compiler only good for developers wanting to create a new and custom assembler, otherwise stick to fasm1.

SUGGESTION: Since fasmg is allegedly a successor to fasm1, take all the macros, incs, and docs for fasm1 and put them into the fasmg package because that is what fasm1 is: fasmg plus all the macs and incs. Then you will actually have the successor to fasm1 instead of bits and pieces of something else. And then your examples page will apply to both fasm1 and fasmg.
Post 04 Jan 2023, 12:53
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 04 Jan 2023, 13:17
TheSage wrote:
Tomasz Grysztar wrote:
You have taken an example written for fasm 1, from the page that mentions that explicitly.
You mean the page with nothing but depreciated examples that say nothing about fasmg.
Let me quote the page itself:
Quote:
This section contains programs created with the flat assembler and contributed by users as sample material for others to learn from. Most of them were submitted in the early days of this website, and they all have been designed for flat assembler 1.

Nowadays new examples are contributed on the relevant forum. You may find some tutorials there as well.

Examples for flat assembler g are gathered in a dedicated thread on the message board.
Not only does it say that the examples there are for fasm 1, it also points where to look for fasmg-related material instead.

TheSage wrote:
If in order for fasmg to be able to assemble object files for Linux I must install fasm1 first, then I don't need fasmg to do that.
That's not what was implied. The thing is, if you first tried to compile the example with fasm 1, which the example was intended for, you would run into exactly the same problem at the linking stage. It unnecessarily complicated the discussion, because this problem was completely unrelated to the concern of migrating from fasm 1 to fasmg, which the topic at least initially seemed to be.

TheSage wrote:
SUGGESTION: Since fasmg is allegedly a successor to fasm1, take all the macros, incs, and docs for fasm1 and put them into the fasmg package because that is what fasm1 is: fasmg plus all the macs and incs.
The exact description from the documentation is:
Quote:
It is an assembly engine designed as a successor of the one used in flat assembler 1, one of the recognized assemblers for x86 processors.
So fasmg is a successor of fasm's engine, not of fasm as a whole. Even fasm 1 could be bent to become almost a different language with a right set of macros, and it was done several times by the members of this board. With fasmg I pushed it one step further and provided just a bare engine, to be used as foundation for such projects.

If fasmg was fasm 2, I would publish it as such, and it would then likely replace fasm 1 on the pages. But it is not fasm 2 and fasm 1 is already good enough at what it is.
Post 04 Jan 2023, 13:17
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20517
Location: In your JS exploiting you and your system
revolution 04 Jan 2023, 13:38
TheSage:

If you just want an assembler to make x86 stuff then use fasm.

If what you really want is to make your own custom syntax and/or try out a new assembler for some exotic chip then fasmg might be a good starting point for testing before committing to writing low level code for the final product.

Each tool is different, targeted to a different job.
Post 04 Jan 2023, 13:38
View user's profile Send private message Visit poster's website Reply with quote
TheSage



Joined: 03 Jan 2023
Posts: 6
TheSage 04 Jan 2023, 17:01
Tomasz Grysztar wrote:
TheSage wrote:
Tomasz Grysztar wrote:
You have taken an example written for fasm 1, from the page that mentions that explicitly.
You mean the page with nothing but depreciated examples that say nothing about fasmg.
Let me quote the page itself:
Quote:
This section contains programs created with the flat assembler and contributed by users as sample material for others to learn from. Most of them were submitted in the early days of this website, and they all have been designed for flat assembler 1.

You told me the examples page was for depreciated code, so I believed you. So get rid of the apparently useless examples page because it contains misleading information.

Nowadays new examples are contributed on the relevant forum. You may find some tutorials there as well.

Examples for flat assembler g are gathered in a dedicated thread on the message board.
Not only does it say that the examples there are for fasm 1, it also points where to look for fasmg-related material instead.


That is not what forums are for. They are for people to find help, get into pissing contests, or find (since older posts are never deleted) misleading information. Forums are helter skelter places not meant to conduct serious research. That's what official documentation is supposed to be used for.

Tomasz Grysztar wrote:
TheSage wrote:
If in order for fasmg to be able to assemble object files for Linux I must install fasm1 first, then I don't need fasmg to do that.
That's not what was implied. The thing is, if you first tried to compile the example with fasm 1, which the example was intended for, you would run into exactly the same problem at the linking stage. It unnecessarily complicated the discussion, because this problem was completely unrelated to the concern of migrating from fasm 1 to fasmg, which the topic at least initially seemed to be.


You thought this was a concern of migrating from one program (fasm1) to another one (fasmg), a program that allegedly wasn't meant to be a replacement for fasm1? I'm just now learning fasm and I didn't want to learn something that would be succeeded by something else and become obsolete. Do you secretly work for Microsoft?Smile

Tomasz Grysztar wrote:
TheSage wrote:
SUGGESTION: Since fasmg is allegedly a successor to fasm1, take all the macros, incs, and docs for fasm1 and put them into the fasmg package because that is what fasm1 is: fasmg plus all the macs and incs.
The exact description from the documentation is:
Quote:
It is an assembly engine designed as a successor of the one used in flat assembler 1, one of the recognized assemblers for x86 processors.
So fasmg is a successor of fasm's engine, not of fasm as a whole. Even fasm 1 could be bent to become almost a different language with a right set of macros, and it was done several times by the members of this board. With fasmg I pushed it one step further and provided just a bare engine, to be used as foundation for such projects.

If fasmg was fasm 2, I would publish it as such, and it would then likely replace fasm 1 on the pages. But it is not fasm 2 and fasm 1 is already good enough at what it is.


"The flat assembler g (abbreviated to fasmg) is a new assembly engine designed as a successor of the one used by flat assembler 1. Instead of having a built-in support for x86 instructions, it implements them through additional packages and in the same way it can be adapted to assemble for different architectures and purposes. With the included example packages it is capable of generating all the output formats that flat assembler 1 could and additional ones, like Mach-O or Intel HEX" (https://flatassembler.net/download.php)

fasmg is not an assembly engine, it is a macro interpreter. It has no "additional packages" because it wasn't meant to be used outside of fasm1 but inside of fasm1, as it's "SUCCESSOR" for it's frontend. Since no useful x86-64 Linux examples were given ("Hello World" doesn't count), it was no wonder I couldn't generate any and had to go to the forum and ask for help. You need to go back and fix your mistakes.

Now that you have clarified the purpose of fasmg, I clearly understand what fasmg is good for (for creating other standalone assembly programs using macros and nothing else), so I will be abandoning fasmg and using fasm1 for Linux instead.
Post 04 Jan 2023, 17:01
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.